Search in sources :

Example 1 with TileSignalBase

use of mods.railcraft.common.blocks.machine.wayobjects.signals.TileSignalBase in project Railcraft by Railcraft.

the class ItemMagnifyingGlass method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (Game.isClient(world))
        return EnumActionResult.PASS;
    TileEntity t = WorldPlugin.getBlockTile(world, pos);
    EnumActionResult returnValue = EnumActionResult.PASS;
    if (t instanceof IOwnable) {
        IOwnable ownable = (IOwnable) t;
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.placedby", ownable.getDisplayName(), ownable.getOwner());
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof TileMultiBlock) {
        TileMultiBlock tile = (TileMultiBlock) t;
        if (tile.isStructureValid()) {
            ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
            ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.master." + (tile.isValidMaster() ? "true" : "false"));
        } else
            for (State returnState : EnumSet.complementOf(EnumSet.of(State.VALID))) {
                List<StructurePattern> pats = tile.patternStates.get(returnState);
                if (!pats.isEmpty()) {
                    List<Integer> indexList = pats.stream().map(map -> tile.getPatterns().indexOf(map)).collect(Collectors.toList());
                    ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, indexList.toString());
                }
            }
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof TileLogic) {
        TileLogic tile = (TileLogic) t;
        Optional<StructureLogic> optLogic = tile.getLogic(StructureLogic.class);
        if (optLogic.isPresent()) {
            StructureLogic logic = optLogic.get();
            if (logic.isStructureValid()) {
                ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
                ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.master." + (logic.isValidMaster() ? "true" : "false"));
            } else
                for (State returnState : EnumSet.complementOf(EnumSet.of(State.VALID))) {
                    List<StructurePattern> pats = logic.patternStates.get(returnState);
                    if (!pats.isEmpty()) {
                        List<Integer> indexList = pats.stream().map(map -> logic.getPatterns().indexOf(map)).collect(Collectors.toList());
                        ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, indexList.toString());
                    }
                }
            returnValue = EnumActionResult.SUCCESS;
        }
    }
    if (t instanceof IDualHeadSignal) {
        IDualHeadSignal signal = (IDualHeadSignal) t;
        SignalAspect top = signal.getSignalAspect(DualLamp.TOP);
        SignalAspect bottom = signal.getSignalAspect(DualLamp.BOTTOM);
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect.dual", top.getLocalizationTag(), bottom.getLocalizationTag());
        returnValue = EnumActionResult.SUCCESS;
    } else if (t instanceof TileSignalBase) {
        ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect", ((TileSignalBase) t).getSignalAspect().getLocalizationTag());
        returnValue = EnumActionResult.SUCCESS;
    }
    if (t instanceof IMagnifiable) {
        ((IMagnifiable) t).onMagnify(player);
    }
    return returnValue;
}
Also used : SignalAspect(mods.railcraft.api.signals.SignalAspect) TileMultiBlock(mods.railcraft.common.blocks.structures.TileMultiBlock) IDualHeadSignal(mods.railcraft.common.blocks.machine.wayobjects.signals.IDualHeadSignal) TileSignalBase(mods.railcraft.common.blocks.machine.wayobjects.signals.TileSignalBase) TileEntity(net.minecraft.tileentity.TileEntity) EnumActionResult(net.minecraft.util.EnumActionResult) StructureLogic(mods.railcraft.common.blocks.logic.StructureLogic) State(mods.railcraft.common.blocks.structures.StructurePattern.State) IOwnable(mods.railcraft.api.core.IOwnable) List(java.util.List) TileLogic(mods.railcraft.common.blocks.TileLogic)

Aggregations

List (java.util.List)1 IOwnable (mods.railcraft.api.core.IOwnable)1 SignalAspect (mods.railcraft.api.signals.SignalAspect)1 TileLogic (mods.railcraft.common.blocks.TileLogic)1 StructureLogic (mods.railcraft.common.blocks.logic.StructureLogic)1 IDualHeadSignal (mods.railcraft.common.blocks.machine.wayobjects.signals.IDualHeadSignal)1 TileSignalBase (mods.railcraft.common.blocks.machine.wayobjects.signals.TileSignalBase)1 State (mods.railcraft.common.blocks.structures.StructurePattern.State)1 TileMultiBlock (mods.railcraft.common.blocks.structures.TileMultiBlock)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumActionResult (net.minecraft.util.EnumActionResult)1