Fixed bug with Mechanical Piston not breaking blocks.

This commit is contained in:
Maxwolf Goodliffe 2014-06-18 21:50:13 -07:00
parent 00b79b1d69
commit a4e300ad9a

View file

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