Search in sources :

Example 1 with RandomizableContainerBlockEntity

use of net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity in project MC-Prefab by Brian-Wuest.

the class BuildingMethods method FillChest.

/**
 * Fills a chest with basic tools and items.
 *
 * @param world        - The world where the chest resides.
 * @param itemPosition - The block position of the chest.
 */
public static void FillChest(Level world, BlockPos itemPosition) {
    // Add each stone tool to the chest and leather armor.
    BlockEntity tileEntity = world.getBlockEntity(itemPosition);
    if (tileEntity instanceof RandomizableContainerBlockEntity) {
        RandomizableContainerBlockEntity chestTile = (RandomizableContainerBlockEntity) tileEntity;
        int itemSlot = 0;
        // Add the tools.
        if (CommonProxy.proxyConfiguration.serverConfiguration.addAxe) {
            chestTile.setItem(itemSlot++, new ItemStack(Items.STONE_AXE));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addHoe) {
            chestTile.setItem(itemSlot++, new ItemStack(Items.STONE_HOE));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addPickAxe) {
            chestTile.setItem(itemSlot++, new ItemStack(Items.STONE_PICKAXE));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addShovel) {
            chestTile.setItem(itemSlot++, new ItemStack(Items.STONE_SHOVEL));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addSword) {
            Item sword = ModRegistry.SwiftBladeStone.get();
            if (!CommonProxy.proxyConfiguration.serverConfiguration.recipeConfiguration.get(ModConfiguration.SwiftBladeKey)) {
                // Swift blades are disabled; use a regular stone sword instead.
                sword = Items.STONE_SWORD;
            }
            chestTile.setItem(itemSlot++, new ItemStack(sword));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addArmor) {
            // Add the armor.
            chestTile.setItem(itemSlot++, new ItemStack(Items.LEATHER_BOOTS));
            chestTile.setItem(itemSlot++, new ItemStack(Items.LEATHER_CHESTPLATE));
            chestTile.setItem(itemSlot++, new ItemStack(Items.LEATHER_HELMET));
            chestTile.setItem(itemSlot++, new ItemStack(Items.LEATHER_LEGGINGS));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addFood) {
            // Add some bread.
            chestTile.setItem(itemSlot++, new ItemStack(Items.BREAD, 20));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addCrops) {
            // Add potatoes.
            chestTile.setItem(itemSlot++, new ItemStack(Items.POTATO, 3));
            // Add carrots.
            chestTile.setItem(itemSlot++, new ItemStack(Items.CARROT, 3));
            // Add seeds.
            chestTile.setItem(itemSlot++, new ItemStack(Items.WHEAT_SEEDS, 3));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addCobble) {
            // Add Cobblestone.
            chestTile.setItem(itemSlot++, new ItemStack(Item.byBlock(Blocks.COBBLESTONE), 64));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addDirt) {
            // Add Dirt.
            chestTile.setItem(itemSlot++, new ItemStack(Item.byBlock(Blocks.DIRT), 64));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addSaplings) {
            // Add oak saplings.
            chestTile.setItem(itemSlot++, new ItemStack(Item.byBlock(Blocks.OAK_SAPLING), 3));
        }
        if (CommonProxy.proxyConfiguration.serverConfiguration.addTorches) {
            // Add a set of 20 torches.
            chestTile.setItem(itemSlot, new ItemStack(Item.byBlock(Blocks.TORCH), 20));
        }
        chestTile.setChanged();
        Packet<ClientGamePacketListener> packet = chestTile.getUpdatePacket();
        if (packet != null) {
            world.getServer().getPlayerList().broadcastAll(packet);
        }
    }
}
Also used : Item(net.minecraft.world.item.Item) RandomizableContainerBlockEntity(net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) ItemStack(net.minecraft.world.item.ItemStack) RandomizableContainerBlockEntity(net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) FurnaceBlockEntity(net.minecraft.world.level.block.entity.FurnaceBlockEntity) ClientGamePacketListener(net.minecraft.network.protocol.game.ClientGamePacketListener)

Aggregations

ClientGamePacketListener (net.minecraft.network.protocol.game.ClientGamePacketListener)1 Item (net.minecraft.world.item.Item)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 ChestBlockEntity (net.minecraft.world.level.block.entity.ChestBlockEntity)1 FurnaceBlockEntity (net.minecraft.world.level.block.entity.FurnaceBlockEntity)1 RandomizableContainerBlockEntity (net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity)1