Search in sources :

Example 21 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Railcraft by Railcraft.

the class ItemSignalTuner method onItemUse.

//TODO: Add chat name highlighting formatting styles
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (actionCleanPairing(stack, playerIn, worldIn, IControllerTile.class, IControllerTile::getController)) {
        return EnumActionResult.SUCCESS;
    }
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile != null) {
        WorldCoordinate previousTarget = getPairData(stack);
        if (tile instanceof IReceiverTile && previousTarget != null) {
            if (Game.isHost(worldIn)) {
                SignalReceiver receiver = ((IReceiverTile) tile).getReceiver();
                if (!Objects.equals(pos, previousTarget.getPos())) {
                    tile = worldIn.getTileEntity(previousTarget.getPos());
                    if (tile instanceof IControllerTile) {
                        SignalController controller = ((IControllerTile) tile).getController();
                        if (receiver.getTile() != controller.getTile()) {
                            controller.registerReceiver(receiver);
                            controller.endPairing();
                            ChatPlugin.sendLocalizedChatFromServer(playerIn, LOC_PREFIX + "success", controller.getLocalizationTag(), receiver.getLocalizationTag());
                            clearPairData(stack);
                            return EnumActionResult.SUCCESS;
                        }
                    } else if (WorldPlugin.isBlockLoaded(worldIn, previousTarget.getPos())) {
                        ChatPlugin.sendLocalizedChatFromServer(playerIn, LOC_PREFIX + "abandon.gone");
                        clearPairData(stack);
                    } else {
                        ChatPlugin.sendLocalizedChatFromServer(playerIn, LOC_PREFIX + "abandon.chunk");
                        clearPairData(stack);
                    }
                }
            }
        } else if (tile instanceof IControllerTile) {
            if (Game.isHost(worldIn)) {
                SignalController controller = ((IControllerTile) tile).getController();
                if (previousTarget == null || !Objects.equals(pos, previousTarget.getPos())) {
                    ChatPlugin.sendLocalizedChatFromServer(playerIn, LOC_PREFIX + "start", controller.getLocalizationTag());
                    setPairData(stack, tile);
                    controller.startPairing();
                } else {
                    ChatPlugin.sendLocalizedChatFromServer(playerIn, LOC_PREFIX + "stop", controller.getLocalizationTag());
                    controller.endPairing();
                    clearPairData(stack);
                }
            }
        } else
            return EnumActionResult.PASS;
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IReceiverTile(mods.railcraft.api.signals.IReceiverTile) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) IControllerTile(mods.railcraft.api.signals.IControllerTile) SignalController(mods.railcraft.api.signals.SignalController) SignalReceiver(mods.railcraft.api.signals.SignalReceiver)

Example 22 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate 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(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    //        System.out.println("click");
    if (actionCleanPairing(stack, playerIn, worldIn, ISignalBlockTile.class, ISignalBlockTile::getSignalBlock)) {
        return EnumActionResult.SUCCESS;
    }
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile != null)
        if (tile instanceof ISignalBlockTile) {
            //            System.out.println("target found");
            if (Game.isHost(worldIn)) {
                ISignalBlockTile signalTile = (ISignalBlockTile) tile;
                SignalBlock signalBlock = signalTile.getSignalBlock();
                WorldCoordinate signalPos = getPairData(stack);
                SignalBlock.Status trackStatus = signalBlock.getTrackStatus();
                if (trackStatus == SignalBlock.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 ISignalBlockTile) {
                        ISignalBlockTile otherTile = (ISignalBlockTile) tile;
                        SignalBlock otherSignal = otherTile.getSignalBlock();
                        if (signalBlock.createSignalBlock(otherSignal)) {
                            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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) ISignalBlockTile(mods.railcraft.api.signals.ISignalBlockTile) SignalBlock(mods.railcraft.api.signals.SignalBlock)

Example 23 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Railcraft by Railcraft.

the class ItemPairingTool method setPairData.

public void setPairData(ItemStack stack, TileEntity tile) {
    NBTTagCompound pairData = new NBTTagCompound();
    WorldCoordinate pos = new WorldCoordinate(tile);
    pos.writeToNBT(pairData, COORD_TAG);
    InvTools.setItemDataRailcraft(stack, PAIR_DATA_TAG, pairData);
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)23 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 NBTTagList (net.minecraft.nbt.NBTTagList)6 TrackScanner (mods.railcraft.api.tracks.TrackScanner)4 TileEntity (net.minecraft.tileentity.TileEntity)4 Map (java.util.Map)3 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 IToolCrowbar (mods.railcraft.api.core.items.IToolCrowbar)2 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 ConnectType (mods.railcraft.api.charge.IElectricGrid.ChargeHandler.ConnectType)1 ConnectType (mods.railcraft.api.electricity.IElectricGrid.ChargeHandler.ConnectType)1 IControllerTile (mods.railcraft.api.signals.IControllerTile)1 IReceiverTile (mods.railcraft.api.signals.IReceiverTile)1 ISignalBlockTile (mods.railcraft.api.signals.ISignalBlockTile)1 SignalBlock (mods.railcraft.api.signals.SignalBlock)1 SignalController (mods.railcraft.api.signals.SignalController)1 SignalReceiver (mods.railcraft.api.signals.SignalReceiver)1 Block (net.minecraft.block.Block)1