Search in sources :

Example 1 with ItemRobot

use of buildcraft.robotics.ItemRobot in project LogisticsPipes by RS485.

the class BuildCraftProxy method checkRobot.

/**
	 * @see buildcraft.robotics.ItemRobot#onItemUse(ItemStack, EntityPlayer,
	 *      World, int, int, int, int, float, float, float)
	 */
private boolean checkRobot(World world, int x, int y, int z, EntityPlayer player, ItemStack currentItem) {
    if (!world.isRemote) {
        Pipe<?> bcPipe = BlockGenericPipe.getPipe(world, x, y, z);
        if (bcPipe == null) {
            return false;
        }
        BlockGenericPipe pipeBlock = BuildCraftTransport.genericPipeBlock;
        BlockGenericPipe.RaytraceResult rayTraceResult = pipeBlock.doRayTrace(world, x, y, z, player);
        if (rayTraceResult != null && rayTraceResult.hitPart == BlockGenericPipe.Part.Pluggable && bcPipe.container.getPipePluggable(rayTraceResult.sideHit) instanceof RobotStationPluggable) {
            RobotStationPluggable pluggable = (RobotStationPluggable) bcPipe.container.getPipePluggable(rayTraceResult.sideHit);
            DockingStation station = pluggable.getStation();
            if (!station.isTaken()) {
                RedstoneBoardRobotNBT robotNBT = ItemRobot.getRobotNBT(currentItem);
                if (robotNBT == RedstoneBoardRegistry.instance.getEmptyRobotBoard()) {
                    return true;
                }
                EntityRobot robot = ((ItemRobot) currentItem.getItem()).createRobot(currentItem, world);
                RobotEvent.Place robotEvent = new RobotEvent.Place(robot, player);
                FMLCommonHandler.instance().bus().post(robotEvent);
                if (robotEvent.isCanceled()) {
                    return true;
                }
                if (robot != null && robot.getRegistry() != null) {
                    robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());
                    float px = x + 0.5F + rayTraceResult.sideHit.offsetX * 0.5F;
                    float py = y + 0.5F + rayTraceResult.sideHit.offsetY * 0.5F;
                    float pz = z + 0.5F + rayTraceResult.sideHit.offsetZ * 0.5F;
                    robot.setPosition(px, py, pz);
                    station.takeAsMain(robot);
                    robot.dock(robot.getLinkedStation());
                    world.spawnEntityInWorld(robot);
                    if (!player.capabilities.isCreativeMode) {
                        player.getCurrentEquippedItem().stackSize--;
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) DockingStation(buildcraft.api.robots.DockingStation) EntityRobot(buildcraft.robotics.EntityRobot) BlockGenericPipe(buildcraft.transport.BlockGenericPipe) RedstoneBoardRobotNBT(buildcraft.api.boards.RedstoneBoardRobotNBT) ItemRobot(buildcraft.robotics.ItemRobot) RobotEvent(buildcraft.api.events.RobotEvent)

Example 2 with ItemRobot

use of buildcraft.robotics.ItemRobot in project LogisticsPipes by RS485.

the class BuildCraftProxy method handleBCClickOnPipe.

@Override
public IBCClickResult handleBCClickOnPipe(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset, CoreUnroutedPipe pipe) {
    boolean result = BuildCraftTransport.genericPipeBlock.onBlockActivated(world, x, y, z, player, side, xOffset, yOffset, zOffset);
    //Again because not all changes have been applied before the call inside the BC method is made.
    world.notifyBlocksOfNeighborChange(x, y, z, LogisticsPipes.LogisticsPipeBlock);
    boolean block = false;
    if (!result) {
        ItemStack currentItem = player.getCurrentEquippedItem();
        if (currentItem != null) {
            if (currentItem.getItem() == Items.sign) {
                block = true;
            } else if (currentItem.getItem() instanceof ItemPipe) {
                block = true;
            } else if (currentItem.getItem() instanceof ItemGateCopier) {
                block = true;
            } else if (currentItem.getItem() instanceof ItemMapLocation) {
                block = true;
            } else if (currentItem.getItem() instanceof ItemRobot) {
                result = checkRobot(world, x, y, z, player, currentItem);
            }
        }
    }
    final boolean fResult = result;
    final boolean fBlock = block;
    return new IBCClickResult() {

        @Override
        public boolean handled() {
            return fResult;
        }

        @Override
        public boolean blocked() {
            return fBlock;
        }
    };
}
Also used : ItemGateCopier(buildcraft.transport.ItemGateCopier) ItemMapLocation(buildcraft.core.ItemMapLocation) IBCClickResult(logisticspipes.proxy.buildcraft.subproxies.IBCClickResult) ItemPipe(buildcraft.transport.ItemPipe) ItemStack(net.minecraft.item.ItemStack) ItemRobot(buildcraft.robotics.ItemRobot)

Aggregations

ItemRobot (buildcraft.robotics.ItemRobot)2 RedstoneBoardRobotNBT (buildcraft.api.boards.RedstoneBoardRobotNBT)1 RobotEvent (buildcraft.api.events.RobotEvent)1 DockingStation (buildcraft.api.robots.DockingStation)1 ItemMapLocation (buildcraft.core.ItemMapLocation)1 EntityRobot (buildcraft.robotics.EntityRobot)1 RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)1 BlockGenericPipe (buildcraft.transport.BlockGenericPipe)1 ItemGateCopier (buildcraft.transport.ItemGateCopier)1 ItemPipe (buildcraft.transport.ItemPipe)1 IBCClickResult (logisticspipes.proxy.buildcraft.subproxies.IBCClickResult)1 ItemStack (net.minecraft.item.ItemStack)1