Search in sources :

Example 11 with SignalAspect

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

the class TileBoxAnalog method readGuiData.

@Override
public void readGuiData(RailcraftInputStream data, @Nullable EntityPlayer sender) throws IOException {
    for (Map.Entry<SignalAspect, BitSet> entry : aspects.entrySet()) {
        BitSet bitSet = entry.getValue();
        bitSet.clear();
        bitSet.or(data.readBitSet());
    }
}
Also used : SignalAspect(mods.railcraft.api.signals.SignalAspect) BitSet(java.util.BitSet) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 12 with SignalAspect

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

the class TileBoxCapacitor method update.

@Override
public void update() {
    super.update();
    if (Game.isClient(worldObj))
        return;
    if (ticksPowered > 0) {
        ticksPowered--;
        if (Objects.equals(stateModeController.getButtonState(), EnumStateMode.FALLING_EDGE)) {
            //new behavior
            SignalAspect tmpaspect = SignalAspect.GREEN;
            Boolean hasInput = false;
            if (PowerPlugin.isBlockBeingPoweredByRepeater(worldObj, getPos()))
                hasInput = true;
            for (int side = 2; side < 6; side++) {
                //get most restrictive aspect from adjacent (active) boxes
                EnumFacing forgeSide = EnumFacing.VALUES[side];
                TileEntity tile = tileCache.getTileOnSide(forgeSide);
                if (tile instanceof TileBoxBase) {
                    TileBoxBase box = (TileBoxBase) tile;
                    if (box.isEmittingRedstone(forgeSide.getOpposite())) {
                        hasInput = true;
                        tmpaspect = SignalAspect.mostRestrictive(tmpaspect, box.getBoxSignalAspect(forgeSide.getOpposite()));
                    }
                }
            }
            if (hasInput) {
                //undo any previous decrements
                ticksPowered = ticksToPower;
                if (!Objects.equals(aspect, tmpaspect)) {
                    //change to the most restrictive aspect found above.
                    aspect = tmpaspect;
                    updateNeighbors();
                }
            }
        }
        //in all cases:
        if (ticksPowered <= 0)
            updateNeighbors();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SignalAspect(mods.railcraft.api.signals.SignalAspect) EnumFacing(net.minecraft.util.EnumFacing)

Example 13 with SignalAspect

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

the class GuiBoxAnalogController method initGui.

@Override
public void initGui() {
    if (tile == null)
        return;
    int w = (width - xSize) / 2;
    int h = (height - ySize) / 2;
    for (Map.Entry<SignalAspect, BitSet> entry : aspects.entrySet()) {
        GuiTextField textField = new GuiTextField(entry.getKey().ordinal(), fontRendererObj, w + 72, h + getYPosFromIndex(entry.getKey().ordinal()), 95, 10);
        textField.setMaxStringLength(37);
        textField.setText(rangeToString(entry.getValue()));
        textBox.put(entry.getKey(), textField);
    }
}
Also used : SignalAspect(mods.railcraft.api.signals.SignalAspect) BitSet(java.util.BitSet) GuiTextField(net.minecraft.client.gui.GuiTextField) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 14 with SignalAspect

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

the class ItemMagnifyingGlass method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(ItemStack stack, 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 = world.getTileEntity(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");
        else
            for (MultiBlockStateReturn returnState : EnumSet.complementOf(EnumSet.of(MultiBlockStateReturn.VALID))) {
                List<Integer> pats = tile.patternStates.get(returnState);
                if (!pats.isEmpty())
                    ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, pats.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;
    }
    return returnValue;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SignalAspect(mods.railcraft.api.signals.SignalAspect) EnumActionResult(net.minecraft.util.EnumActionResult) TileMultiBlock(mods.railcraft.common.blocks.machine.TileMultiBlock) MultiBlockStateReturn(mods.railcraft.common.blocks.machine.TileMultiBlock.MultiBlockStateReturn) IDualHeadSignal(mods.railcraft.common.blocks.wayobjects.IDualHeadSignal) TileSignalBase(mods.railcraft.common.blocks.wayobjects.TileSignalBase) IOwnable(mods.railcraft.api.core.IOwnable) List(java.util.List)

Aggregations

SignalAspect (mods.railcraft.api.signals.SignalAspect)14 EnumFacing (net.minecraft.util.EnumFacing)5 BitSet (java.util.BitSet)4 EnumMap (java.util.EnumMap)4 Map (java.util.Map)4 TileEntity (net.minecraft.tileentity.TileEntity)3 IDualHeadSignal (mods.railcraft.common.blocks.wayobjects.IDualHeadSignal)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 IOException (java.io.IOException)1 List (java.util.List)1 IOwnable (mods.railcraft.api.core.IOwnable)1 TileMultiBlock (mods.railcraft.common.blocks.machine.TileMultiBlock)1 MultiBlockStateReturn (mods.railcraft.common.blocks.machine.TileMultiBlock.MultiBlockStateReturn)1 TileSignalBase (mods.railcraft.common.blocks.wayobjects.TileSignalBase)1 PacketGuiReturn (mods.railcraft.common.util.network.PacketGuiReturn)1 GuiTextField (net.minecraft.client.gui.GuiTextField)1 EnumActionResult (net.minecraft.util.EnumActionResult)1