Search in sources :

Example 86 with Vec3i

use of net.minecraft.util.math.Vec3i in project 3arthh4ck by 3arthqu4ke.

the class RayTraceFactory method rayTrace.

/**
 * Performs the SmartRaytrace.
 * A res value of >= 1.0 means that just the middle
 * of the block will be traced, a value <= 0 means
 * that the 4 corners and the middle will be traced
 * and other values set the step width for many raytraces.
 * A value of -1.0 is recommended.
 *
 * @param from the entity from whose eyes to trace.
 * @param on the position to trace to.
 * @param facing the offset to the position.
 * @param access BlockAccess
 * @param state the state at the position
 * @param res the resolution as explained above
 * @return a Ray, never null.
 */
public static Ray rayTrace(Entity from, BlockPos on, EnumFacing facing, IBlockAccess access, IBlockState state, double res) {
    Vec3d start = PositionUtil.getEyePos(from);
    AxisAlignedBB bb = state.getBoundingBox(access, on);
    if (res >= 1.0) {
        float[] r = rots(on, facing, from, access, state);
        Vec3d look = RotationUtil.getVec3d(r[0], r[1]);
        double d = mc.playerController.getBlockReachDistance();
        Vec3d rotations = start.add(look.x * d, look.y * d, look.z * d);
        RayTraceResult result = RayTracer.trace(mc.world, access, start, rotations, false, false, true);
        if (result == null || result.sideHit != facing || !on.equals(result.getBlockPos())) {
            return dumbRay(on, facing, r);
        }
        return new Ray(result, r, on, facing, null).setLegit(true);
    } else {
        Vec3i dirVec = facing.getDirectionVec();
        double dirX = dirVec.getX() < 0 ? bb.minX : dirVec.getX() * bb.maxX;
        double dirY = dirVec.getY() < 0 ? bb.minY : dirVec.getY() * bb.maxY;
        double dirZ = dirVec.getZ() < 0 ? bb.minZ : dirVec.getZ() * bb.maxZ;
        double minX = on.getX() + dirX + (dirVec.getX() == 0 ? bb.minX : 0);
        double minY = on.getY() + dirY + (dirVec.getY() == 0 ? bb.minY : 0);
        double minZ = on.getZ() + dirZ + (dirVec.getZ() == 0 ? bb.minZ : 0);
        double maxX = on.getX() + dirX + (dirVec.getX() == 0 ? bb.maxX : 0);
        double maxY = on.getY() + dirY + (dirVec.getY() == 0 ? bb.maxY : 0);
        double maxZ = on.getZ() + dirZ + (dirVec.getZ() == 0 ? bb.maxZ : 0);
        boolean xEq = Double.compare(minX, maxX) == 0;
        boolean yEq = Double.compare(minY, maxY) == 0;
        boolean zEq = Double.compare(minZ, maxZ) == 0;
        // These ifs set the position slightly into the block
        if (xEq) {
            minX -= dirVec.getX() * 0.0005;
            maxX = minX;
        }
        if (yEq) {
            minY -= dirVec.getY() * 0.0005;
            maxY = minY;
        }
        if (zEq) {
            minZ -= dirVec.getZ() * 0.0005;
            maxZ = minZ;
        }
        // determine max and min x, y and z
        // xEq ? 0 : 0.0005 makes slight offsets or we hit other blocks
        // TODO: use the Res to make the Offsets!!!
        double endX = Math.max(minX, maxX) - (xEq ? 0 : 0.0005);
        double endY = Math.max(minY, maxY) - (yEq ? 0 : 0.0005);
        double endZ = Math.max(minZ, maxZ) - (zEq ? 0 : 0.0005);
        if (// 4 corners + middle
        res <= 0.0) {
            double staX = Math.min(minX, maxX) + (xEq ? 0 : 0.0005);
            double staY = Math.min(minY, maxY) + (yEq ? 0 : 0.0005);
            double staZ = Math.min(minZ, maxZ) + (zEq ? 0 : 0.0005);
            // I mean instead of using a Set we could just think
            // about which 5 vectors are unique but ¯\_(ツ)_/¯
            Set<Vec3d> vectors = new HashSet<>();
            vectors.add(new Vec3d(staX, staY, staZ));
            vectors.add(new Vec3d(staX, staY, endZ));
            vectors.add(new Vec3d(staX, endY, staZ));
            vectors.add(new Vec3d(staX, endY, endZ));
            vectors.add(new Vec3d(endX, staY, staZ));
            vectors.add(new Vec3d(endX, staY, endZ));
            vectors.add(new Vec3d(endX, endY, staZ));
            vectors.add(new Vec3d(endX, endY, endZ));
            double x = (endX - staX) / 2.0 + staX;
            double y = (endY - staY) / 2.0 + staY;
            double z = (endZ - staZ) / 2.0 + staZ;
            // middle of the block side
            vectors.add(new Vec3d(x, y, z));
            for (Vec3d vec : vectors) {
                RayTraceResult ray = RayTracer.trace(mc.world, access, start, vec, false, false, true);
                if (ray != null && on.equals(ray.getBlockPos()) && facing == ray.sideHit) {
                    return new Ray(ray, rots(from, vec), on, facing, vec).setLegit(true);
                }
            }
            return dumbRay(on, facing, rots(on, facing, from, access, state));
        }
        // TODO: this shouldn't be required anymore
        for (double x = Math.min(minX, maxX); x <= endX; x += res) {
            for (double y = Math.min(minY, maxY); y <= endY; y += res) {
                for (double z = Math.min(minZ, maxZ); z <= endZ; z += res) {
                    Vec3d vector = new Vec3d(x, y, z);
                    RayTraceResult ray = RayTracer.trace(mc.world, access, start, vector, false, false, true);
                    if (ray != null && facing == ray.sideHit && on.equals(ray.getBlockPos())) {
                        return new Ray(ray, rots(from, vector), on, facing, vector).setLegit(true);
                    }
                }
            }
        }
    }
    return dumbRay(on, facing, rots(on, facing, from, access, state));
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vec3i(net.minecraft.util.math.Vec3i) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) HashSet(java.util.HashSet)

Example 87 with Vec3i

use of net.minecraft.util.math.Vec3i in project GregTech by GregTechCE.

the class MetaTileEntityTank method clearConnectedTanks.

private void clearConnectedTanks() {
    for (BlockPos tankPos : ImmutableList.copyOf(connectedTanks)) {
        MetaTileEntityTank metaTileEntityTank = getTankTile(tankPos);
        if (metaTileEntityTank == null)
            continue;
        removeTankFromMultiblock(metaTileEntityTank);
    }
    this.connectedTanks.clear();
    this.multiblockSize = new Vec3i(1, 1, 1);
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 88 with Vec3i

use of net.minecraft.util.math.Vec3i in project Gaspunk by Ladysnake.

the class EntityGrenade method onImpact.

@Override
protected void onImpact(@Nonnull RayTraceResult result) {
    if (result.typeOfHit == RayTraceResult.Type.BLOCK && world.getBlockState(result.getBlockPos()).isFullBlock() && this.ignoreTime-- <= 0) {
        Vec3i hitVector = result.sideHit.getDirectionVec();
        motionX *= hitVector.getX() * -0.4 + 0.2;
        if (Math.abs(motionX) < 0.2)
            motionX = 0;
        motionY *= hitVector.getY() * -0.4 + 0.2;
        if (Math.abs(motionY) < 0.3)
            motionY = 0;
        motionZ *= hitVector.getZ() * -0.4 + 0.2;
        if (Math.abs(motionZ) < 0.2)
            motionZ = 0;
        this.ignoreTime = 2;
        isAirBorne = true;
    } else if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
        this.motionX *= -0.05;
        this.motionY *= -0.05;
        this.motionZ *= -0.05;
        this.rotationYaw += 180.0F;
        this.prevRotationYaw += 180.0F;
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i)

Example 89 with Vec3i

use of net.minecraft.util.math.Vec3i in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method rightClickWithItem.

public void rightClickWithItem(@Nonnull World worldIn, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos, @Nonnull EnumFacing sideHit, float hitX, float hitY, float hitZ) {
    ItemStack multiTool = player.getHeldItemMainhand();
    if (multiTool.getItem() != this) {
        return;
    }
    NBTTagCompound tagCompound = multiTool.getTagCompound();
    if (tagCompound == null || !tagCompound.hasKey("Item")) {
        player.sendStatusMessage(new TextComponentString("No block type selected to place."), true);
        return;
    }
    NBTTagCompound itemTag = tagCompound.getCompoundTag("Item");
    ItemStack blockStack = new ItemStack(itemTag);
    if (!(blockStack.getItem() instanceof ItemBlock)) {
        player.sendStatusMessage(new TextComponentString("No valid block type selected to place."), true);
        return;
    }
    IEnergyStorage energy = multiTool.getCapability(ENERGY, null);
    Vec3i sideVector = sideHit.getDirectionVec();
    BlockPos.MutableBlockPos newPosition = new BlockPos.MutableBlockPos(pos.add(sideVector));
    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
        return;
    if (player.isSneaking()) {
        BlockPos playerPos = player.getPosition();
        switch(sideHit) {
            case UP:
                while (newPosition.getY() < playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case DOWN:
                while (newPosition.getY() > playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case NORTH:
                while (newPosition.getZ() > playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case SOUTH:
                while (newPosition.getZ() < playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case EAST:
                while (newPosition.getX() < playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case WEST:
                while (newPosition.getX() > playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 90 with Vec3i

use of net.minecraft.util.math.Vec3i in project Overloaded by CJ-MC-Mods.

the class ModelUtils method renderQuadsARGB.

public static void renderQuadsARGB(List<BakedQuad> listQuads, int ARGB_Hex) {
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    int i = 0;
    for (int j = listQuads.size(); i < j; ++i) {
        BakedQuad bakedquad = (BakedQuad) listQuads.get(i);
        vertexbuffer.begin(7, DefaultVertexFormats.ITEM);
        vertexbuffer.addVertexData(bakedquad.getVertexData());
        vertexbuffer.putColor4(ARGB_Hex);
        Vec3i vec3i = bakedquad.getFace().getDirectionVec();
        vertexbuffer.putNormal((float) vec3i.getX(), (float) vec3i.getY(), (float) vec3i.getZ());
        tessellator.draw();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Vec3i(net.minecraft.util.math.Vec3i) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Aggregations

Vec3i (net.minecraft.util.math.Vec3i)161 BlockPos (net.minecraft.util.math.BlockPos)88 IBlockState (net.minecraft.block.state.IBlockState)29 Vec3d (net.minecraft.util.math.Vec3d)25 EnumFacing (net.minecraft.util.EnumFacing)18 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)15 Block (net.minecraft.block.Block)12 Entity (net.minecraft.entity.Entity)11 ArrayList (java.util.ArrayList)10 World (net.minecraft.world.World)10 TileEntity (net.minecraft.tileentity.TileEntity)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 HashSet (java.util.HashSet)6 Tessellator (net.minecraft.client.renderer.Tessellator)6 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 HashMap (java.util.HashMap)5 Random (java.util.Random)5 Direction (net.minecraft.util.math.Direction)5