Search in sources :

Example 1 with AbstractPair

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

use of mods.railcraft.api.signals.AbstractPair 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);
}
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) ItemStack(net.minecraft.item.ItemStack) ISignalTileBlock(mods.railcraft.api.signals.ISignalTileBlock) AbstractPair(mods.railcraft.api.signals.AbstractPair) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 AbstractPair (mods.railcraft.api.signals.AbstractPair)2 IControllerTile (mods.railcraft.api.signals.IControllerTile)2 IReceiverTile (mods.railcraft.api.signals.IReceiverTile)2 IBlockState (net.minecraft.block.state.IBlockState)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ISignalBlockTile (mods.railcraft.api.signals.ISignalBlockTile)1 ISignalTileBlock (mods.railcraft.api.signals.ISignalTileBlock)1 ItemStack (net.minecraft.item.ItemStack)1