use of mods.railcraft.api.signals.ISignalTileBlock in project Railcraft by Railcraft.
the class ItemSignalLabel method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(hand);
if (Game.isHost(worldIn) && playerIn.isSneaking() && stack.hasDisplayName()) {
TileEntity tile = worldIn.getTileEntity(pos);
Set<AbstractPair> pairs = new HashSet<>();
if (tile instanceof IReceiverTile) {
pairs.add(((IReceiverTile) tile).getReceiver());
}
if (tile instanceof IControllerTile) {
pairs.add(((IControllerTile) tile).getController());
}
if (tile instanceof ISignalTileBlock) {
pairs.add(((ISignalTileBlock) tile).getSignalBlock());
}
if (!pairs.isEmpty()) {
String newName = stack.getDisplayName();
boolean done = false;
for (AbstractPair pair : pairs) {
if (!newName.equals(pair.getName())) {
pair.setName(newName);
done = true;
}
}
if (done) {
dec(stack);
PlayerPlugin.swingArm(playerIn, hand);
IBlockState state = WorldPlugin.getBlockState(worldIn, pos);
worldIn.notifyBlockUpdate(pos, state, state, 3);
return EnumActionResult.SUCCESS;
}
}
}
return super.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
use of mods.railcraft.api.signals.ISignalTileBlock in project Railcraft by Railcraft.
the class ItemSignalBlockSurveyor method onItemUse.
// TODO: Add chat name highlighting formatting styles
// TODO: This function could probably be picked apart and pulled into the super class, but meh...
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
// System.out.println("click");
ItemStack stack = playerIn.getHeldItem(hand);
if (actionCleanPairing(stack, playerIn, worldIn, ISignalTileBlock.class, ISignalTileBlock::getSignalBlock)) {
return EnumActionResult.SUCCESS;
}
TileEntity tile = worldIn.getTileEntity(pos);
if (tile != null)
if (tile instanceof ISignalTile) {
// System.out.println("target found");
if (Game.isHost(worldIn)) {
ISignalTile signalTile = (ISignalTile) tile;
IPair signalBlock = signalTile.getPair();
WorldCoordinate signalPos = getPairData(stack);
TrackLocator.Status trackStatus = signalTile.getTrackLocator().getTrackStatus();
if (trackStatus == TrackLocator.Status.INVALID)
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.track", signalTile.getDisplayName());
else if (signalPos == null) {
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.begin");
setPairData(stack, tile);
signalBlock.startPairing();
} else if (!Objects.equals(pos, signalPos.getPos())) {
// System.out.println("attempt pairing");
tile = WorldPlugin.getBlockTile(worldIn, signalPos.getPos());
if (tile instanceof ISignalTile) {
if (signalBlock.createPair(tile)) {
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.success");
clearPairData(stack);
} else
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.invalid");
} else if (WorldPlugin.isBlockLoaded(worldIn, signalPos.getPos())) {
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.lost");
signalBlock.endPairing();
clearPairData(stack);
} else
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.unloaded");
} else {
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.abandon");
signalBlock.endPairing();
clearPairData(stack);
}
}
return EnumActionResult.SUCCESS;
} else if (Game.isHost(worldIn))
ChatPlugin.sendLocalizedChatFromServer(playerIn, "gui.railcraft.surveyor.wrong");
return EnumActionResult.PASS;
}
Aggregations