1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-16 18:19:55 +00:00

Load treasure disks from various loot tables

This commit is contained in:
SquidDev 2020-04-30 11:19:46 +01:00
parent 697e9449cf
commit 9f87eda5de
4 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1 @@
{}

View File

@ -116,7 +116,7 @@ public static void onItemColours( ColorHandlerEvent.Item event )
event.getItemColors().register(
( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
ComputerCraft.Items.disk
ComputerCraft.Items.disk, ComputerCraft.Items.treasureDisk
);
event.getItemColors().register( ( stack, layer ) -> {

View File

@ -9,6 +9,7 @@
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.data.BlockNamedEntityLootCondition;
import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.util.ResourceLocation;
@ -41,6 +42,11 @@ protected void registerLoot( BiConsumer<ResourceLocation, LootTable> add )
computerDrop( add, ComputerCraft.Blocks.computerAdvanced );
computerDrop( add, ComputerCraft.Blocks.turtleNormal );
computerDrop( add, ComputerCraft.Blocks.turtleAdvanced );
add.accept( ComputerCraftProxyCommon.ForgeHandlers.LOOT_TREASURE_DISK, LootTable
.builder()
.setParameterSet( LootParameterSets.GENERIC )
.build() );
}
private static void basicDrop( BiConsumer<ResourceLocation, LootTable> add, Block block )

View File

@ -31,7 +31,12 @@
import net.minecraft.tileentity.CommandBlockTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.ConstantRange;
import net.minecraft.world.storage.loot.LootPool;
import net.minecraft.world.storage.loot.LootTables;
import net.minecraft.world.storage.loot.TableLootEntry;
import net.minecraft.world.storage.loot.conditions.LootConditionManager;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -41,6 +46,10 @@
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD )
public final class ComputerCraftProxyCommon
{
@ -167,5 +176,33 @@ public static void onServerStopped( FMLServerStoppedEvent event )
WirelessNetwork.resetNetworks();
Tracking.reset();
}
public static final ResourceLocation LOOT_TREASURE_DISK = new ResourceLocation( ComputerCraft.MOD_ID, "treasure_disk" );
private static final Set<ResourceLocation> TABLES = new HashSet<>( Arrays.asList(
LootTables.CHESTS_SIMPLE_DUNGEON,
LootTables.CHESTS_ABANDONED_MINESHAFT,
LootTables.CHESTS_STRONGHOLD_CORRIDOR,
LootTables.CHESTS_STRONGHOLD_CROSSING,
LootTables.CHESTS_STRONGHOLD_LIBRARY,
LootTables.CHESTS_DESERT_PYRAMID,
LootTables.CHESTS_JUNGLE_TEMPLE,
LootTables.CHESTS_IGLOO_CHEST,
LootTables.CHESTS_WOODLAND_MANSION,
LootTables.CHESTS_VILLAGE_VILLAGE_CARTOGRAPHER
) );
@SubscribeEvent
public static void lootLoad( LootTableLoadEvent event )
{
ResourceLocation name = event.getName();
if( !name.getNamespace().equals( "minecraft" ) || !TABLES.contains( name ) ) return;
event.getTable().addPool( LootPool.builder()
.addEntry( TableLootEntry.builder( LOOT_TREASURE_DISK ) )
.rolls( ConstantRange.of( 1 ) )
.name( "computercraft_treasure" )
.build() );
}
}
}