Search in sources :

Example 1 with ISignalBlockTile

use of mods.railcraft.api.signals.ISignalBlockTile in project Railcraft by Railcraft.

the class ItemSignalLabel method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (Game.isHost(worldIn) && playerIn.isSneaking() && stack.hasDisplayName()) {
        TileEntity tile = worldIn.getTileEntity(pos);
        Set<AbstractPair> pairs = new HashSet<AbstractPair>();
        if (tile instanceof IReceiverTile) {
            pairs.add(((IReceiverTile) tile).getReceiver());
        }
        if (tile instanceof IControllerTile) {
            pairs.add(((IControllerTile) tile).getController());
        }
        if (tile instanceof ISignalBlockTile) {
            pairs.add(((ISignalBlockTile) 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) {
                --stack.stackSize;
                PlayerPlugin.swingArm(playerIn, hand);
                IBlockState state = WorldPlugin.getBlockState(worldIn, pos);
                worldIn.notifyBlockUpdate(pos, state, state, 3);
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IReceiverTile(mods.railcraft.api.signals.IReceiverTile) IBlockState(net.minecraft.block.state.IBlockState) IControllerTile(mods.railcraft.api.signals.IControllerTile) ISignalBlockTile(mods.railcraft.api.signals.ISignalBlockTile) AbstractPair(mods.railcraft.api.signals.AbstractPair) HashSet(java.util.HashSet)

Example 2 with ISignalBlockTile

use of mods.railcraft.api.signals.ISignalBlockTile in project Railcraft by Railcraft.

the class PacketPairRequest method readData.

@Override
public void readData(RailcraftInputStream data) throws IOException {
    World world = DimensionManager.getWorld(data.readInt());
    if (world == null)
        return;
    int x = data.readInt();
    int y = data.readInt();
    int z = data.readInt();
    TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
    switch(packetType) {
        case CONTROLLER_REQUEST:
            if (tile instanceof IControllerTile)
                pairing = ((IControllerTile) tile).getController();
            break;
        case RECEIVER_REQUEST:
            if (tile instanceof IReceiverTile)
                pairing = ((IReceiverTile) tile).getReceiver();
            break;
        case SIGNAL_REQUEST:
            if (tile instanceof ISignalBlockTile)
                pairing = ((ISignalBlockTile) tile).getSignalBlock();
            break;
    }
    if (pairing != null && player != null) {
        PacketPairUpdate pkt = new PacketPairUpdate(pairing);
        PacketDispatcher.sendToPlayer(pkt, player);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ISignalBlockTile(mods.railcraft.api.signals.ISignalBlockTile)

Example 3 with ISignalBlockTile

use of mods.railcraft.api.signals.ISignalBlockTile 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)

Aggregations

ISignalBlockTile (mods.railcraft.api.signals.ISignalBlockTile)3 TileEntity (net.minecraft.tileentity.TileEntity)3 HashSet (java.util.HashSet)1 WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)1 AbstractPair (mods.railcraft.api.signals.AbstractPair)1 IControllerTile (mods.railcraft.api.signals.IControllerTile)1 IReceiverTile (mods.railcraft.api.signals.IReceiverTile)1 SignalBlock (mods.railcraft.api.signals.SignalBlock)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1