diff --git a/src/main/java/forestry/apiculture/blocks/BlockCandle.java b/src/main/java/forestry/apiculture/blocks/BlockCandle.java index 75a71873a..77dd30c7b 100755 --- a/src/main/java/forestry/apiculture/blocks/BlockCandle.java +++ b/src/main/java/forestry/apiculture/blocks/BlockCandle.java @@ -63,9 +63,9 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister, ITile public static final Set lightingItems; public static final String colourTagName = "colour"; - private static final PropertyEnum STATE = PropertyEnum.create("state", State.class); + public static final PropertyEnum STATE = PropertyEnum.create("state", State.class); - private enum State implements IStringSerializable { + enum State implements IStringSerializable { ON("on"), OFF("off"); private final String name; diff --git a/src/main/java/forestry/apiculture/blocks/BlockStump.java b/src/main/java/forestry/apiculture/blocks/BlockStump.java index bdf6d4213..871206b79 100755 --- a/src/main/java/forestry/apiculture/blocks/BlockStump.java +++ b/src/main/java/forestry/apiculture/blocks/BlockStump.java @@ -12,7 +12,6 @@ package forestry.apiculture.blocks; import java.util.Random; -import net.minecraft.block.Block; import net.minecraft.block.BlockTorch; import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; @@ -59,9 +58,7 @@ public class BlockStump extends BlockTorch implements IItemModelRegister { public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack heldItem = playerIn.getHeldItem(hand); if (BlockCandle.lightingItems.contains(heldItem.getItem())) { - IBlockState blockState = worldIn.getBlockState(pos); - Block block = blockState.getBlock(); - IBlockState activatedState = ModuleApiculture.getBlocks().candle.getStateFromMeta(block.getMetaFromState(blockState)); + IBlockState activatedState = ModuleApiculture.getBlocks().candle.getDefaultState().withProperty(BlockCandle.STATE, BlockCandle.State.ON); worldIn.setBlockState(pos, activatedState, Constants.FLAG_BLOCK_SYNC); TileCandle tc = new TileCandle(); tc.setColour(16777215); // default to white diff --git a/src/main/java/forestry/core/network/packets/PacketFXSignal.java b/src/main/java/forestry/core/network/packets/PacketFXSignal.java index d8d081741..6861af0d7 100644 --- a/src/main/java/forestry/core/network/packets/PacketFXSignal.java +++ b/src/main/java/forestry/core/network/packets/PacketFXSignal.java @@ -22,6 +22,8 @@ import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -63,9 +65,9 @@ public class PacketFXSignal extends ForestryPacket implements IForestryPacketCli data.writeBlockPos(pos); data.writeByte(visualFX.ordinal()); data.writeByte(soundFX.ordinal()); - Block block = blockState.getBlock(); - data.writeVarInt(Block.getIdFromBlock(block)); - data.writeVarInt(block.getMetaFromState(blockState)); + NBTTagCompound tag = new NBTTagCompound(); + NBTUtil.writeBlockState(tag, blockState); + data.writeCompoundTag(tag); } @Override @@ -80,10 +82,9 @@ public class PacketFXSignal extends ForestryPacket implements IForestryPacketCli BlockPos pos = data.readBlockPos(); VisualFXType visualFX = VisualFXType.values()[data.readByte()]; SoundFXType soundFX = SoundFXType.values()[data.readByte()]; - Block block = Block.getBlockById(data.readVarInt()); - IBlockState blockState = block.getStateFromMeta(data.readVarInt()); - World world = player.world; + IBlockState blockState = NBTUtil.readBlockState(data.readCompoundTag()); + Block block = blockState.getBlock(); if (visualFX == VisualFXType.BLOCK_BREAK) { Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(pos, blockState); diff --git a/src/main/java/forestry/core/worldgen/WorldGenerator.java b/src/main/java/forestry/core/worldgen/WorldGenerator.java index 0b359920a..77aee2748 100755 --- a/src/main/java/forestry/core/worldgen/WorldGenerator.java +++ b/src/main/java/forestry/core/worldgen/WorldGenerator.java @@ -68,15 +68,16 @@ public class WorldGenerator implements IWorldGenerator { } private void generateWorld(Random random, int chunkX, int chunkZ, World world) { - if(!Config.isValidOreDim(world.provider.getDimension())) + if (!Config.isValidOreDim(world.provider.getDimension())) { return; + } if (apatiteGenerator == null || copperGenerator == null || tinGenerator == null) { BlockResourceOre resourcesBlock = ModuleCore.getBlocks().resources; - IBlockState apatiteBlockState = resourcesBlock.getStateFromMeta(EnumResourceType.APATITE.getMeta()); - IBlockState copperBlockState = resourcesBlock.getStateFromMeta(EnumResourceType.COPPER.getMeta()); - IBlockState tinBlockState = resourcesBlock.getStateFromMeta(EnumResourceType.TIN.getMeta()); + IBlockState apatiteBlockState = resourcesBlock.getDefaultState().withProperty(BlockResourceOre.ORE_RESOURCES, EnumResourceType.APATITE); + IBlockState copperBlockState = resourcesBlock.getDefaultState().withProperty(BlockResourceOre.ORE_RESOURCES, EnumResourceType.COPPER); + IBlockState tinBlockState = resourcesBlock.getDefaultState().withProperty(BlockResourceOre.ORE_RESOURCES, EnumResourceType.TIN); apatiteGenerator = new WorldGenMinable(apatiteBlockState, 36); copperGenerator = new WorldGenMinable(copperBlockState, 6); tinGenerator = new WorldGenMinable(tinBlockState, 6); diff --git a/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java b/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java index 53e3ab2a1..b615c47aa 100644 --- a/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java +++ b/src/main/java/forestry/farming/logic/farmables/FarmableRusticSapling.java @@ -28,8 +28,9 @@ public class FarmableRusticSapling implements IFarmable { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - if (world.setBlockState(pos, germlingBlock.getStateFromMeta(germling.getItemDamage()))) { - PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, germlingBlock.getStateFromMeta(germling.getItemDamage())); + IBlockState blockState = germlingBlock.getStateFromMeta(germling.getItemDamage()); //TODO - stop using meta here + if (world.setBlockState(pos, blockState)) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState); NetworkUtil.sendNetworkPacket(packet, pos, world); return true; } diff --git a/src/main/java/forestry/farming/tiles/TileFarmPlain.java b/src/main/java/forestry/farming/tiles/TileFarmPlain.java index c78536c86..7c472febf 100644 --- a/src/main/java/forestry/farming/tiles/TileFarmPlain.java +++ b/src/main/java/forestry/farming/tiles/TileFarmPlain.java @@ -10,9 +10,12 @@ ******************************************************************************/ package forestry.farming.tiles; -import forestry.api.multiblock.IMultiblockController; import net.minecraft.util.math.BlockPos; +import forestry.api.multiblock.IMultiblockController; +import forestry.farming.blocks.BlockFarm; +import forestry.farming.blocks.EnumFarmBlockType; + public class TileFarmPlain extends TileFarm { @Override public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) { @@ -21,7 +24,7 @@ public class TileFarmPlain extends TileFarm { // set band block meta int bandY = maxCoord.getY() - 1; if (getPos().getY() == bandY) { - this.world.setBlockState(getPos(), getBlockType().getStateFromMeta(1), 2); + this.world.setBlockState(getPos(), getBlockType().getDefaultState().withProperty(BlockFarm.META, EnumFarmBlockType.BAND), 2); } } diff --git a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java index 1ea5a4603..775a5bb58 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java +++ b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java @@ -133,7 +133,7 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored if (rand.nextInt(24) != 0) { return false; } - + IButterfly butterfly = ButterflyManager.butterflyRoot.getMember(entityItem.getItem()); if (butterfly == null) { return false; @@ -163,25 +163,25 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored @Override public void registerModel(Item item, IModelManager manager) { switch (this.type) { - case CATERPILLAR: - manager.registerItemModel(item, 0, "caterpillar"); - break; - case BUTTERFLY: - manager.registerItemModel(item, 0, "butterflyGE"); - break; - case COCOON: - manager.registerItemModel(item, new CocoonMeshDefinition()); - for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) { - if (allele instanceof IAlleleButterflyCocoon) { - for (int age = 0; age < 3; age++) { - ModelBakery.registerItemVariants(this, - ((IAlleleButterflyCocoon) allele).getCocoonItemModel(age)); + case CATERPILLAR: + manager.registerItemModel(item, 0, "caterpillar"); + break; + case BUTTERFLY: + manager.registerItemModel(item, 0, "butterflyGE"); + break; + case COCOON: + manager.registerItemModel(item, new CocoonMeshDefinition()); + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) { + if (allele instanceof IAlleleButterflyCocoon) { + for (int age = 0; age < 3; age++) { + ModelBakery.registerItemVariants(this, + ((IAlleleButterflyCocoon) allele).getCocoonItemModel(age)); + } } } - } - break; - default: - manager.registerItemModel(item, 0, "liquids/jar"); + break; + default: + manager.registerItemModel(item, 0, "liquids/jar"); } } @@ -191,10 +191,10 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored NBTTagCompound tagCompound = itemstack.getTagCompound(); IButterflyGenome genome; int age; - if(tagCompound == null){ + if (tagCompound == null) { genome = ButterflyDefinition.CabbageWhite.getGenome(); age = 0; - }else { + } else { if (!tagCompound.hasKey(NBT_AGE)) { tagCompound.setInteger(NBT_AGE, 0); } @@ -223,8 +223,7 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored if (type == EnumFlutterType.COCOON) { pos = ButterflyManager.butterflyRoot.plantCocoon(world, pos, flutter, player.getGameProfile(), getAge(stack), true); if (pos != BlockPos.ORIGIN) { - PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, - world.getBlockState(pos)); + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState); NetworkUtil.sendNetworkPacket(packet, pos, world); if (!player.capabilities.isCreativeMode) { @@ -257,30 +256,30 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored return EnumActionResult.PASS; } } - - public static void setAge(ItemStack cocoon, int age){ - if(cocoon.isEmpty()){ + + public static void setAge(ItemStack cocoon, int age) { + if (cocoon.isEmpty()) { return; } if (ButterflyManager.butterflyRoot.getType(cocoon) != EnumFlutterType.COCOON) { return; } NBTTagCompound tagCompound = cocoon.getTagCompound(); - if(tagCompound == null){ + if (tagCompound == null) { cocoon.setTagCompound(tagCompound = new NBTTagCompound()); } tagCompound.setInteger(NBT_AGE, age); } - - public static int getAge(ItemStack cocoon){ - if(cocoon.isEmpty()){ + + public static int getAge(ItemStack cocoon) { + if (cocoon.isEmpty()) { return 0; } if (ButterflyManager.butterflyRoot.getType(cocoon) != EnumFlutterType.COCOON) { return 0; } NBTTagCompound tagCompound = cocoon.getTagCompound(); - if(tagCompound == null){ + if (tagCompound == null) { return 0; } return tagCompound.getInteger(NBT_AGE);