diff --git a/src/main/java/forestry/apiculture/blocks/BlockStump.java b/src/main/java/forestry/apiculture/blocks/BlockStump.java index 41f16aeb8..d04180c5a 100644 --- a/src/main/java/forestry/apiculture/blocks/BlockStump.java +++ b/src/main/java/forestry/apiculture/blocks/BlockStump.java @@ -61,7 +61,7 @@ public class BlockStump extends BlockTorch implements IItemModelRegister { IBlockState blockState = worldIn.getBlockState(pos); Block block = blockState.getBlock(); IBlockState activatedState = PluginApiculture.blocks.candle.getStateFromMeta(block.getMetaFromState(blockState) | 0x08); - worldIn.setBlockState(pos, activatedState, Constants.FLAG_BLOCK_SYNCH); + worldIn.setBlockState(pos, activatedState, Constants.FLAG_BLOCK_SYNC); TileCandle tc = new TileCandle(); tc.setColour(0); // default to white worldIn.setTileEntity(pos, tc); diff --git a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java index 108f2f2cd..9351e5de3 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java @@ -293,6 +293,6 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe @Override public boolean plantRandomFlower(String flowerType, World world, BlockPos pos) { Flower flower = getRandomPlantableFlower(flowerType, world.rand); - return world.setBlockState(pos, flower.getBlock().getStateFromMeta(flower.getMeta()), Constants.FLAG_BLOCK_SYNCH); + return world.setBlockState(pos, flower.getBlock().getStateFromMeta(flower.getMeta()), Constants.FLAG_BLOCK_SYNC); } } diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectGlacial.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectGlacial.java index 511c40379..ad72061e0 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectGlacial.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectGlacial.java @@ -20,7 +20,6 @@ import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.EnumTemperature; import forestry.api.genetics.IEffectData; -import forestry.core.config.Constants; import forestry.core.utils.VectUtil; public class AlleleEffectGlacial extends AlleleEffectThrottled { @@ -62,7 +61,7 @@ public class AlleleEffectGlacial extends AlleleEffectThrottled { continue; } - world.setBlockState(posBlock, Blocks.ICE.getDefaultState(), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE); + world.setBlockState(posBlock, Blocks.ICE.getDefaultState()); } return storedData; diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectRadioactive.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectRadioactive.java index b92c4f3fd..c4c742e6b 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectRadioactive.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectRadioactive.java @@ -27,6 +27,7 @@ import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.apiculture.blocks.BlockAlveary; +import forestry.core.utils.BlockUtil; import forestry.core.utils.DamageSourceForestry; import forestry.core.utils.VectUtil; @@ -103,7 +104,7 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled { continue; } - world.setBlockToAir(posBlock); + BlockUtil.setBlockToAirWithSound(world, posBlock, blockState); break; } diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectSnowing.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectSnowing.java index 53254f66f..130a47626 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectSnowing.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectSnowing.java @@ -22,7 +22,6 @@ import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.EnumTemperature; import forestry.api.genetics.IEffectData; -import forestry.core.config.Constants; import forestry.core.proxy.Proxies; import forestry.core.utils.VectUtil; @@ -68,10 +67,10 @@ public class AlleleEffectSnowing extends AlleleEffectThrottled { if (block == Blocks.SNOW_LAYER) { int meta = block.getMetaFromState(state); if (meta < 7) { - world.setBlockState(posBlock, block.getStateFromMeta(meta + 1), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE); + world.setBlockState(posBlock, block.getStateFromMeta(meta + 1)); } } else if (block.isReplaceable(world, posBlock)) { - world.setBlockState(posBlock, Blocks.SNOW_LAYER.getDefaultState(), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE); + world.setBlockState(posBlock, Blocks.SNOW_LAYER.getDefaultState()); } } diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java index 081ad5f3c..e4b1adc88 100755 --- a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java @@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.IChunkGenerator; + import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType; import net.minecraftforge.event.terraingen.TerrainGen; @@ -128,7 +129,7 @@ public abstract class HiveDecorator { private static boolean setHive(World world, BlockPos pos, Hive hive) { IBlockState hiveState = hive.getHiveBlockState(); Block hiveBlock = hiveState.getBlock(); - boolean placed = world.setBlockState(pos, hiveState, Constants.FLAG_BLOCK_SYNCH); + boolean placed = world.setBlockState(pos, hiveState, Constants.FLAG_BLOCK_SYNC); if (!placed) { return false; } diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java index f8d83c581..d81c33c4a 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java @@ -22,6 +22,7 @@ import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.BiomeDictionary; + import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.hives.HiveManager; import forestry.api.apiculture.hives.IHiveDescription; @@ -34,6 +35,7 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; import forestry.apiculture.PluginApiculture; import forestry.apiculture.genetics.BeeDefinition; +import forestry.core.config.Constants; public enum HiveDescription implements IHiveDescription { @@ -69,7 +71,7 @@ public enum HiveDescription implements IHiveDescription { @Override public void postGen(World world, BlockPos pos) { if (world.isAirBlock(pos.add(0, 1, 0))) { - world.setBlockState(pos.add(0, 1, 0), Blocks.SNOW_LAYER.getDefaultState(), 0); + world.setBlockState(pos.add(0, 1, 0), Blocks.SNOW_LAYER.getDefaultState(), Constants.FLAG_BLOCK_SYNC); } postGenFlowers(world, pos, flowerStates); diff --git a/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java b/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java index 8c8304289..737eeef59 100644 --- a/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java @@ -334,7 +334,7 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { } IBlockState beeHouseDefaultState = PluginApiculture.blocks.beeHouse.getDefaultState(); - world.setBlockState(posNew, beeHouseDefaultState, Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(posNew, beeHouseDefaultState, Constants.FLAG_BLOCK_SYNC); TileBeeHouse beeHouse = TileUtil.getTile(world, posNew, TileBeeHouse.class); if (beeHouse == null) { diff --git a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java index 2f635143d..0f121956d 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java @@ -1025,7 +1025,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe @Override public boolean setLeaves(ITreeGenome genome, World world, GameProfile owner, BlockPos pos) { - boolean placed = world.setBlockState(pos, PluginArboriculture.blocks.leaves.getDefaultState(), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE); + boolean placed = world.setBlockState(pos, PluginArboriculture.blocks.leaves.getDefaultState()); if (!placed) { return false; } diff --git a/src/main/java/forestry/arboriculture/genetics/TreeRoot.java b/src/main/java/forestry/arboriculture/genetics/TreeRoot.java index 8c6b235bc..ead82db2f 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeRoot.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeRoot.java @@ -59,8 +59,9 @@ import forestry.arboriculture.blocks.BlockFruitPod; import forestry.arboriculture.blocks.BlockSapling; import forestry.arboriculture.tiles.TileFruitPod; import forestry.arboriculture.tiles.TileSapling; -import forestry.core.config.Constants; import forestry.core.genetics.SpeciesRoot; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.proxy.Proxies; import forestry.core.tiles.TileUtil; import forestry.core.utils.BlockUtil; import forestry.core.utils.GeneticsUtil; @@ -210,12 +211,13 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { public boolean plantSapling(World world, ITree tree, GameProfile owner, BlockPos pos) { IBlockState state = PluginArboriculture.blocks.saplingGE.getDefaultState().withProperty(BlockSapling.TREE, tree.getGenome().getPrimary()); - boolean placed = world.setBlockState(pos, state, Constants.FLAG_BLOCK_SYNCH_AND_UPDATE); + boolean placed = world.setBlockState(pos, state); if (!placed) { return false; } - Block block = world.getBlockState(pos).getBlock(); + IBlockState blockState = world.getBlockState(pos); + Block block = blockState.getBlock(); if (PluginArboriculture.blocks.saplingGE != block) { return false; } @@ -230,6 +232,9 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { sapling.setTree(tree.copy()); sapling.setOwner(owner); + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); + return true; } diff --git a/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java b/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java index 912a4528f..e304ab45e 100755 --- a/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java +++ b/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java @@ -17,6 +17,7 @@ import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumActionResult; @@ -164,7 +165,6 @@ public class ItemGermlingGE extends ItemGE implements IVariableFermentable, ICol } if (TreeManager.treeRoot.plantSapling(worldIn, tree, playerIn.getGameProfile(), pos)) { - Proxies.common.addBlockPlaceEffects(worldIn, pos, worldIn.getBlockState(pos)); if (!playerIn.capabilities.isCreativeMode) { stack.stackSize--; } @@ -191,8 +191,10 @@ public class ItemGermlingGE extends ItemGE implements IVariableFermentable, ICol } pollinatable.mateWith(tree); - Proxies.common.sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.LEAF, worldIn, pos, - worldIn.getBlockState(pos)); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, Blocks.LEAVES.getDefaultState()); + Proxies.net.sendNetworkPacket(packet, worldIn); + if (!playerIn.capabilities.isCreativeMode) { stack.stackSize--; } diff --git a/src/main/java/forestry/arboriculture/tiles/TileFruitPod.java b/src/main/java/forestry/arboriculture/tiles/TileFruitPod.java index ec4984911..de466f01d 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileFruitPod.java +++ b/src/main/java/forestry/arboriculture/tiles/TileFruitPod.java @@ -36,6 +36,7 @@ import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; import forestry.core.network.packets.PacketTileStream; +import forestry.core.utils.BlockUtil; import forestry.core.utils.Log; public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamable { @@ -142,8 +143,9 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl Collection fruits = getDrops(); maturity = 0; - IBlockState state = worldObj.getBlockState(getPos()).withProperty(BlockCocoa.AGE, 0); - worldObj.setBlockState(getPos(), state); + IBlockState oldState = worldObj.getBlockState(getPos()); + IBlockState newState = oldState.withProperty(BlockCocoa.AGE, 0); + BlockUtil.setBlockWithBreakSound(worldObj, getPos(), newState, oldState); return fruits; } diff --git a/src/main/java/forestry/core/blocks/BlockBogEarth.java b/src/main/java/forestry/core/blocks/BlockBogEarth.java index 21cfccb8a..ff6cb8e4e 100644 --- a/src/main/java/forestry/core/blocks/BlockBogEarth.java +++ b/src/main/java/forestry/core/blocks/BlockBogEarth.java @@ -133,8 +133,7 @@ public class BlockBogEarth extends Block implements IItemModelRegister, IBlockWi if (type == SoilType.BOG_EARTH) { if (isMoistened(world, pos)) { - world.setBlockState(pos, state.withProperty(MATURITY, maturity + 1), Constants.FLAG_BLOCK_SYNCH); - world.markBlockRangeForRenderUpdate(pos, pos); + world.setBlockState(pos, state.withProperty(MATURITY, maturity + 1), Constants.FLAG_BLOCK_SYNC); } } } diff --git a/src/main/java/forestry/core/blocks/BlockHumus.java b/src/main/java/forestry/core/blocks/BlockHumus.java index 911f156bb..33f2c8f27 100644 --- a/src/main/java/forestry/core/blocks/BlockHumus.java +++ b/src/main/java/forestry/core/blocks/BlockHumus.java @@ -115,9 +115,9 @@ public class BlockHumus extends Block implements IItemModelRegister { degrade++; if (degrade >= degradeDelimiter) { - world.setBlockState(pos, Blocks.SAND.getDefaultState(), Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(pos, Blocks.SAND.getDefaultState(), Constants.FLAG_BLOCK_SYNC); } else { - world.setBlockState(pos, blockState.withProperty(DEGRADE, degrade), Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(pos, blockState.withProperty(DEGRADE, degrade), Constants.FLAG_BLOCK_SYNC); } world.markBlockRangeForRenderUpdate(pos, pos); } diff --git a/src/main/java/forestry/core/config/Constants.java b/src/main/java/forestry/core/config/Constants.java index a7000a566..204d3c9e2 100644 --- a/src/main/java/forestry/core/config/Constants.java +++ b/src/main/java/forestry/core/config/Constants.java @@ -24,8 +24,7 @@ public class Constants implements IForestryConstants { public static final String BUILD_NUMBER = "@BUILD_NUMBER@"; public static final int FLAG_BLOCK_UPDATE = 1; - public static final int FLAG_BLOCK_SYNCH = 2; - public static final int FLAG_BLOCK_SYNCH_AND_UPDATE = FLAG_BLOCK_UPDATE + FLAG_BLOCK_SYNCH; + public static final int FLAG_BLOCK_SYNC = 2; public static final int BUCKET_VOLUME = 1000; public static final int FLUID_PER_HONEY_DROP = 100; diff --git a/src/main/java/forestry/core/network/packets/PacketFXSignal.java b/src/main/java/forestry/core/network/packets/PacketFXSignal.java index 628ae59c6..85e06c377 100644 --- a/src/main/java/forestry/core/network/packets/PacketFXSignal.java +++ b/src/main/java/forestry/core/network/packets/PacketFXSignal.java @@ -12,11 +12,11 @@ package forestry.core.network.packets; import java.io.IOException; +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -25,87 +25,76 @@ import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IForestryPacketClient; import forestry.core.network.PacketIdClient; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemStackUtil; public class PacketFXSignal extends PacketCoordinates implements IForestryPacketClient { public enum VisualFXType { - NONE, BLOCK_DESTROY, SAPLING_PLACE + NONE, BLOCK_BREAK, SAPLING_PLACE } public enum SoundFXType { - NONE(null), - BLOCK_DESTROY(null), - BLOCK_PLACE(null), - LEAF(Blocks.LEAVES.getSoundType().getStepSound()), - LOG(Blocks.LOG.getSoundType().getBreakSound()), - DIRT(Blocks.DIRT.getSoundType().getBreakSound()); - - public final SoundEvent soundEvent; - public final float volume; - public final float pitch; - - SoundFXType(SoundEvent soundEvent) { - this.soundEvent = soundEvent; - this.volume = 1.0f; - this.pitch = 1.0f; - } + NONE, BLOCK_BREAK, BLOCK_PLACE; } private VisualFXType visualFX; private SoundFXType soundFX; - private IBlockState state; + private IBlockState blockState; public PacketFXSignal() { } - public PacketFXSignal(VisualFXType type, BlockPos pos, IBlockState state) { - this(type, SoundFXType.NONE, pos, state); + public PacketFXSignal(VisualFXType type, BlockPos pos, IBlockState blockState) { + this(type, SoundFXType.NONE, pos, blockState); } - public PacketFXSignal(SoundFXType type, BlockPos pos, IBlockState state) { - this(VisualFXType.NONE, type, pos, state); + public PacketFXSignal(SoundFXType type, BlockPos pos, IBlockState blockState) { + this(VisualFXType.NONE, type, pos, blockState); } - public PacketFXSignal(VisualFXType visualFX, SoundFXType soundFX, BlockPos pos, IBlockState state) { + public PacketFXSignal(VisualFXType visualFX, SoundFXType soundFX, BlockPos pos, IBlockState blockState) { super(pos); this.visualFX = visualFX; this.soundFX = soundFX; - this.state = state; + this.blockState = blockState; } @Override public void writeData(DataOutputStreamForestry data) throws IOException { super.writeData(data); - data.writeShort(visualFX.ordinal()); - data.writeShort(soundFX.ordinal()); - data.writeInt(state.getBlock().getMetaFromState(state)); - data.writeUTF(ItemStackUtil.getBlockNameFromRegistryAsSting(state.getBlock())); + data.writeByte(visualFX.ordinal()); + data.writeByte(soundFX.ordinal()); + Block block = blockState.getBlock(); + data.writeVarInt(Block.getIdFromBlock(block)); + data.writeVarInt(block.getMetaFromState(blockState)); } @Override public void readData(DataInputStreamForestry data) throws IOException { super.readData(data); - this.visualFX = VisualFXType.values()[data.readShort()]; - this.soundFX = SoundFXType.values()[data.readShort()]; - int meta = data.readInt(); - this.state = ItemStackUtil.getBlockFromRegistry(data.readUTF()).getStateFromMeta(meta); + this.visualFX = VisualFXType.values()[data.readByte()]; + this.soundFX = SoundFXType.values()[data.readByte()]; + Block block = Block.getBlockById(data.readVarInt()); + this.blockState = block.getStateFromMeta(data.readVarInt()); } @Override public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException { - World renderWorld = Proxies.common.getRenderWorld(); - if (visualFX != VisualFXType.NONE) { - Proxies.common.addBlockDestroyEffects(renderWorld, getPos(), state); + World world = player.getEntityWorld(); + BlockPos pos = getPos(); + + if (visualFX == VisualFXType.BLOCK_BREAK) { + Proxies.common.addBlockDestroyEffects(world, pos, blockState); } + if (soundFX != SoundFXType.NONE) { - if (soundFX == SoundFXType.BLOCK_DESTROY) { - Proxies.common.playBlockBreakSoundFX(renderWorld, getPos(), state); + Block block = blockState.getBlock(); + SoundType soundType = block.getSoundType(); + + if (soundFX == SoundFXType.BLOCK_BREAK) { + world.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getBreakSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false); } else if (soundFX == SoundFXType.BLOCK_PLACE) { - Proxies.common.playBlockPlaceSoundFX(renderWorld, getPos(), state); - } else { - Proxies.common.playSoundFX(renderWorld, getPos(), soundFX.soundEvent, SoundCategory.BLOCKS, soundFX.volume, soundFX.pitch); + world.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false); } } } diff --git a/src/main/java/forestry/core/proxy/Proxies.java b/src/main/java/forestry/core/proxy/Proxies.java index ff46eeb79..6e2572c21 100755 --- a/src/main/java/forestry/core/proxy/Proxies.java +++ b/src/main/java/forestry/core/proxy/Proxies.java @@ -13,7 +13,7 @@ package forestry.core.proxy; import net.minecraftforge.fml.common.SidedProxy; public class Proxies { - @SidedProxy(clientSide = "forestry.core.proxy.ProxyCommonClient", serverSide = "forestry.core.proxy.ProxyCommon") + @SidedProxy(clientSide = "forestry.core.proxy.ProxyClient", serverSide = "forestry.core.proxy.ProxyCommon") public static ProxyCommon common; @SidedProxy(clientSide = "forestry.core.proxy.ProxyNetworkClient", serverSide = "forestry.core.proxy.ProxyNetwork") public static ProxyNetwork net; diff --git a/src/main/java/forestry/core/proxy/ProxyCommonClient.java b/src/main/java/forestry/core/proxy/ProxyClient.java similarity index 63% rename from src/main/java/forestry/core/proxy/ProxyCommonClient.java rename to src/main/java/forestry/core/proxy/ProxyClient.java index e0090f5d6..24caa7a99 100644 --- a/src/main/java/forestry/core/proxy/ProxyCommonClient.java +++ b/src/main/java/forestry/core/proxy/ProxyClient.java @@ -19,8 +19,6 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -31,11 +29,10 @@ import org.lwjgl.input.Keyboard; import forestry.core.TickHandlerCoreClient; import forestry.core.models.ModelManager; import forestry.core.multiblock.MultiblockClientTickHandler; -import forestry.core.network.packets.PacketFXSignal; import forestry.core.render.TextureManager; import forestry.core.worldgen.WorldGenerator; -public class ProxyCommonClient extends ProxyCommon { +public class ProxyClient extends ProxyCommon { @Override public void registerTickHandlers(WorldGenerator worldGenerator) { @@ -92,45 +89,8 @@ public class ProxyCommonClient extends ProxyCommon { } @Override - public void playBlockBreakSoundFX(World world, BlockPos pos, IBlockState state) { - Block block = state.getBlock(); - playSoundFX(world, pos, block.getSoundType().getBreakSound(), SoundCategory.BLOCKS, block.getSoundType().getVolume() / 4, block.getSoundType().getPitch()); - } - - @Override - public void playBlockPlaceSoundFX(World world, BlockPos pos, IBlockState state) { - Block block = state.getBlock(); - playSoundFX(world, pos, block.getSoundType().getStepSound(), SoundCategory.BLOCKS, block.getSoundType().getVolume() / 4, block.getSoundType().getPitch()); - } - - @Override - public void sendFXSignal(PacketFXSignal.VisualFXType visualFX, PacketFXSignal.SoundFXType soundFX, World world, BlockPos pos, IBlockState state) { - } - - @Override - public void playSoundFX(World world, BlockPos pos, SoundEvent sound, SoundCategory soundCategory, float volume, float pitch) { - int x = pos.getX(); - int y = pos.getY(); - int z = pos.getZ(); - world.playSound(x + 0.5, y + 0.5, z + 0.5, sound, soundCategory, volume, pitch, false); - } - - @Override - public void addBlockDestroyEffects(World world, BlockPos pos, IBlockState state) { - if (world.isRemote) { - getClientInstance().effectRenderer.addBlockDestroyEffects(pos, state); - } else { - super.addBlockDestroyEffects(world, pos, state); - } - } - - @Override - public void addBlockPlaceEffects(World world, BlockPos pos, IBlockState state) { - if (world.isRemote) { - playBlockPlaceSoundFX(world, pos, state); - } else { - super.addBlockPlaceEffects(world, pos, state); - } + public void addBlockDestroyEffects(World world, BlockPos pos, IBlockState blockState) { + Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(pos, blockState); } @Override diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 2d4f2c599..c1d0f7242 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -20,8 +20,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.server.management.UserListOpsEntry; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -32,7 +30,6 @@ import net.minecraftforge.fml.common.Loader; import forestry.core.TickHandlerCoreServer; import forestry.core.multiblock.MultiblockServerTickHandler; -import forestry.core.network.packets.PacketFXSignal; import forestry.core.worldgen.WorldGenerator; public class ProxyCommon { @@ -79,25 +76,8 @@ public class ProxyCommon { return false; } - public void playSoundFX(World world, BlockPos pos, SoundEvent sound, SoundCategory soundCategory, float volume, float pitch) { - } + public void addBlockDestroyEffects(World world, BlockPos pos, IBlockState blockState) { - public void addBlockDestroyEffects(World world, BlockPos pos, IBlockState state) { - sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.BLOCK_DESTROY, world, pos, state); - } - - public void addBlockPlaceEffects(World world, BlockPos pos, IBlockState state) { - sendFXSignal(PacketFXSignal.VisualFXType.NONE, PacketFXSignal.SoundFXType.BLOCK_PLACE, world, pos, state); - } - - public void playBlockBreakSoundFX(World world, BlockPos pos, IBlockState state) { - } - - public void playBlockPlaceSoundFX(World world, BlockPos pos, IBlockState state) { - } - - public void sendFXSignal(PacketFXSignal.VisualFXType visualFX, PacketFXSignal.SoundFXType soundFX, World world, BlockPos pos, IBlockState state) { - Proxies.net.sendNetworkPacket(new PacketFXSignal(visualFX, soundFX, pos, state), world); } public World getRenderWorld() { diff --git a/src/main/java/forestry/core/utils/BlockUtil.java b/src/main/java/forestry/core/utils/BlockUtil.java index a937815e3..b441c3996 100644 --- a/src/main/java/forestry/core/utils/BlockUtil.java +++ b/src/main/java/forestry/core/utils/BlockUtil.java @@ -34,6 +34,8 @@ import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.proxy.Proxies; import forestry.core.tiles.TileEngine; import cofh.api.energy.IEnergyConnection; @@ -314,4 +316,31 @@ public abstract class BlockUtil { return !blockAccess.getBlockState(pos.offset(side)).doesSideBlockRendering(blockAccess, pos.offset(side), side.getOpposite()); } + + public static boolean setBlockWithPlaceSound(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState blockState) { + if (world.setBlockState(pos, blockState)) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); + return true; + } + return false; + } + + public static boolean setBlockWithBreakSound(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState blockState, @Nonnull IBlockState oldState) { + if (world.setBlockState(pos, blockState)) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, oldState); + Proxies.net.sendNetworkPacket(packet, world); + return true; + } + return false; + } + + public static boolean setBlockToAirWithSound(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState oldState) { + if (world.setBlockToAir(pos)) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, oldState); + Proxies.net.sendNetworkPacket(packet, world); + return true; + } + return false; + } } diff --git a/src/main/java/forestry/farming/blocks/BlockMushroom.java b/src/main/java/forestry/farming/blocks/BlockMushroom.java index 30f93201f..2c7894f91 100644 --- a/src/main/java/forestry/farming/blocks/BlockMushroom.java +++ b/src/main/java/forestry/farming/blocks/BlockMushroom.java @@ -18,6 +18,7 @@ import java.util.Random; import net.minecraft.block.BlockBush; import net.minecraft.block.BlockDirt; import net.minecraft.block.IGrowable; +import net.minecraft.block.SoundType; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; @@ -77,6 +78,7 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro setCreativeTab(null); setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MushroomType.BROWN).withProperty(MATURE, false)); setTickRandomly(true); + setSoundType(SoundType.PLANT); } @Override @@ -134,7 +136,7 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro IBlockState blockState = world.getBlockState(pos); if (!blockState.getValue(MATURE)) { - world.setBlockState(pos, blockState.withProperty(MATURE, true), Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(pos, blockState.withProperty(MATURE, true), Constants.FLAG_BLOCK_SYNC); } else { int lightValue1 = world.getLightFromNeighbors(pos.up()); if (lightValue1 <= 7) { diff --git a/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java b/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java index d9d4daca1..e174fc28c 100644 --- a/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java +++ b/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java @@ -15,13 +15,11 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import forestry.core.config.Constants; -import forestry.core.proxy.Proxies; +import forestry.core.utils.BlockUtil; public class CropBasicAgriCraft extends Crop { @@ -45,8 +43,9 @@ public class CropBasicAgriCraft extends Crop { harvest.remove(1); //AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting doesn't return them. } harvest.remove(0); - Proxies.common.addBlockDestroyEffects(world, pos, Blocks.MELON_BLOCK.getDefaultState()); - world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH); + + IBlockState oldState = world.getBlockState(pos); + BlockUtil.setBlockWithBreakSound(world, pos, block.getDefaultState(), oldState); return harvest; } diff --git a/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java b/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java index fe7890655..925503f0e 100644 --- a/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java +++ b/src/main/java/forestry/farming/logic/CropBasicGrowthCraft.java @@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import forestry.core.config.Constants; +import forestry.core.network.packets.PacketFXSignal; import forestry.core.proxy.Proxies; public class CropBasicGrowthCraft extends Crop { @@ -47,16 +48,19 @@ public class CropBasicGrowthCraft extends Crop { if (harvest.size() > 1) { harvest.remove(0); //Hops have rope as first drop. } - Proxies.common.addBlockDestroyEffects(world, pos, blockState); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); + if (isGrape) { world.setBlockToAir(pos); } else { - world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNC); } if (isRice) { // TODO: GrowthCraft for MC 1.9. Don't use meta, get the actual block state. - world.setBlockState(pos.down(), block.getStateFromMeta(7), Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(pos.down(), block.getStateFromMeta(7), Constants.FLAG_BLOCK_SYNC); } return harvest; diff --git a/src/main/java/forestry/farming/logic/CropDestroy.java b/src/main/java/forestry/farming/logic/CropDestroy.java index 1f24b7c82..169aae206 100644 --- a/src/main/java/forestry/farming/logic/CropDestroy.java +++ b/src/main/java/forestry/farming/logic/CropDestroy.java @@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import forestry.core.config.Constants; +import forestry.core.network.packets.PacketFXSignal; import forestry.core.proxy.Proxies; public class CropDestroy extends Crop { @@ -43,10 +44,12 @@ public class CropDestroy extends Crop { protected Collection harvestBlock(World world, BlockPos pos) { Block block = blockState.getBlock(); Collection harvested = block.getDrops(world, pos, blockState, 0); - Proxies.common.addBlockDestroyEffects(world, pos, blockState); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); if (replantState != null) { - world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNCH); + world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC); } else { world.setBlockToAir(pos); } diff --git a/src/main/java/forestry/farming/logic/CropFruit.java b/src/main/java/forestry/farming/logic/CropFruit.java index e5e31bb51..6d06f96f8 100755 --- a/src/main/java/forestry/farming/logic/CropFruit.java +++ b/src/main/java/forestry/farming/logic/CropFruit.java @@ -54,7 +54,8 @@ public class CropFruit extends Crop { } IBlockState blockState = world.getBlockState(pos); - Proxies.common.sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.LEAF, world, pos, blockState); + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); return ((IFruitBearer) tile).pickFruit(null); } diff --git a/src/main/java/forestry/farming/logic/CropPeat.java b/src/main/java/forestry/farming/logic/CropPeat.java index 0e82a4cab..679da9484 100755 --- a/src/main/java/forestry/farming/logic/CropPeat.java +++ b/src/main/java/forestry/farming/logic/CropPeat.java @@ -24,6 +24,7 @@ import net.minecraft.world.World; import forestry.core.PluginCore; import forestry.core.blocks.BlockBogEarth; import forestry.core.config.Constants; +import forestry.core.network.packets.PacketFXSignal; import forestry.core.proxy.Proxies; public class CropPeat extends Crop { @@ -50,8 +51,11 @@ public class CropPeat extends Crop { drops.add(PluginCore.items.peat.getItemStack()); IBlockState blockState = world.getBlockState(pos); - Proxies.common.addBlockDestroyEffects(world, pos, blockState); - world.setBlockState(pos, Blocks.DIRT.getDefaultState(), Constants.FLAG_BLOCK_SYNCH); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); + + world.setBlockState(pos, Blocks.DIRT.getDefaultState(), Constants.FLAG_BLOCK_SYNC); return drops; } diff --git a/src/main/java/forestry/farming/logic/CropRubber.java b/src/main/java/forestry/farming/logic/CropRubber.java index f6a0aaeee..585caaa2a 100755 --- a/src/main/java/forestry/farming/logic/CropRubber.java +++ b/src/main/java/forestry/farming/logic/CropRubber.java @@ -19,6 +19,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import forestry.core.config.Constants; +import forestry.core.network.packets.PacketFXSignal; import forestry.core.proxy.Proxies; import forestry.plugins.compat.PluginIC2; @@ -33,8 +34,11 @@ public class CropRubber extends CropDestroy { protected Collection harvestBlock(World world, BlockPos pos) { Collection harvested = new ArrayList<>(); harvested.add(PluginIC2.resin.copy()); - Proxies.common.addBlockDestroyEffects(world, pos, blockState); - world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNCH); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + Proxies.net.sendNetworkPacket(packet, world); + + world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC); return harvested; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicCocoa.java b/src/main/java/forestry/farming/logic/FarmLogicCocoa.java index d13361dff..582d9b150 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCocoa.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCocoa.java @@ -20,8 +20,10 @@ import java.util.Set; import java.util.Stack; import net.minecraft.block.Block; +import net.minecraft.block.BlockOldLog; import net.minecraft.block.BlockPlanks; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -46,6 +48,12 @@ public class FarmLogicCocoa extends FarmLogic { return Items.DYE; } + @Override + @SideOnly(Side.CLIENT) + public int getMetadata() { + return 3; + } + @Override public String getName() { return "Cocoa Plantation"; @@ -128,9 +136,7 @@ public class FarmLogicCocoa extends FarmLogic { private boolean tryPlantingCocoa(World world, IFarmHousing farmHousing, BlockPos position) { BlockPos.MutableBlockPos current = new BlockPos.MutableBlockPos(position); IBlockState blockState = world.getBlockState(current); - Block block = blockState.getBlock(); - while (block.isWood(world, current) && blockState.getValue(BlockPlanks.VARIANT) == BlockPlanks.EnumType.JUNGLE) { - + while (isJungleTreeTrunk(blockState)) { for (EnumFacing direction : EnumFacing.HORIZONTALS) { BlockPos candidate = new BlockPos(current.getX() + direction.getFrontOffsetX(), current.getY(), current.getZ() + direction.getFrontOffsetZ()); if (world.isAirBlock(candidate)) { @@ -144,12 +150,19 @@ public class FarmLogicCocoa extends FarmLogic { } blockState = world.getBlockState(current); - blockState.getBlock(); } return false; } + private static boolean isJungleTreeTrunk(IBlockState blockState) { + Block block = blockState.getBlock(); + if (block == Blocks.LOG && blockState.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE) { + return true; + } + return false; + } + private Collection getHarvestBlocks(World world, BlockPos position) { Set seen = new HashSet<>(); diff --git a/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java b/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java index 0b43af6d2..e44527592 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java +++ b/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java @@ -105,7 +105,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic { produce.addAll(BlockUtil.getBlockDrops(world, position)); - world.setBlockState(position, this.soilState); + BlockUtil.setBlockWithPlaceSound(world, position, this.soilState); farmHousing.getFarmInventory().removeResources(resources); return true; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicWatered.java b/src/main/java/forestry/farming/logic/FarmLogicWatered.java index e780d0b20..11ab5fb4a 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicWatered.java +++ b/src/main/java/forestry/farming/logic/FarmLogicWatered.java @@ -149,7 +149,9 @@ public abstract class FarmLogicWatered extends FarmLogic { if (!farmHousing.getFarmInventory().hasResources(resources)) { return false; } - world.setBlockState(position, ground); + if (!BlockUtil.setBlockWithPlaceSound(world, position, ground)) { + return false; + } farmHousing.getFarmInventory().removeResources(resources); return true; } @@ -164,7 +166,7 @@ public abstract class FarmLogicWatered extends FarmLogic { } produce.addAll(BlockUtil.getBlockDrops(world, position)); - world.setBlockState(position, Blocks.WATER.getDefaultState()); + BlockUtil.setBlockWithPlaceSound(world, position, Blocks.WATER.getDefaultState()); farmHousing.removeLiquid(STACK_WATER); return true; } diff --git a/src/main/java/forestry/farming/logic/FarmableAgingCrop.java b/src/main/java/forestry/farming/logic/FarmableAgingCrop.java index 16259bc6e..d3ce36d01 100644 --- a/src/main/java/forestry/farming/logic/FarmableAgingCrop.java +++ b/src/main/java/forestry/farming/logic/FarmableAgingCrop.java @@ -12,9 +12,10 @@ import net.minecraft.world.World; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; /** - * For blocks that are harvestable once they are a certain aga. + * For blocks that are harvestable once they are a certain age. */ public class FarmableAgingCrop implements IFarmable { protected final ItemStack germling; @@ -53,13 +54,17 @@ public class FarmableAgingCrop implements IFarmable { } if (replantAge != null) { - IBlockState replantState = cropBlock.getDefaultState().withProperty(ageProperty, replantAge); + IBlockState replantState = getReplantState(world, pos, blockState); return new CropDestroy(world, blockState, pos, replantState); } else { return new CropDestroy(world, blockState, pos, null); } } + protected IBlockState getReplantState(World world, BlockPos pos, IBlockState blockState) { + return blockState.withProperty(ageProperty, replantAge); + } + @Override public boolean isGermling(ItemStack itemstack) { return ItemStack.areItemsEqual(germling, itemstack); @@ -68,7 +73,7 @@ public class FarmableAgingCrop implements IFarmable { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { IBlockState plantedState = cropBlock.getDefaultState().withProperty(ageProperty, 0); - return world.setBlockState(pos, plantedState); + return BlockUtil.setBlockWithPlaceSound(world, pos, plantedState); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableBase.java b/src/main/java/forestry/farming/logic/FarmableBase.java index 4062db58b..c871a18c9 100644 --- a/src/main/java/forestry/farming/logic/FarmableBase.java +++ b/src/main/java/forestry/farming/logic/FarmableBase.java @@ -8,7 +8,7 @@ import net.minecraft.world.World; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; -import forestry.core.config.Constants; +import forestry.core.utils.BlockUtil; public abstract class FarmableBase implements IFarmable { protected final ItemStack germling; @@ -49,7 +49,7 @@ public abstract class FarmableBase implements IFarmable { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - return world.setBlockState(pos, plantedState, Constants.FLAG_BLOCK_SYNCH); + return BlockUtil.setBlockWithPlaceSound(world, pos, plantedState); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableBasicGrowthCraft.java b/src/main/java/forestry/farming/logic/FarmableBasicGrowthCraft.java index b24116a73..fe5c42420 100644 --- a/src/main/java/forestry/farming/logic/FarmableBasicGrowthCraft.java +++ b/src/main/java/forestry/farming/logic/FarmableBasicGrowthCraft.java @@ -46,7 +46,7 @@ public class FarmableBasicGrowthCraft { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - return world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH); + return world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNC); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableCocoa.java b/src/main/java/forestry/farming/logic/FarmableCocoa.java index 9954ba175..0f821f020 100755 --- a/src/main/java/forestry/farming/logic/FarmableCocoa.java +++ b/src/main/java/forestry/farming/logic/FarmableCocoa.java @@ -27,7 +27,7 @@ public class FarmableCocoa extends FarmableAgingCrop { public static final int COCOA_META = 3; public FarmableCocoa() { - super(new ItemStack(COCOA_SEED, 1, COCOA_META), Blocks.COCOA, BlockCocoa.AGE, 2, 0); + super(new ItemStack(COCOA_SEED, 1, COCOA_META), Blocks.COCOA, BlockCocoa.AGE, 2, null); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableGenericSapling.java b/src/main/java/forestry/farming/logic/FarmableGenericSapling.java deleted file mode 100755 index 870d71740..000000000 --- a/src/main/java/forestry/farming/logic/FarmableGenericSapling.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.farming.logic; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmable; - -public class FarmableGenericSapling implements IFarmable { - protected final ItemStack germling; - protected final IBlockState plantedState; - private final boolean replant; - private final ItemStack[] windfall; - - public FarmableGenericSapling(ItemStack germling, IBlockState plantedState, boolean replant, ItemStack... windfall) { - this.germling = germling; - this.plantedState = plantedState; - this.replant = replant; - this.windfall = windfall; - } - - @Override - public boolean isSaplingAt(World world, BlockPos pos) { - return world.getBlockState(pos).getBlock() == plantedState.getBlock(); - } - - @Override - public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { - Block block = blockState.getBlock(); - if (!block.isWood(world, pos)) { - return null; - } - - if (replant) { - return new CropDestroy(world, blockState, pos, plantedState); - } else { - return new CropDestroy(world, blockState, pos, null); - } - } - - @Override - public boolean isGermling(ItemStack itemstack) { - return ItemStack.areItemsEqual(germling, itemstack); - } - - @Override - public boolean isWindfall(ItemStack itemstack) { - for (ItemStack drop : windfall) { - if (drop.isItemEqual(itemstack)) { - return true; - } - } - return false; - } - - @Override - public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - return germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0) == EnumActionResult.SUCCESS; - } - -} diff --git a/src/main/java/forestry/farming/logic/FarmableGourd.java b/src/main/java/forestry/farming/logic/FarmableGourd.java index 68a43a206..3c1efe3b2 100755 --- a/src/main/java/forestry/farming/logic/FarmableGourd.java +++ b/src/main/java/forestry/farming/logic/FarmableGourd.java @@ -19,6 +19,7 @@ import net.minecraft.world.World; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; public class FarmableGourd implements IFarmable { @@ -59,7 +60,7 @@ public class FarmableGourd implements IFarmable { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - return world.setBlockState(pos, stem.getDefaultState()); + return BlockUtil.setBlockWithPlaceSound(world, pos, stem.getDefaultState()); } } diff --git a/src/main/java/forestry/farming/logic/FarmableStacked.java b/src/main/java/forestry/farming/logic/FarmableStacked.java index 7b11b6888..2bc8bea39 100755 --- a/src/main/java/forestry/farming/logic/FarmableStacked.java +++ b/src/main/java/forestry/farming/logic/FarmableStacked.java @@ -19,6 +19,7 @@ import net.minecraft.world.World; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; public class FarmableStacked implements IFarmable { protected final ItemStack germling; @@ -55,8 +56,7 @@ public class FarmableStacked implements IFarmable { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { - IBlockState plantedState = cropBlock.getDefaultState(); - return world.setBlockState(pos, plantedState); + return BlockUtil.setBlockWithPlaceSound(world, pos, cropBlock.getDefaultState()); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java b/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java index c1c7d792a..54f5e1806 100755 --- a/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java +++ b/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.farming.logic; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -23,14 +25,22 @@ import net.minecraft.world.World; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.TreeManager; import forestry.api.core.ForestryAPI; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; import forestry.api.genetics.IIndividual; +import forestry.core.network.packets.PacketFXSignal; +import forestry.core.proxy.Proxies; import forestry.core.utils.GeneticsUtil; import forestry.plugins.ForestryPluginUids; -public class FarmableVanillaSapling extends FarmableGenericSapling { +public class FarmableVanillaSapling implements IFarmable { + + protected final ItemStack germling; + private final ItemStack[] windfall; public FarmableVanillaSapling() { - super(new ItemStack(Blocks.SAPLING), Blocks.SAPLING.getDefaultState(), false, new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META)); + this.germling = new ItemStack(Blocks.SAPLING); + this.windfall = new ItemStack[]{new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META)}; } @Override @@ -43,8 +53,43 @@ public class FarmableVanillaSapling extends FarmableGenericSapling { return TreeManager.treeRoot.plantSapling(world, (ITree) tree, player.getGameProfile(), pos); } else { - return germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0) == EnumActionResult.SUCCESS; + EnumActionResult actionResult = germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); + if (actionResult == EnumActionResult.SUCCESS) { + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState()); + Proxies.net.sendNetworkPacket(packet, world); + return true; + } + return false; } } + @Override + public boolean isSaplingAt(World world, BlockPos pos) { + return world.getBlockState(pos).getBlock() == Blocks.SAPLING; + } + + @Override + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + Block block = blockState.getBlock(); + if (!block.isWood(world, pos)) { + return null; + } + + return new CropDestroy(world, blockState, pos, null); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + return ItemStack.areItemsEqual(germling, itemstack); + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + for (ItemStack drop : windfall) { + if (drop.isItemEqual(itemstack)) { + return true; + } + } + return false; + } } diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java index 31c6cd0b7..634073359 100644 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java @@ -44,7 +44,6 @@ import forestry.api.lepidopterology.IButterflyMutation; import forestry.api.lepidopterology.IButterflyNursery; import forestry.api.lepidopterology.IButterflyRoot; import forestry.api.lepidopterology.ILepidopteristTracker; -import forestry.core.config.Constants; import forestry.core.genetics.SpeciesRoot; import forestry.core.utils.BlockUtil; import forestry.core.utils.EntityUtil; @@ -181,7 +180,7 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { public boolean plantCocoon(World world, IButterflyNursery nursery, GameProfile owner, int age) { BlockPos pos = getNextPos(world, nursery.getCoordinates()); IBlockState state = PluginLepidopterology.blocks.cocoon.getDefaultState(); - boolean placed = world.setBlockState(pos, state, Constants.FLAG_BLOCK_SYNCH_AND_UPDATE); + boolean placed = world.setBlockState(pos, state); if (!placed) { return false; } diff --git a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java index 4f5a69172..54e72bdc8 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java +++ b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java @@ -203,7 +203,7 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored } @Override - public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, final BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return EnumActionResult.PASS; } @@ -214,12 +214,12 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored } TileEntity tileEntity = worldIn.getTileEntity(pos); + IBlockState blockState = worldIn.getBlockState(pos); if (type == EnumFlutterType.COCOON) { int age = stack.getTagCompound().getInteger(NBT_AGE); // x, y, z are the coordinates of the block "hit", can thus either be the soil or tall grass, etc. int yShift; - IBlockState blockState = worldIn.getBlockState(pos); if (!BlockUtil.isReplaceableBlock(blockState, worldIn, pos)) { if(!worldIn.isAirBlock(pos.down())){ return EnumActionResult.PASS; @@ -246,7 +246,9 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored if(nursery.canNurse(flutter)){ nursery.setCaterpillar(flutter); if(ButterflyManager.butterflyRoot.plantCocoon(worldIn, nursery, playerIn.getGameProfile(), age)){ - Proxies.common.addBlockPlaceEffects(worldIn, pos, worldIn.getBlockState(posS)); + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, worldIn.getBlockState(posS)); + Proxies.net.sendNetworkPacket(packet, worldIn); + if (!playerIn.capabilities.isCreativeMode) { stack.stackSize--; } @@ -260,19 +262,20 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored return EnumActionResult.PASS; }else if (type == EnumFlutterType.CATERPILLAR) { - TileEntity target = tileEntity; - if (!(target instanceof IButterflyNursery)) { + if (!(tileEntity instanceof IButterflyNursery)) { return EnumActionResult.PASS; } - IButterflyNursery pollinatable = (IButterflyNursery) target; + IButterflyNursery pollinatable = (IButterflyNursery) tileEntity; if (!pollinatable.canNurse(flutter)) { return EnumActionResult.PASS; } pollinatable.setCaterpillar(flutter); - Proxies.common.sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.LEAF, worldIn, pos, - worldIn.getBlockState(pos)); + + PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState); + Proxies.net.sendNetworkPacket(packet, worldIn); + if (!playerIn.capabilities.isCreativeMode) { stack.stackSize--; } diff --git a/src/main/java/forestry/lepidopterology/worldgen/CocoonDecorator.java b/src/main/java/forestry/lepidopterology/worldgen/CocoonDecorator.java index 8264c7dfb..9010b57f0 100644 --- a/src/main/java/forestry/lepidopterology/worldgen/CocoonDecorator.java +++ b/src/main/java/forestry/lepidopterology/worldgen/CocoonDecorator.java @@ -111,7 +111,7 @@ public abstract class CocoonDecorator { private static boolean setCocoon(World world, BlockPos pos, IButterfly butterfly) { Block cocoonBlock = PluginLepidopterology.blocks.solidCocoon; - boolean placed = world.setBlockState(pos, cocoonBlock.getDefaultState(), Constants.FLAG_BLOCK_SYNCH); + boolean placed = world.setBlockState(pos, cocoonBlock.getDefaultState(), Constants.FLAG_BLOCK_SYNC); if (!placed) { return false; }