Search in sources :

Example 1 with QMovingObjectPosition

use of uk.co.qmunity.lib.raytrace.QMovingObjectPosition in project BluePower by Qmunity.

the class PneumaticTube method rayTrace.

@Override
public QMovingObjectPosition rayTrace(Vec3d start, Vec3d end) {
    QMovingObjectPosition mop = super.rayTrace(start, end);
    if (mop == null)
        return null;
    EntityPlayer player = BluePower.proxy.getPlayer();
    if (redwireType != null && player != null && player.isSneaking()) {
        double wireSize = getSize() / 16D;
        double frameSeparation = 4 / 16D - (wireSize - 2 / 16D);
        double frameThickness = 1 / 16D;
        frameThickness /= 1.5;
        frameSeparation -= 1 / 32D;
        QMovingObjectPosition wire = RayTracer.instance().rayTraceCubes(getFrameBoxes(wireSize, frameSeparation, frameThickness, shouldRenderConnection(ForgeDirection.DOWN), shouldRenderConnection(ForgeDirection.UP), shouldRenderConnection(ForgeDirection.WEST), shouldRenderConnection(ForgeDirection.EAST), shouldRenderConnection(ForgeDirection.NORTH), shouldRenderConnection(ForgeDirection.SOUTH), redstoneConnections[ForgeDirection.DOWN.ordinal()], redstoneConnections[ForgeDirection.UP.ordinal()], redstoneConnections[ForgeDirection.WEST.ordinal()], redstoneConnections[ForgeDirection.EAST.ordinal()], redstoneConnections[ForgeDirection.NORTH.ordinal()], redstoneConnections[ForgeDirection.SOUTH.ordinal()], getParent() != null && getWorld() != null), start, end, new Vec3i(this));
        QMovingObjectPosition frame = RayTracer.instance().rayTraceCubes(getFrameBoxes(), start, end, new Vec3i(this));
        if (wire != null) {
            if (frame != null) {
                if (wire.hitVec.distanceTo(start.toVec3()) < frame.hitVec.distanceTo(start.toVec3()))
                    mop.hitInfo = PartManager.getPartInfo("wire." + redwireType.getName()).getStack();
            } else {
                mop.hitInfo = PartManager.getPartInfo("wire." + redwireType.getName()).getStack();
            }
        }
    }
    return mop;
}
Also used : Vec3i(uk.co.qmunity.lib.vec.Vec3i) EntityPlayer(net.minecraft.entity.player.EntityPlayer) QMovingObjectPosition(uk.co.qmunity.lib.raytrace.QMovingObjectPosition)

Example 2 with QMovingObjectPosition

use of uk.co.qmunity.lib.raytrace.QMovingObjectPosition in project BluePower by Qmunity.

the class ItemSilkyScrewdriver method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    TileEntity te = world.getTileEntity(x, y, z);
    ITilePartHolder h = MultipartCompatibility.getPartHolder(world, x, y, z);
    if (h != null) {
        QMovingObjectPosition mop = h.rayTrace(RayTracer.instance().getStartVector(player), RayTracer.instance().getEndVector(player));
        if (mop != null) {
            IPart p = mop.getPart();
            if (p instanceof ISilkyRemovable && !world.isRemote) {
                if (p instanceof IAdvancedSilkyRemovable && !((IAdvancedSilkyRemovable) p).preSilkyRemoval(world, x, y, z))
                    return false;
                NBTTagCompound tag = new NBTTagCompound();
                boolean hideTooltip = false;
                if (p instanceof IAdvancedSilkyRemovable) {
                    hideTooltip = ((IAdvancedSilkyRemovable) p).writeSilkyData(world, x, y, z, tag);
                } else {
                    p.writeToNBT(tag);
                }
                ItemStack droppedStack = p.getItem();
                NBTTagCompound stackTag = droppedStack.getTagCompound();
                if (stackTag == null) {
                    stackTag = new NBTTagCompound();
                    droppedStack.setTagCompound(stackTag);
                }
                stackTag.setTag("tileData", tag);
                stackTag.setBoolean("hideSilkyTooltip", hideTooltip);
                world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, droppedStack));
                h.removePart(p);
                if (p instanceof IAdvancedSilkyRemovable)
                    ((IAdvancedSilkyRemovable) p).postSilkyRemoval(world, x, y, z);
                stack.damageItem(1, player);
                return true;
            }
        }
        return false;
    }
    if (block instanceof ISilkyRemovable && !world.isRemote) {
        if (block instanceof IAdvancedSilkyRemovable && !((IAdvancedSilkyRemovable) block).preSilkyRemoval(world, x, y, z))
            return false;
        if (te == null)
            throw new IllegalStateException("Block doesn't have a TileEntity?! Implementers of ISilkyRemovable should have one. Offender: " + block.getUnlocalizedName());
        NBTTagCompound tag = new NBTTagCompound();
        te.writeToNBT(tag);
        int metadata = world.getBlockMetadata(x, y, z);
        Item item = block.getItemDropped(metadata, itemRand, 0);
        if (item == null)
            throw new NullPointerException("Block returns null for getItemDropped(meta, rand, fortune)! Offender: " + block.getUnlocalizedName());
        ItemStack droppedStack = new ItemStack(item, 1, block.damageDropped(metadata));
        NBTTagCompound stackTag = droppedStack.getTagCompound();
        if (stackTag == null) {
            stackTag = new NBTTagCompound();
            droppedStack.setTagCompound(stackTag);
        }
        stackTag.setTag("tileData", tag);
        world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, droppedStack));
        world.setBlockToAir(x, y, z);
        if (block instanceof IAdvancedSilkyRemovable)
            ((IAdvancedSilkyRemovable) block).postSilkyRemoval(world, x, y, z);
        stack.damageItem(1, player);
        return true;
    }
    return false;
}
Also used : IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QMovingObjectPosition(uk.co.qmunity.lib.raytrace.QMovingObjectPosition) TileEntity(net.minecraft.tileentity.TileEntity) ITilePartHolder(uk.co.qmunity.lib.part.ITilePartHolder) EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) IPart(uk.co.qmunity.lib.part.IPart) ISilkyRemovable(com.bluepowermod.api.block.ISilkyRemovable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

QMovingObjectPosition (uk.co.qmunity.lib.raytrace.QMovingObjectPosition)2 IAdvancedSilkyRemovable (com.bluepowermod.api.block.IAdvancedSilkyRemovable)1 ISilkyRemovable (com.bluepowermod.api.block.ISilkyRemovable)1 Block (net.minecraft.block.Block)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IPart (uk.co.qmunity.lib.part.IPart)1 ITilePartHolder (uk.co.qmunity.lib.part.ITilePartHolder)1 Vec3i (uk.co.qmunity.lib.vec.Vec3i)1