Search in sources :

Example 1 with IStripesHandler

use of buildcraft.api.transport.IStripesHandler in project BuildCraft by BuildCraft.

the class PipeItemsStripes method eventHandler.

public void eventHandler(PipeEventItem.DropItem event) {
    if (container.getWorld().isRemote) {
        return;
    }
    EnumFacing direction = actionDir.face;
    if (direction == null) {
        direction = event.direction;
    }
    Vec3d p = Utils.convert(container.getPos()).add(Utils.convert(direction));
    ItemStack stack = event.entity.getEntityItem();
    EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(), Utils.convertFloor(p)).get();
    switch(direction) {
        case DOWN:
            player.rotationPitch = 90;
            player.rotationYaw = 0;
            break;
        case UP:
            player.rotationPitch = 270;
            player.rotationYaw = 0;
            break;
        case NORTH:
            player.rotationPitch = 0;
            player.rotationYaw = 180;
            break;
        case SOUTH:
            player.rotationPitch = 0;
            player.rotationYaw = 0;
            break;
        case WEST:
            player.rotationPitch = 0;
            player.rotationYaw = 90;
            break;
        case EAST:
            player.rotationPitch = 0;
            player.rotationYaw = 270;
            break;
    }
    /**
     * Check if there's a handler for this item type.
     */
    for (IStripesHandler handler : PipeManager.stripesHandlers) {
        if (handler.getType() == StripesHandlerType.ITEM_USE && handler.shouldHandle(stack)) {
            if (handler.handle(getWorld(), Utils.convertFloor(p), direction, stack, player, this)) {
                event.entity = null;
                return;
            }
        }
    }
}
Also used : IStripesHandler(buildcraft.api.transport.IStripesHandler) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with IStripesHandler

use of buildcraft.api.transport.IStripesHandler in project BuildCraft by BuildCraft.

the class PipeItemsStripes method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (container.getWorld().isRemote) {
        return;
    }
    if (battery.getEnergyStored() >= 10) {
        EnumPipePart o = actionDir;
        if (o == EnumPipePart.CENTER) {
            o = EnumPipePart.fromFacing(getOpenOrientation());
        }
        if (o != EnumPipePart.CENTER) {
            Vec3d vec = Utils.convert(container.getPos()).add(Utils.convert(o.face));
            BlockPos veci = Utils.convertFloor(vec);
            if (!BlockUtil.isUnbreakableBlock(getWorld(), Utils.convertFloor(vec))) {
                IBlockState state = getWorld().getBlockState(Utils.convertFloor(vec));
                Block block = state.getBlock();
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    return;
                }
                ItemStack stack = new ItemStack(block, 1, block.getMetaFromState(state));
                EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(), veci).get();
                if (battery.useEnergy(10, 10, false) != 10) {
                    return;
                }
                for (IStripesHandler handler : PipeManager.stripesHandlers) {
                    if (handler.getType() == StripesHandlerType.BLOCK_BREAK && handler.shouldHandle(stack)) {
                        if (handler.handle(getWorld(), veci, o.face, stack, player, this)) {
                            return;
                        }
                    }
                }
                List<ItemStack> stacks = block.getDrops(getWorld(), veci, state, 0);
                if (stacks != null) {
                    for (ItemStack s : stacks) {
                        if (s != null) {
                            sendItem(s, o.opposite().face);
                        }
                    }
                }
                getWorld().setBlockToAir(veci);
            }
        }
        return;
    }
}
Also used : IStripesHandler(buildcraft.api.transport.IStripesHandler) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EnumPipePart(buildcraft.api.core.EnumPipePart) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with IStripesHandler

use of buildcraft.api.transport.IStripesHandler in project BuildCraft by BuildCraft.

the class AIRobotStripesHandler method update.

@Override
public void update() {
    if (useToBlock == null) {
        setSuccess(false);
        terminate();
        return;
    }
    useCycles++;
    if (useCycles > 60) {
        ItemStack stack = robot.getHeldItem();
        EnumFacing direction = EnumFacing.NORTH;
        EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) robot.worldObj, useToBlock).get();
        player.rotationPitch = 0;
        player.rotationYaw = 180;
        for (IStripesHandler handler : PipeManager.stripesHandlers) {
            if (handler.getType() == StripesHandlerType.ITEM_USE && handler.shouldHandle(stack)) {
                if (handler.handle(robot.worldObj, useToBlock, direction, stack, player, this)) {
                    robot.setItemInUse(null);
                    terminate();
                    return;
                }
            }
        }
        terminate();
    }
}
Also used : IStripesHandler(buildcraft.api.transport.IStripesHandler) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IStripesHandler (buildcraft.api.transport.IStripesHandler)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 WorldServer (net.minecraft.world.WorldServer)3 EnumFacing (net.minecraft.util.EnumFacing)2 Vec3d (net.minecraft.util.math.Vec3d)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 Block (net.minecraft.block.Block)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)1