diff --git a/src/main/java/com/hbm/blocks/network/BlockCraneBase.java b/src/main/java/com/hbm/blocks/network/BlockCraneBase.java index 3cdd1f8e5..577ceb614 100644 --- a/src/main/java/com/hbm/blocks/network/BlockCraneBase.java +++ b/src/main/java/com/hbm/blocks/network/BlockCraneBase.java @@ -6,7 +6,6 @@ import com.hbm.items.tool.ItemTooling; import com.hbm.lib.RefStrings; import com.hbm.main.MainRegistry; import com.hbm.tileentity.network.TileEntityCraneBase; -import com.hbm.util.ChatBuilder; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.relauncher.Side; @@ -23,7 +22,6 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -92,10 +90,6 @@ public abstract class BlockCraneBase extends BlockContainer implements IBlockSid world.setBlockMetadataWithNotify(x, y, z, l, 2); } - protected boolean hasReversedIO() { - return false; - } - @Override public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) { if (tool != ToolType.SCREWDRIVER) return false; @@ -105,28 +99,12 @@ public abstract class BlockCraneBase extends BlockContainer implements IBlockSid TileEntityCraneBase craneTileEntity = (TileEntityCraneBase) te; - // some cranes like the ejector have reversed input and output sides - // so this bit of logic is to hide that away from the player - boolean actuallyCycleInput = player.isSneaking() != hasReversedIO(); - ForgeDirection newDirection; + ForgeDirection newDirection = ForgeDirection.getOrientation(side); - if (actuallyCycleInput) { // cycle input - // it's in reverse because players are more likely to want to turn the output from DOWN to UP - int newValue = Math.floorMod(world.getBlockMetadata(x, y, z) - 1, 6); - newDirection = ForgeDirection.getOrientation(newValue); - - world.setBlockMetadataWithNotify(x, y, z, newValue, 3); - craneTileEntity.ensureOutputOverrideValid(); - } else { // cycle output - newDirection = craneTileEntity.cycleOutputOverride(); - } - - if (!world.isRemote) { - ChatBuilder message = player.isSneaking() - ? ChatBuilder.start("Input: ").color(EnumChatFormatting.GREEN) - : ChatBuilder.start("Output: ").color(EnumChatFormatting.RED); - message.next(newDirection.name()).color(EnumChatFormatting.WHITE); - player.addChatComponentMessage(message.flush()); + if (player.isSneaking()) { + craneTileEntity.setOutputOverride(newDirection); + } else { + craneTileEntity.setInput(newDirection); } return true; diff --git a/src/main/java/com/hbm/blocks/network/CraneExtractor.java b/src/main/java/com/hbm/blocks/network/CraneExtractor.java index 7b142bb70..a50ff756a 100644 --- a/src/main/java/com/hbm/blocks/network/CraneExtractor.java +++ b/src/main/java/com/hbm/blocks/network/CraneExtractor.java @@ -42,11 +42,6 @@ public class CraneExtractor extends BlockCraneBase { this.iconDirectionalSideDownTurnRight = iconRegister.registerIcon(RefStrings.MODID + ":crane_out_side_right_turn_down"); } - @Override - protected boolean hasReversedIO() { - return true; - } - @Override public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) { int meta = world.getBlockMetadata(x, y, z); diff --git a/src/main/java/com/hbm/blocks/network/CraneUnboxer.java b/src/main/java/com/hbm/blocks/network/CraneUnboxer.java index 109be9ac7..b9ffd19a2 100644 --- a/src/main/java/com/hbm/blocks/network/CraneUnboxer.java +++ b/src/main/java/com/hbm/blocks/network/CraneUnboxer.java @@ -50,11 +50,6 @@ public class CraneUnboxer extends BlockCraneBase implements IEnterableBlock { this.iconDirectionalSideDownTurnRight = iconRegister.registerIcon(RefStrings.MODID + ":crane_unboxer_side_right_turn_down"); } - @Override - protected boolean hasReversedIO() { - return true; - } - @Override public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) { int meta = world.getBlockMetadata(x, y, z); diff --git a/src/main/java/com/hbm/tileentity/network/TileEntityCraneBase.java b/src/main/java/com/hbm/tileentity/network/TileEntityCraneBase.java index 28daa73f7..8449c27a1 100644 --- a/src/main/java/com/hbm/tileentity/network/TileEntityCraneBase.java +++ b/src/main/java/com/hbm/tileentity/network/TileEntityCraneBase.java @@ -46,18 +46,31 @@ public abstract class TileEntityCraneBase extends TileEntityMachineBase { return outputOverride; } - public ForgeDirection cycleOutputOverride() { - do { - outputOverride = ForgeDirection.getOrientation(Math.floorMod(outputOverride.ordinal() - 1, 7)); - } while (outputOverride.ordinal() == getBlockMetadata()); + public void setOutputOverride(ForgeDirection direction) { + ForgeDirection oldSide = getOutputSide(); + if (oldSide == direction) + direction = direction.getOpposite(); - onBlockChanged(); - return outputOverride; + outputOverride = direction; + + if (direction == getInputSide()) + setInput(oldSide); + else + onBlockChanged(); } - public void ensureOutputOverrideValid() { - if (outputOverride.ordinal() == getBlockMetadata()) - cycleOutputOverride(); + public void setInput(ForgeDirection direction) { + outputOverride = getOutputSide(); // save the current output, if it isn't saved yet + + ForgeDirection oldSide = getInputSide(); + if (oldSide == direction) + direction = direction.getOpposite(); + + boolean needSwapOutput = direction == getOutputSide(); + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), needSwapOutput ? 4 : 3); + + if (needSwapOutput) + setOutputOverride(oldSide); } protected void onBlockChanged() {