use of net.minecraft.network.protocol.game.ClientGamePacketListener 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);
}
}
}
use of net.minecraft.network.protocol.game.ClientGamePacketListener in project MC-Prefab by Brian-Wuest.
the class Structure method setBlockEntities.
protected void setBlockEntities() {
for (BuildTileEntity buildTileEntity : this.tileEntities) {
try {
// Beds are processed separately.
if (buildTileEntity.getEntityName().equals("bed")) {
continue;
}
BlockPos tileEntityPos = buildTileEntity.getStartingPosition().getRelativePosition(this.originalPos, this.getClearSpace().getShape().getDirection(), this.configuration.houseFacing);
BlockEntity tileEntity = this.world.getBlockEntity(tileEntityPos);
BlockState tileBlock = this.world.getBlockState(tileEntityPos);
if (tileEntity != null) {
this.world.removeBlockEntity(tileEntityPos);
}
tileEntity = BlockEntity.loadStatic(tileEntityPos, tileBlock, buildTileEntity.getEntityDataTag());
if (tileEntity == null) {
continue;
}
this.world.removeBlockEntity(tileEntityPos);
tileEntity = BlockEntity.loadStatic(tileEntityPos, tileBlock, buildTileEntity.getEntityDataTag());
this.world.setBlockEntity(tileEntity);
this.world.getChunkAt(tileEntityPos).setUnsaved(true);
tileEntity.setChanged();
Packet<ClientGamePacketListener> packet = tileEntity.getUpdatePacket();
if (packet != null) {
this.world.getServer().getPlayerList().broadcastAll(packet);
}
} catch (Exception ex) {
Prefab.LOGGER.error(ex);
}
}
}
Aggregations