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.lib.RefStrings;
|
||||||
import com.hbm.main.MainRegistry;
|
import com.hbm.main.MainRegistry;
|
||||||
import com.hbm.tileentity.network.TileEntityCraneBase;
|
import com.hbm.tileentity.network.TileEntityCraneBase;
|
||||||
import com.hbm.util.ChatBuilder;
|
|
||||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
@ -23,7 +22,6 @@ import net.minecraft.inventory.ISidedInventory;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@ -92,10 +90,6 @@ public abstract class BlockCraneBase extends BlockContainer implements IBlockSid
|
|||||||
world.setBlockMetadataWithNotify(x, y, z, l, 2);
|
world.setBlockMetadataWithNotify(x, y, z, l, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasReversedIO() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) {
|
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;
|
if (tool != ToolType.SCREWDRIVER) return false;
|
||||||
@ -105,28 +99,12 @@ public abstract class BlockCraneBase extends BlockContainer implements IBlockSid
|
|||||||
|
|
||||||
TileEntityCraneBase craneTileEntity = (TileEntityCraneBase) te;
|
TileEntityCraneBase craneTileEntity = (TileEntityCraneBase) te;
|
||||||
|
|
||||||
// some cranes like the ejector have reversed input and output sides
|
ForgeDirection newDirection = ForgeDirection.getOrientation(side);
|
||||||
// so this bit of logic is to hide that away from the player
|
|
||||||
boolean actuallyCycleInput = player.isSneaking() != hasReversedIO();
|
|
||||||
ForgeDirection newDirection;
|
|
||||||
|
|
||||||
if (actuallyCycleInput) { // cycle input
|
if (player.isSneaking()) {
|
||||||
// it's in reverse because players are more likely to want to turn the output from DOWN to UP
|
craneTileEntity.setOutputOverride(newDirection);
|
||||||
int newValue = Math.floorMod(world.getBlockMetadata(x, y, z) - 1, 6);
|
} else {
|
||||||
newDirection = ForgeDirection.getOrientation(newValue);
|
craneTileEntity.setInput(newDirection);
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -42,11 +42,6 @@ public class CraneExtractor extends BlockCraneBase {
|
|||||||
this.iconDirectionalSideDownTurnRight = iconRegister.registerIcon(RefStrings.MODID + ":crane_out_side_right_turn_down");
|
this.iconDirectionalSideDownTurnRight = iconRegister.registerIcon(RefStrings.MODID + ":crane_out_side_right_turn_down");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean hasReversedIO() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) {
|
public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) {
|
||||||
int meta = world.getBlockMetadata(x, y, z);
|
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");
|
this.iconDirectionalSideDownTurnRight = iconRegister.registerIcon(RefStrings.MODID + ":crane_unboxer_side_right_turn_down");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean hasReversedIO() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) {
|
public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) {
|
||||||
int meta = world.getBlockMetadata(x, y, z);
|
int meta = world.getBlockMetadata(x, y, z);
|
||||||
|
|||||||
@ -46,18 +46,31 @@ public abstract class TileEntityCraneBase extends TileEntityMachineBase {
|
|||||||
return outputOverride;
|
return outputOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForgeDirection cycleOutputOverride() {
|
public void setOutputOverride(ForgeDirection direction) {
|
||||||
do {
|
ForgeDirection oldSide = getOutputSide();
|
||||||
outputOverride = ForgeDirection.getOrientation(Math.floorMod(outputOverride.ordinal() - 1, 7));
|
if (oldSide == direction)
|
||||||
} while (outputOverride.ordinal() == getBlockMetadata());
|
direction = direction.getOpposite();
|
||||||
|
|
||||||
onBlockChanged();
|
outputOverride = direction;
|
||||||
return outputOverride;
|
|
||||||
|
if (direction == getInputSide())
|
||||||
|
setInput(oldSide);
|
||||||
|
else
|
||||||
|
onBlockChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ensureOutputOverrideValid() {
|
public void setInput(ForgeDirection direction) {
|
||||||
if (outputOverride.ordinal() == getBlockMetadata())
|
outputOverride = getOutputSide(); // save the current output, if it isn't saved yet
|
||||||
cycleOutputOverride();
|
|
||||||
|
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() {
|
protected void onBlockChanged() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user