Search in sources :

Example 1 with GatePluggable

use of buildcraft.transport.gates.GatePluggable in project LogisticsPipes by RS485.

the class LPBCTileGenericPipe method updateEntity_LP.

@Override
@SneakyThrows({ NoSuchFieldException.class, SecurityException.class, IllegalArgumentException.class, IllegalAccessException.class, NoSuchMethodException.class, InvocationTargetException.class })
public void updateEntity_LP() {
    //Make sure we still have the same TE values
    xCoord = lpPipe.xCoord;
    yCoord = lpPipe.yCoord;
    zCoord = lpPipe.zCoord;
    if (attachPluggables) {
        attachPluggables = false;
        // Attach callback
        PipePluggable[] pluggables = ReflectionHelper.getPrivateField(PipePluggable[].class, SideProperties.class, "pluggables", sideProperties);
        for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
            if (pluggables[i] != null) {
                pipe.eventBus.registerHandler(pluggables[i]);
                pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i));
            }
        }
        notifyBlockChanged();
    }
    if (!BlockGenericPipe.isValid(pipe)) {
        return;
    }
    pipe.updateEntity();
    boolean recheckThisPipe = false;
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        PipePluggable p = getPipePluggable(direction);
        if (p != null) {
            p.update(this, direction);
            //Check Gate for ActionChanges
            if (p instanceof GatePluggable && lpPipe.isRoutingPipe()) {
                if (!activeActions.containsKey(direction)) {
                    activeActions.put(direction, new ArrayList<>());
                }
                if (!listEquals(activeActions.get(direction), pipe.gates[direction.ordinal()].activeActions)) {
                    activeActions.get(direction).clear();
                    activeActions.get(direction).addAll(pipe.gates[direction.ordinal()].activeActions);
                    lpPipe.getRoutingPipe().triggerConnectionCheck();
                    recheckThisPipe = true;
                }
            } else if (activeActions.containsKey(direction)) {
                activeActions.remove(direction);
            }
            if (p instanceof RobotStationPluggable) {
                if (((RobotStationPluggable) p).getStation() != null && ((RobotStationPluggable) p).getStation().robotTaking() != null && ((RobotStationPluggable) p).getStation().robotTaking().getBoard() instanceof LogisticsRoutingBoardRobot) {
                    ((RobotStationPluggable) p).getStation().robotTaking().getBoard().cycle();
                }
            }
        }
    }
    if (recheckThisPipe) {
        LPRobotConnectionControl.instance.checkAll(worldObj);
    }
    if (worldObj.isRemote) {
        if (resyncGateExpansions) {
            ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "syncGateExpansions", new Class[] {}, new Object[] {});
        }
        return;
    }
    if (blockNeighborChange) {
        //ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "computeConnections", new Class[]{}, new Object[]{});
        pipe.onNeighborBlockChange(0);
        blockNeighborChange = false;
        refreshRenderState = true;
    }
    if (refreshRenderState) {
        refreshRenderState();
        refreshRenderState = false;
    }
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) GatePluggable(buildcraft.transport.gates.GatePluggable) SneakyThrows(lombok.SneakyThrows)

Example 2 with GatePluggable

use of buildcraft.transport.gates.GatePluggable in project BuildCraft by BuildCraft.

the class TileGenericPipe method syncGateExpansions.

private void syncGateExpansions() {
    resyncGateExpansions = false;
    for (int i = 0; i < EnumFacing.VALUES.length; i++) {
        Gate gate = pipe.gates[i];
        if (gate == null) {
            continue;
        }
        GatePluggable gatePluggable = (GatePluggable) sideProperties.pluggables[i];
        if (gatePluggable.getExpansions().length > 0) {
            for (IGateExpansion expansion : gatePluggable.getExpansions()) {
                if (expansion != null) {
                    if (!gate.expansions.containsKey(expansion)) {
                        gate.addGateExpansion(expansion);
                    }
                } else {
                    resyncGateExpansions = true;
                }
            }
        }
    }
}
Also used : IGateExpansion(buildcraft.api.gates.IGateExpansion) GatePluggable(buildcraft.transport.gates.GatePluggable)

Example 3 with GatePluggable

use of buildcraft.transport.gates.GatePluggable in project BuildCraft by BuildCraft.

the class TileGenericPipe method setGate.

// Legacy
public void setGate(Gate gate, int direction) {
    if (sideProperties.pluggables[direction] == null) {
        gate.setDirection(EnumFacing.getFront(direction));
        pipe.gates[direction] = gate;
        sideProperties.pluggables[direction] = new GatePluggable(gate);
    }
}
Also used : GatePluggable(buildcraft.transport.gates.GatePluggable)

Example 4 with GatePluggable

use of buildcraft.transport.gates.GatePluggable in project BuildCraft by BuildCraft.

the class BlockGenericPipe method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float xOffset, float yOffset, float zOffset) {
    if (super.onBlockActivated(world, pos, state, player, side, xOffset, yOffset, zOffset)) {
        return true;
    }
    world.notifyBlockOfStateChange(pos, BuildCraftTransport.genericPipeBlock);
    Pipe<?> pipe = getPipe(world, pos);
    RaytraceResult rayTrace = doRayTrace(world, pos, player);
    if (rayTrace != null) {
        side = rayTrace.sideHit;
    }
    if (isValid(pipe)) {
        ItemStack currentItem = player.getCurrentEquippedItem();
        // from the pipe.
        if (player.isSneaking() && currentItem == null) {
            if (stripEquipment(world, pos, player, pipe, side)) {
                return true;
            }
        } else if (currentItem == null) {
        // Fall through the end of the test
        } else if (currentItem.getItem() == Items.sign) {
            // Sign will be placed anyway, so lets show the sign gui
            return false;
        } else if (currentItem.getItem() instanceof ItemPipe) {
            return false;
        } else if (currentItem.getItem() instanceof ItemGateCopier) {
            return false;
        } else if (currentItem.getItem() instanceof IToolWrench) {
            // Only check the instance at this point. Call the IToolWrench
            // interface callbacks for the individual pipe/logic calls
            RaytraceResult rayTraceResult = doRayTrace(world, pos, player);
            if (rayTraceResult != null) {
                EnumFacing hitSide = rayTraceResult.hitPart == Part.Pipe ? rayTraceResult.sideHit : null;
                return pipe.blockActivated(player, hitSide);
            } else {
                return pipe.blockActivated(player, null);
            }
        } else if (currentItem.getItem() instanceof IMapLocation) {
            // We want to be able to record pipe locations
            return false;
        } else if (PipeWire.RED.isPipeWire(currentItem)) {
            if (addOrStripWire(player, pipe, PipeWire.RED)) {
                return true;
            }
        } else if (PipeWire.BLUE.isPipeWire(currentItem)) {
            if (addOrStripWire(player, pipe, PipeWire.BLUE)) {
                return true;
            }
        } else if (PipeWire.GREEN.isPipeWire(currentItem)) {
            if (addOrStripWire(player, pipe, PipeWire.GREEN)) {
                return true;
            }
        } else if (PipeWire.YELLOW.isPipeWire(currentItem)) {
            if (addOrStripWire(player, pipe, PipeWire.YELLOW)) {
                return true;
            }
        } else if (currentItem.getItem() == Items.water_bucket) {
            if (!world.isRemote) {
                pipe.container.setPipeColor(-1);
            }
            return true;
        } else if (currentItem.getItem() instanceof IPipePluggableItem) {
            if (addOrStripPipePluggable(world, pos, currentItem, player, side, pipe)) {
                return true;
            }
        }
        Gate clickedGate = null;
        if (rayTrace != null && rayTrace.hitPart == Part.Pluggable && pipe.container.getPipePluggable(rayTrace.sideHit) instanceof GatePluggable) {
            clickedGate = pipe.gates[rayTrace.sideHit.ordinal()];
        }
        if (clickedGate != null) {
            clickedGate.openGui(player);
            return true;
        } else {
            if (pipe.blockActivated(player, side)) {
                return true;
            }
            if (rayTrace != null) {
                EnumFacing hitSide = rayTrace.hitPart == Part.Pipe ? rayTrace.sideHit : null;
                return pipe.blockActivated(player, hitSide);
            }
        }
    }
    return false;
}
Also used : IToolWrench(buildcraft.api.tools.IToolWrench) EnumFacing(net.minecraft.util.EnumFacing) IMapLocation(buildcraft.api.items.IMapLocation) ItemStack(net.minecraft.item.ItemStack) IPipePluggableItem(buildcraft.api.transport.pluggable.IPipePluggableItem) GatePluggable(buildcraft.transport.gates.GatePluggable)

Example 5 with GatePluggable

use of buildcraft.transport.gates.GatePluggable in project BuildCraft by BuildCraft.

the class ItemGateCopier method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    }
    boolean isCopying = !player.isSneaking();
    Block block = world.getBlockState(pos).getBlock();
    TileEntity tile = world.getTileEntity(pos);
    NBTTagCompound data = NBTUtilBC.getItemData(stack);
    PipePluggable pluggable = null;
    Gate gate = null;
    if (tile == null || !(tile instanceof IPipeTile)) {
        isCopying = true;
    } else {
        if (tile instanceof TileGenericPipe && block instanceof BlockGenericPipe) {
            RaytraceResult rayTraceResult = ((BlockGenericPipe) block).doRayTrace(world, pos, player);
            if (rayTraceResult != null && rayTraceResult.boundingBox != null && rayTraceResult.hitPart == Part.Pluggable) {
                pluggable = ((TileGenericPipe) tile).getPipePluggable(rayTraceResult.sideHit);
            }
        } else {
            pluggable = ((IPipeTile) tile).getPipePluggable(side);
        }
    }
    if (pluggable instanceof GatePluggable) {
        gate = ((GatePluggable) pluggable).realGate;
    }
    if (isCopying) {
        if (gate == null) {
            data = new NBTTagCompound();
            stack.setTagCompound(data);
            // Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
            data.setBoolean("Unbreakable", true);
            // Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
            data.setInteger("HideFlags", 4);
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.clear"));
            return true;
        }
        data = new NBTTagCompound();
        stack.setTagCompound(data);
        gate.writeStatementsToNBT(data);
        data.setByte("material", (byte) gate.material.ordinal());
        data.setByte("logic", (byte) gate.logic.ordinal());
        player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gateCopied"));
        // Tell ItemModelMesher that this is NOT damageable, so it will use the meta for the icon
        data.setBoolean("Unbreakable", true);
        // Tell ItemStack.getToolTip() that we want to hide the resulting "Unbreakable" line that we just added
        data.setInteger("HideFlags", 4);
    } else {
        if (!data.hasKey("logic")) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noInformation"));
            return true;
        } else if (gate == null) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.noGate"));
            return true;
        }
        GateMaterial dataMaterial = GateMaterial.fromOrdinal(data.getByte("material"));
        GateMaterial gateMaterial = gate.material;
        if (gateMaterial.numSlots < dataMaterial.numSlots) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.slots"));
        }
        if (gateMaterial.numActionParameters < dataMaterial.numActionParameters) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.actionParameters"));
        }
        if (gateMaterial.numTriggerParameters < dataMaterial.numTriggerParameters) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.triggerParameters"));
        }
        if (data.getByte("logic") != gate.logic.ordinal()) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.logic"));
        }
        gate.readStatementsFromNBT(data);
        if (!gate.verifyGateStatements()) {
            player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.warning.load"));
        }
        if (tile instanceof TileGenericPipe) {
            ((TileGenericPipe) tile).sendNetworkUpdate();
        }
        player.addChatMessage(new ChatComponentTranslation("chat.gateCopier.gatePasted"));
        return true;
    }
    return true;
}
Also used : IPipeTile(buildcraft.api.transport.IPipeTile) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) TileEntity(net.minecraft.tileentity.TileEntity) GateMaterial(buildcraft.transport.gates.GateDefinition.GateMaterial) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) Block(net.minecraft.block.Block) RaytraceResult(buildcraft.transport.BlockGenericPipe.RaytraceResult) GatePluggable(buildcraft.transport.gates.GatePluggable)

Aggregations

GatePluggable (buildcraft.transport.gates.GatePluggable)5 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)2 IGateExpansion (buildcraft.api.gates.IGateExpansion)1 IMapLocation (buildcraft.api.items.IMapLocation)1 IToolWrench (buildcraft.api.tools.IToolWrench)1 IPipeTile (buildcraft.api.transport.IPipeTile)1 IPipePluggableItem (buildcraft.api.transport.pluggable.IPipePluggableItem)1 RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)1 RaytraceResult (buildcraft.transport.BlockGenericPipe.RaytraceResult)1 GateMaterial (buildcraft.transport.gates.GateDefinition.GateMaterial)1 LogisticsRoutingBoardRobot (logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot)1 SneakyThrows (lombok.SneakyThrows)1 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 EnumFacing (net.minecraft.util.EnumFacing)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1