diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java b/mechanical/src/main/scala/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java index 4032137f..6667eb4a 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java @@ -24,239 +24,238 @@ import java.lang.reflect.Method; public class TileMechanicalPiston extends TileMechanical implements IRotatable { - @Config(comment = "Outdated, not used anymore. use mechanicalPistonMultiplier as its based on block hardness now") - @Deprecated - private static int mechanicalPistonBreakCount = 5; + @Config(comment = "Outdated, not used anymore. use mechanicalPistonMultiplier as its based on block hardness now") + @Deprecated + private static int mechanicalPistonBreakCount = 5; - @Config - private static int mechanicalPistonMultiplier = 2; + @Config + private static int mechanicalPistonMultiplier = 2; - private boolean markRevolve = false; + private boolean markRevolve = false; - public TileMechanicalPiston() - { - super(Material.piston); + public TileMechanicalPiston() + { + super(Material.piston); - mechanicalNode = new MechanicalNode(this) - { - @Override - protected void revolve() - { - markRevolve = true; - } + mechanicalNode = new MechanicalNode(this) + { + @Override + protected void revolve() + { + markRevolve = true; + } - @Override - public boolean canConnect(ForgeDirection from, Object source) - { - return from != getDirection(); - } + @Override + public boolean canConnect(ForgeDirection from, Object source) + { + return from != getDirection(); + } - }.setLoad(0.5f); + }.setLoad(0.5f); - isOpaqueCube = false; - normalRender = false; - customItemRender = true; - rotationMask = Byte.parseByte("111111", 2); - textureName = "material_steel_dark"; - } + isOpaqueCube = false; + normalRender = false; + customItemRender = true; + rotationMask = Byte.parseByte("111111", 2); + textureName = "material_steel_dark"; + } - @Override - public void updateEntity() - { - super.updateEntity(); + @Override + public void updateEntity() + { + super.updateEntity(); - if (markRevolve) - { - Vector3 movePosition = new Vector3(TileMechanicalPiston.this).translate(getDirection()); + if (markRevolve) + { + Vector3 movePosition = new Vector3(TileMechanicalPiston.this).translate(getDirection()); - if (!hitOreBlock(movePosition)) - { - if (!worldObj.isRemote) - { - Vector3 moveNewPosition = movePosition.clone().translate(getDirection()); + if (!hitOreBlock(movePosition)) + { + if (!worldObj.isRemote) + { + Vector3 moveNewPosition = movePosition.clone().translate(getDirection()); - if (canMove(movePosition, moveNewPosition)) - move(movePosition, moveNewPosition); - } - } + if (canMove(movePosition, moveNewPosition)) + { + move(movePosition, moveNewPosition); + } + } + } - markRevolve = false; - } - } + markRevolve = false; + } + } - public boolean hitOreBlock(Vector3 blockPos) - { - Block block = Block.blocksList[blockPos.getBlockID(world())]; + public boolean hitOreBlock(Vector3 blockPos) + { + Block block = Block.blocksList[blockPos.getBlockID(world())]; - if (block != null) - { - int breakCount = (int) (mechanicalPistonMultiplier * block.blockHardness); - final int startBreakCount = breakCount; + if (block != null) + { + int breakCount = (int) (mechanicalPistonMultiplier * block.blockHardness); + final int startBreakCount = breakCount; - ItemStack blockStack = new ItemStack(block); - RecipeResource[] resources = MachineRecipes.INSTANCE.getOutput(ResonantInduction.RecipeType.CRUSHER.name(), blockStack); + ItemStack blockStack = new ItemStack(block); + RecipeResource[] resources = MachineRecipes.INSTANCE.getOutput(ResonantInduction.RecipeType.CRUSHER.name(), blockStack); - if (resources.length > 0) - { - if (!worldObj.isRemote) - { - int breakStatus = (int) (((float) (startBreakCount - breakCount) / (float) startBreakCount) * 10f); - world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), breakStatus); + if (resources.length > 0) + { + if (!worldObj.isRemote) + { + int breakStatus = (int) (((float) (startBreakCount - breakCount) / (float) startBreakCount) * 10f); + world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), breakStatus); + ResonantInduction.LOGGER.info("[Mechanical Piston] Break Count: " + breakCount); + + if (breakCount >= mechanicalPistonMultiplier) + { + for (RecipeResource recipe : resources) + { + if (Math.random() <= recipe.getChance()) + { + InventoryUtility.dropItemStack(world(), blockPos.clone().translate(0.5), recipe.getItemStack(), 10, 0); + } + } - if (breakCount <= 0) - { - if (!world().isRemote) - { - for (RecipeResource recipe : resources) - { - if (Math.random() <= recipe.getChance()) - { - InventoryUtility.dropItemStack(world(), blockPos.clone().translate(0.5), recipe.getItemStack(), 10, 0); - } - } + getWorldObj().destroyBlock(blockPos.intX(), blockPos.intY(), blockPos.intZ(), false); + } + } - getWorldObj().destroyBlock(blockPos.intX(), blockPos.intY(), blockPos.intZ(), false); - } - } - } + ResonantInduction.proxy.renderBlockParticle(worldObj, blockPos.clone().translate(0.5), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), block.blockID, 1); + breakCount--; + return true; + } + } - ResonantInduction.proxy.renderBlockParticle(worldObj, blockPos.clone().translate(0.5), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), block.blockID, 1); - breakCount--; - return true; - } - } + if (!worldObj.isRemote) + { + world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), -1); + } + + return false; + } - if (!worldObj.isRemote) - world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), -1); - return false; - } + @Override + public void onRemove(int par5, int par6) + { + super.onRemove(par5, par6); + } - @Override - public void onRemove(int par5, int par6) - { - super.onRemove(par5, par6); - } + public boolean canMove(Vector3 from, Vector3 to) + { + TileEntity tileEntity = from.getTileEntity(worldObj); - public boolean canMove(Vector3 from, Vector3 to) - { - TileEntity tileEntity = from.getTileEntity(worldObj); + if (this.equals(to.getTileEntity(getWorldObj()))) + { + return false; + } - if (this.equals(to.getTileEntity(getWorldObj()))) - { - return false; - } + /** Check Target */ + int targetBlockID = to.getBlockID(worldObj); - /** Check Target */ - int targetBlockID = to.getBlockID(worldObj); + if (!(worldObj.isAirBlock(to.intX(), to.intY(), to.intZ()) || (targetBlockID > 0 && (Block.blocksList[targetBlockID].isBlockReplaceable(worldObj, to.intX(), to.intY(), to.intZ()))))) + { + return false; + } - if (!(worldObj.isAirBlock(to.intX(), to.intY(), to.intZ()) || (targetBlockID > 0 && (Block.blocksList[targetBlockID].isBlockReplaceable(worldObj, to.intX(), to.intY(), to.intZ()))))) - { - return false; - } + return true; + } - return true; - } + public void move(Vector3 from, Vector3 to) + { + int blockID = from.getBlockID(worldObj); + int blockMetadata = from.getBlockMetadata(worldObj); - public void move(Vector3 from, Vector3 to) - { - int blockID = from.getBlockID(worldObj); - int blockMetadata = from.getBlockMetadata(worldObj); + TileEntity tileEntity = from.getTileEntity(worldObj); - TileEntity tileEntity = from.getTileEntity(worldObj); + NBTTagCompound tileData = new NBTTagCompound(); - NBTTagCompound tileData = new NBTTagCompound(); + if (tileEntity != null) + { + tileEntity.writeToNBT(tileData); + } - if (tileEntity != null) - { - tileEntity.writeToNBT(tileData); - } + MovementUtility.setBlockSneaky(worldObj, from, 0, 0, null); - MovementUtility.setBlockSneaky(worldObj, from, 0, 0, null); + if (tileEntity != null && tileData != null) + { + /** Forge Multipart Support. Use FMP's custom TE creator. */ + boolean isMultipart = tileData.getString("id").equals("savedMultipart"); - if (tileEntity != null && tileData != null) - { - /** - * Forge Multipart Support. Use FMP's custom TE creator. - */ - boolean isMultipart = tileData.getString("id").equals("savedMultipart"); + TileEntity newTile = null; - TileEntity newTile = null; + if (isMultipart) + { + try + { + Class multipart = Class.forName("codechicken.multipart.MultipartHelper"); + Method m = multipart.getMethod("createTileFromNBT", World.class, NBTTagCompound.class); + newTile = (TileEntity) m.invoke(null, worldObj, tileData); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + else + { + newTile = TileEntity.createAndLoadEntity(tileData); + } - if (isMultipart) - { - try - { - Class multipart = Class.forName("codechicken.multipart.MultipartHelper"); - Method m = multipart.getMethod("createTileFromNBT", World.class, NBTTagCompound.class); - newTile = (TileEntity) m.invoke(null, worldObj, tileData); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - else - { - newTile = TileEntity.createAndLoadEntity(tileData); - } + MovementUtility.setBlockSneaky(worldObj, to, blockID, blockMetadata, newTile); - MovementUtility.setBlockSneaky(worldObj, to, blockID, blockMetadata, newTile); + if (newTile != null && isMultipart) + { + try + { + // Send the description packet of the TE after moving it. + Class multipart = Class.forName("codechicken.multipart.MultipartHelper"); + multipart.getMethod("sendDescPacket", World.class, TileEntity.class).invoke(null, worldObj, newTile); - if (newTile != null && isMultipart) - { - try - { - // Send the description packet of the TE after moving it. - Class multipart = Class.forName("codechicken.multipart.MultipartHelper"); - multipart.getMethod("sendDescPacket", World.class, TileEntity.class).invoke(null, worldObj, newTile); + // Call onMoved event. + Class tileMultipart = Class.forName("codechicken.multipart.TileMultipart"); + tileMultipart.getMethod("onMoved").invoke(newTile); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + else + { + MovementUtility.setBlockSneaky(worldObj, to, blockID, blockMetadata, null); + } - // Call onMoved event. - Class tileMultipart = Class.forName("codechicken.multipart.TileMultipart"); - tileMultipart.getMethod("onMoved").invoke(newTile); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - else - { - MovementUtility.setBlockSneaky(worldObj, to, blockID, blockMetadata, null); - } + notifyChanges(from); + notifyChanges(to); + } - notifyChanges(from); - notifyChanges(to); - } + public void notifyChanges(Vector3 pos) + { + worldObj.notifyBlocksOfNeighborChange(pos.intX(), pos.intY(), pos.intZ(), pos.getBlockID(worldObj)); - public void notifyChanges(Vector3 pos) - { - worldObj.notifyBlocksOfNeighborChange(pos.intX(), pos.intY(), pos.intZ(), pos.getBlockID(worldObj)); + TileEntity newTile = pos.getTileEntity(worldObj); - TileEntity newTile = pos.getTileEntity(worldObj); + if (newTile != null) + { + if (Loader.isModLoaded("BuildCraft|Factory")) + { + /** Special quarry compatibility code. */ + try + { + Class clazz = Class.forName("buildcraft.factory.TileQuarry"); - if (newTile != null) - { - if (Loader.isModLoaded("BuildCraft|Factory")) - { - /** - * Special quarry compatibility code. - */ - try - { - Class clazz = Class.forName("buildcraft.factory.TileQuarry"); - - if (newTile.equals(clazz)) - { - ReflectionHelper.setPrivateValue(clazz, newTile, true, "isAlive"); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - } + if (newTile.equals(clazz)) + { + ReflectionHelper.setPrivateValue(clazz, newTile, true, "isAlive"); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + } }