Search in sources :

Example 36 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project BetterStorage by copygirl.

the class Attachments method rayTrace.

// Called in Block.collisionRayTrace.
public MovingObjectPosition rayTrace(World world, int x, int y, int z, Vec3 start, Vec3 end) {
    AxisAlignedBB aabb = tileEntity.getBlockType().getCollisionBoundingBoxFromPool(world, x, y, z);
    MovingObjectPosition target = aabb.calculateIntercept(start, end);
    EntityPlayer player = playerLocal.get();
    double distance = ((target != null) ? start.distanceTo(target.hitVec) : Double.MAX_VALUE);
    for (Attachment attachment : this) {
        if (!attachment.boxVisible(player))
            continue;
        AxisAlignedBB attachmentBox = attachment.getHighlightBox();
        MovingObjectPosition attachmentTarget = attachmentBox.calculateIntercept(start, end);
        if (attachmentTarget == null)
            continue;
        double attachmentDistance = start.distanceTo(attachmentTarget.hitVec);
        if (attachmentDistance >= distance)
            continue;
        distance = attachmentDistance;
        target = attachmentTarget;
        target.subHit = attachment.subId;
    }
    if (target != null) {
        target.blockX = x;
        target.blockY = y;
        target.blockZ = z;
    }
    return target;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 37 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project PneumaticCraft by MineMaarten.

the class ThaumcraftApiHelper method rayTraceIgnoringSource.

public static MovingObjectPosition rayTraceIgnoringSource(World world, Vec3 v1, Vec3 v2, boolean bool1, boolean bool2, boolean bool3) {
    if (!Double.isNaN(v1.xCoord) && !Double.isNaN(v1.yCoord) && !Double.isNaN(v1.zCoord)) {
        if (!Double.isNaN(v2.xCoord) && !Double.isNaN(v2.yCoord) && !Double.isNaN(v2.zCoord)) {
            int i = MathHelper.floor_double(v2.xCoord);
            int j = MathHelper.floor_double(v2.yCoord);
            int k = MathHelper.floor_double(v2.zCoord);
            int l = MathHelper.floor_double(v1.xCoord);
            int i1 = MathHelper.floor_double(v1.yCoord);
            int j1 = MathHelper.floor_double(v1.zCoord);
            Block block = world.getBlock(l, i1, j1);
            int k1 = world.getBlockMetadata(l, i1, j1);
            MovingObjectPosition movingobjectposition2 = null;
            k1 = 200;
            while (k1-- >= 0) {
                if (Double.isNaN(v1.xCoord) || Double.isNaN(v1.yCoord) || Double.isNaN(v1.zCoord)) {
                    return null;
                }
                if (l == i && i1 == j && j1 == k) {
                    continue;
                }
                boolean flag6 = true;
                boolean flag3 = true;
                boolean flag4 = true;
                double d0 = 999.0D;
                double d1 = 999.0D;
                double d2 = 999.0D;
                if (i > l) {
                    d0 = (double) l + 1.0D;
                } else if (i < l) {
                    d0 = (double) l + 0.0D;
                } else {
                    flag6 = false;
                }
                if (j > i1) {
                    d1 = (double) i1 + 1.0D;
                } else if (j < i1) {
                    d1 = (double) i1 + 0.0D;
                } else {
                    flag3 = false;
                }
                if (k > j1) {
                    d2 = (double) j1 + 1.0D;
                } else if (k < j1) {
                    d2 = (double) j1 + 0.0D;
                } else {
                    flag4 = false;
                }
                double d3 = 999.0D;
                double d4 = 999.0D;
                double d5 = 999.0D;
                double d6 = v2.xCoord - v1.xCoord;
                double d7 = v2.yCoord - v1.yCoord;
                double d8 = v2.zCoord - v1.zCoord;
                if (flag6) {
                    d3 = (d0 - v1.xCoord) / d6;
                }
                if (flag3) {
                    d4 = (d1 - v1.yCoord) / d7;
                }
                if (flag4) {
                    d5 = (d2 - v1.zCoord) / d8;
                }
                boolean flag5 = false;
                byte b0;
                if (d3 < d4 && d3 < d5) {
                    if (i > l) {
                        b0 = 4;
                    } else {
                        b0 = 5;
                    }
                    v1.xCoord = d0;
                    v1.yCoord += d7 * d3;
                    v1.zCoord += d8 * d3;
                } else if (d4 < d5) {
                    if (j > i1) {
                        b0 = 0;
                    } else {
                        b0 = 1;
                    }
                    v1.xCoord += d6 * d4;
                    v1.yCoord = d1;
                    v1.zCoord += d8 * d4;
                } else {
                    if (k > j1) {
                        b0 = 2;
                    } else {
                        b0 = 3;
                    }
                    v1.xCoord += d6 * d5;
                    v1.yCoord += d7 * d5;
                    v1.zCoord = d2;
                }
                Vec3 vec32 = Vec3.createVectorHelper(v1.xCoord, v1.yCoord, v1.zCoord);
                l = (int) (vec32.xCoord = (double) MathHelper.floor_double(v1.xCoord));
                if (b0 == 5) {
                    --l;
                    ++vec32.xCoord;
                }
                i1 = (int) (vec32.yCoord = (double) MathHelper.floor_double(v1.yCoord));
                if (b0 == 1) {
                    --i1;
                    ++vec32.yCoord;
                }
                j1 = (int) (vec32.zCoord = (double) MathHelper.floor_double(v1.zCoord));
                if (b0 == 3) {
                    --j1;
                    ++vec32.zCoord;
                }
                Block block1 = world.getBlock(l, i1, j1);
                int l1 = world.getBlockMetadata(l, i1, j1);
                if (!bool2 || block1.getCollisionBoundingBoxFromPool(world, l, i1, j1) != null) {
                    if (block1.canCollideCheck(l1, bool1)) {
                        MovingObjectPosition movingobjectposition1 = block1.collisionRayTrace(world, l, i1, j1, v1, v2);
                        if (movingobjectposition1 != null) {
                            return movingobjectposition1;
                        }
                    } else {
                        movingobjectposition2 = new MovingObjectPosition(l, i1, j1, b0, v1, false);
                    }
                }
            }
            return bool3 ? movingobjectposition2 : null;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) Block(net.minecraft.block.Block)

Example 38 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project PneumaticCraft by MineMaarten.

the class BlockPressureTube method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    MovingObjectPosition bestMOP = null;
    AxisAlignedBB bestAABB = null;
    setBlockBounds(BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS);
    MovingObjectPosition mop = super.collisionRayTrace(world, x, y, z, origin, direction);
    if (isCloserMOP(origin, bestMOP, mop)) {
        bestMOP = mop;
        bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
    }
    TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
    for (int i = 0; i < 6; i++) {
        if (tube.sidesConnected[i]) {
            setBlockBounds(boundingBoxes[i]);
            mop = super.collisionRayTrace(world, x, y, z, origin, direction);
            if (isCloserMOP(origin, bestMOP, mop)) {
                bestMOP = mop;
                bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
            }
        }
    }
    //unknown indicates we hit the tube.
    if (bestMOP != null)
        bestMOP.hitInfo = ForgeDirection.UNKNOWN;
    TubeModule[] modules = tube.modules;
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (modules[dir.ordinal()] != null) {
            setBlockBounds(modules[dir.ordinal()].boundingBoxes[dir.ordinal()]);
            mop = super.collisionRayTrace(world, x, y, z, origin, direction);
            if (isCloserMOP(origin, bestMOP, mop)) {
                mop.hitInfo = dir;
                bestMOP = mop;
                bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
            }
        }
    }
    if (bestAABB != null)
        setBlockBounds(bestAABB);
    return bestMOP;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 39 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project PneumaticCraft by MineMaarten.

the class BlockPressureTube method getLookedModule.

public static TubeModule getLookedModule(World world, int x, int y, int z, EntityPlayer player) {
    Pair<Vec3, Vec3> vecs = PneumaticCraftUtils.getStartAndEndLookVec(player);
    MovingObjectPosition mop = Blockss.pressureTube.collisionRayTrace(world, x, y, z, vecs.getLeft(), vecs.getRight());
    if (mop != null && mop.hitInfo instanceof ForgeDirection && (ForgeDirection) mop.hitInfo != ForgeDirection.UNKNOWN) {
        TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
        return tube.modules[((ForgeDirection) mop.hitInfo).ordinal()];
    }
    return null;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 40 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project PneumaticCraft by MineMaarten.

the class FMPPlacementListener method place.

public static boolean place(EntityPlayer player, World world) {
    MovingObjectPosition hit = RayTracer.reTrace(world, player);
    if (hit == null)
        return false;
    BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
    ItemStack held = player.getHeldItem();
    PartPressureTube part = null;
    if (held == null)
        return false;
    Block heldBlock = Block.getBlockFromItem(held.getItem());
    if (heldBlock == Blockss.pressureTube) {
        part = new PartPressureTube();
    } else if (heldBlock == Blockss.advancedPressureTube) {
        part = new PartAdvancedPressureTube();
    }
    if (part == null)
        return false;
    if (//attempt to use block activated like normal and tell the server the right stuff
    world.isRemote && !player.isSneaking()) {
        Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
        Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
        if (!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z)) {
            player.swingItem();
            PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x, (float) f.y, (float) f.z));
            return true;
        }
    }
    TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
    if (tile == null || !tile.canAddPart(part)) {
        pos = pos.offset(hit.sideHit);
        tile = TileMultipart.getOrConvertTile(world, pos);
        if (tile == null || !tile.canAddPart(part))
            return false;
    }
    if (!world.isRemote) {
        TileMultipart.addPart(world, pos, part);
        world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blockss.pressureTube.stepSound.func_150496_b(), (Blockss.pressureTube.stepSound.getVolume() + 1.0F) / 2.0F, Blockss.pressureTube.stepSound.getPitch() * 0.8F);
        if (!player.capabilities.isCreativeMode) {
            held.stackSize--;
            if (held.stackSize == 0) {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
                MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
            }
        }
    } else {
        player.swingItem();
        NetworkHandler.sendToServer(new PacketFMPPlacePart());
    }
    return true;
}
Also used : TileMultipart(codechicken.multipart.TileMultipart) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) C08PacketPlayerBlockPlacement(net.minecraft.network.play.client.C08PacketPlayerBlockPlacement) Block(net.minecraft.block.Block) Vector3(codechicken.lib.vec.Vector3) BlockCoord(codechicken.lib.vec.BlockCoord) ItemStack(net.minecraft.item.ItemStack) PlayerDestroyItemEvent(net.minecraftforge.event.entity.player.PlayerDestroyItemEvent)

Aggregations

MovingObjectPosition (net.minecraft.util.MovingObjectPosition)60 Vec3 (net.minecraft.util.Vec3)19 Entity (net.minecraft.entity.Entity)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)17 ItemStack (net.minecraft.item.ItemStack)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Block (net.minecraft.block.Block)8 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 AMVector3 (am2.api.math.AMVector3)5 World (net.minecraft.world.World)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 List (java.util.List)4 SpellCastResult (am2.api.spell.enums.SpellCastResult)3 ParticleApproachPoint (am2.particles.ParticleApproachPoint)3 IBlockState (net.minecraft.block.state.IBlockState)3 AMParticle (am2.particles.AMParticle)2 PacketPlayerItem (com.builtbroken.mc.core.network.packet.PacketPlayerItem)2