mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Improve crane I/O screwdriver logic
Instead of cycling through all directions, the side the player clicks on will be manipulated directly, and, if applicable, input will be swapped with output and vice versa. Right-clicking normally changes the conveyor side, shift-right-clicking the machine side. Clicking on a side twice will manipulate the opposite side.
This commit is contained in:
parent
9f99034e96
commit
64db18a2b4
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user