Search in sources :

Example 16 with Box

use of net.minecraft.util.math.Box in project lithium-fabric by CaffeineMC.

the class TestCustomVoxelShapesCollisions method testCollisions.

// @Test
public void testCollisions() {
    this.noCollision = 0;
    this.collision = 0;
    this.intersects = 0;
    this.intersectsCollision = 0;
    this.withCollisionBoxesInside = 0;
    this.rand = new Random();
    // insert your seed here for debugging when the test failed and printed its seed
    long seed = this.rand.nextLong();
    this.rand.setSeed(seed);
    this.randomSeed = seed;
    this.boxes = new Box[20];
    this.boxes[0] = new Box(0.2931994021407849, 0.5175531777466607, 0.14575020167685837, 1.4562191976519117, 2.2389429614133496, 0.31827209851790766);
    this.boxes[1] = new Box(0.5 - 0.5E-7, 0.75, 0.125 + 1E-7, 1, 1 + 1E-6, 0.5);
    for (int i = 2; i < 20; i++) {
        this.boxes[i] = getRandomBox(this.rand);
    }
    Random rand = this.rand;
    this.distances = new double[] { 2.814955055053852, 5 * rand.nextDouble(), -5 * rand.nextDouble(), 5 * rand.nextDouble(), -5 * rand.nextDouble(), 1E-7, 1.1E-7, 0.9E-7, -1E-7, -1.1E-7, -0.9E-7, 1, 10, -1, -10, 0.1, -0.1, 0.25, -0.25, 0.33, -0.33, 1 - 1E-7, -1 + 1E-7, 5 * rand.nextDouble(), -5 * rand.nextDouble(), 5 * rand.nextDouble(), -5 * rand.nextDouble() };
    // test all of the 1/8th of a block aligned shapes
    for (int x = 0; x <= 7; x++) {
        for (int x2 = x + 1; x2 <= 8; x2++) {
            for (int y = 0; y <= 7; y++) {
                for (int y2 = y + 1; y2 <= 8; y2++) {
                    for (int z = 0; z <= 7; z++) {
                        for (int z2 = z + 1; z2 <= 8; z2++) {
                            VoxelShape[] pair = getVanillaModdedVoxelShapePair(new Box(x / 8D, y / 8D, z / 8D, x2 / 8D, y2 / 8D, z2 / 8D));
                            this.testShapeBehaviorEquality(pair);
                            // test random offsetting to test VoxelShapeAlignedCuboid_Offset
                            double xOff = 5 * rand.nextGaussian();
                            double yOff = 4 * rand.nextDouble();
                            double zOff = rand.nextDouble();
                            pair[0] = pair[0].offset(xOff, yOff, zOff);
                            pair[1] = pair[1].offset(xOff, yOff, zOff);
                            this.testShapeBehaviorEquality(pair);
                            // test random EPSILON-sized deviations
                            pair = getVanillaModdedVoxelShapePair(new Box(x / 8D + 2E-7 * this.rand.nextDouble(), y / 8D + 4E-8, z / 8D, x2 / 8D, y2 / 8D + 9E-8, z2 / 8D));
                            this.testShapeBehaviorEquality(pair);
                        }
                    }
                }
            }
        }
    }
    // test some random shapes, just in case there is a really stupid mistake somewhere
    for (int i = 0; i < 2000; i++) {
        this.testShapeBehaviorEquality(getVanillaModdedVoxelShapePair(new Box(rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian())));
    }
}
Also used : Random(java.util.Random) Box(net.minecraft.util.math.Box)

Example 17 with Box

use of net.minecraft.util.math.Box in project lithium-fabric by CaffeineMC.

the class EntityMixin method lithiumCollideMultiAxisMovement.

private static Vec3d lithiumCollideMultiAxisMovement(@Nullable Entity entity, Vec3d movement, Box entityBoundingBox, World world, boolean getEntityCollisions) {
    // vanilla order: entities, worldborder, blocks. It is unknown whether changing this order changes the result regarding the confusing 1e-7 VoxelShape margin behavior. Not yet investigated
    double velX = movement.x;
    double velY = movement.y;
    double velZ = movement.z;
    boolean isVerticalOnly = velX == 0 && velZ == 0;
    Box movementSpace;
    if (isVerticalOnly) {
        if (velY < 0) {
            movementSpace = new Box(entityBoundingBox.minX, entityBoundingBox.minY + velY, entityBoundingBox.minZ, entityBoundingBox.maxX, entityBoundingBox.minY, entityBoundingBox.maxZ);
        } else {
            movementSpace = new Box(entityBoundingBox.minX, entityBoundingBox.maxY, entityBoundingBox.minZ, entityBoundingBox.maxX, entityBoundingBox.maxY + velY, entityBoundingBox.maxZ);
        }
    } else {
        movementSpace = entityBoundingBox.stretch(movement);
    }
    List<VoxelShape> blockCollisions = LithiumEntityCollisions.getBlockCollisions(world, entity, movementSpace);
    List<VoxelShape> entityWorldBorderCollisions = null;
    if (velY != 0.0) {
        velY = VoxelShapes.calculateMaxOffset(Direction.Axis.Y, entityBoundingBox, blockCollisions, velY);
        if (velY != 0.0) {
            if (getEntityCollisions) {
                entityWorldBorderCollisions = LithiumEntityCollisions.getEntityWorldBorderCollisions(world, entity, movementSpace, entity != null);
                velY = VoxelShapes.calculateMaxOffset(Direction.Axis.Y, entityBoundingBox, entityWorldBorderCollisions, velY);
            }
            if (velY != 0.0) {
                entityBoundingBox = entityBoundingBox.offset(0.0, velY, 0.0);
            }
        }
    }
    boolean velXSmallerVelZ = Math.abs(velX) < Math.abs(velZ);
    if (velXSmallerVelZ) {
        velZ = VoxelShapes.calculateMaxOffset(Direction.Axis.Z, entityBoundingBox, blockCollisions, velZ);
        if (velZ != 0.0) {
            if (entityWorldBorderCollisions == null && getEntityCollisions) {
                entityWorldBorderCollisions = LithiumEntityCollisions.getEntityWorldBorderCollisions(world, entity, movementSpace, entity != null);
            }
            if (getEntityCollisions) {
                velZ = VoxelShapes.calculateMaxOffset(Direction.Axis.Z, entityBoundingBox, entityWorldBorderCollisions, velZ);
            }
            if (velZ != 0.0) {
                entityBoundingBox = entityBoundingBox.offset(0.0, 0.0, velZ);
            }
        }
    }
    if (velX != 0.0) {
        velX = VoxelShapes.calculateMaxOffset(Direction.Axis.X, entityBoundingBox, blockCollisions, velX);
        if (velX != 0.0) {
            if (entityWorldBorderCollisions == null && getEntityCollisions) {
                entityWorldBorderCollisions = LithiumEntityCollisions.getEntityWorldBorderCollisions(world, entity, movementSpace, entity != null);
            }
            if (getEntityCollisions) {
                velX = VoxelShapes.calculateMaxOffset(Direction.Axis.X, entityBoundingBox, entityWorldBorderCollisions, velX);
            }
            if (velX != 0.0) {
                entityBoundingBox = entityBoundingBox.offset(velX, 0.0, 0.0);
            }
        }
    }
    if (!velXSmallerVelZ && velZ != 0.0) {
        velZ = VoxelShapes.calculateMaxOffset(Direction.Axis.Z, entityBoundingBox, blockCollisions, velZ);
        if (velZ != 0.0 && getEntityCollisions) {
            if (entityWorldBorderCollisions == null) {
                entityWorldBorderCollisions = LithiumEntityCollisions.getEntityWorldBorderCollisions(world, entity, movementSpace, entity != null);
            }
            velZ = VoxelShapes.calculateMaxOffset(Direction.Axis.Z, entityBoundingBox, entityWorldBorderCollisions, velZ);
        }
    }
    return new Vec3d(velX, velY, velZ);
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) Box(net.minecraft.util.math.Box) Vec3d(net.minecraft.util.math.Vec3d)

Example 18 with Box

use of net.minecraft.util.math.Box in project BleachHack by BleachDrinker420.

the class Search method onRender.

@BleachSubscribe
public void onRender(EventWorldRender.Post event) {
    int mode = getSetting(0).asMode().getMode();
    int i = 0;
    for (BlockPos pos : foundBlocks) {
        if (i > 3000)
            return;
        BlockState state = mc.world.getBlockState(pos);
        int[] color = getColorForBlock(state, pos);
        VoxelShape voxelShape = state.getOutlineShape(mc.world, pos);
        if (voxelShape.isEmpty()) {
            voxelShape = VoxelShapes.cuboid(0, 0, 0, 1, 1, 1);
        }
        if (mode == 0 || mode == 2) {
            int fillAlpha = (int) (getSetting(2).asSlider().getValue() * 255);
            for (Box box : voxelShape.getBoundingBoxes()) {
                Renderer.drawBoxFill(box.offset(pos), QuadColor.single(color[0], color[1], color[2], fillAlpha));
            }
        }
        if (mode == 0 || mode == 1) {
            float outlineWidth = getSetting(1).asSlider().getValueFloat();
            for (Box box : voxelShape.getBoundingBoxes()) {
                Renderer.drawBoxOutline(box.offset(pos), QuadColor.single(color[0], color[1], color[2], 255), outlineWidth);
            }
        }
        SettingToggle tracers = getSetting(3).asToggle();
        if (tracers.getState()) {
            // This is bad when bobbing is enabled!
            Vec3d lookVec = new Vec3d(0, 0, 75).rotateX(-(float) Math.toRadians(mc.gameRenderer.getCamera().getPitch())).rotateY(-(float) Math.toRadians(mc.gameRenderer.getCamera().getYaw())).add(mc.cameraEntity.getEyePos());
            Renderer.drawLine(lookVec.x, lookVec.y, lookVec.z, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, LineColor.single(color[0], color[1], color[2], (int) (tracers.getChild(1).asSlider().getValue() * 255)), tracers.getChild(0).asSlider().getValueFloat());
        }
        i++;
    }
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) SettingToggle(org.bleachhack.setting.module.SettingToggle) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box) Vec3d(net.minecraft.util.math.Vec3d) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 19 with Box

use of net.minecraft.util.math.Box in project BleachHack by BleachDrinker420.

the class Trajectories method onWorldRender.

@BleachSubscribe
public void onWorldRender(EventWorldRender.Post event) {
    int[] col = getSetting(6).asColor().getRGBArray();
    int opacity = (int) (getSetting(8).asSlider().getValueFloat() * 255);
    for (Triple<List<Vec3d>, Entity, BlockPos> t : poses) {
        if (t.getLeft().size() >= 2) {
            if (getSetting(0).asMode().getMode() == 0) {
                for (int i = 1; i < t.getLeft().size(); i++) {
                    Renderer.drawLine(t.getLeft().get(i - 1).x, t.getLeft().get(i - 1).y, t.getLeft().get(i - 1).z, t.getLeft().get(i).x, t.getLeft().get(i).y, t.getLeft().get(i).z, LineColor.single(col[0], col[1], col[2], opacity), getSetting(7).asSlider().getValueFloat());
                }
            } else {
                for (Vec3d v : t.getLeft()) {
                    Renderer.drawBoxFill(new Box(v, v).expand(0.08), QuadColor.single(col[0], col[1], col[2], opacity));
                }
            }
        }
        VoxelShape hitbox = t.getMiddle() != null ? VoxelShapes.cuboid(t.getMiddle().getBoundingBox()) : t.getRight() != null ? mc.world.getBlockState(t.getRight()).getCollisionShape(mc.world, t.getRight()).offset(t.getRight().getX(), t.getRight().getY(), t.getRight().getZ()) : null;
        Vec3d lastVec = !t.getLeft().isEmpty() ? t.getLeft().get(t.getLeft().size() - 1) : mc.player.getEyePos();
        if (hitbox != null) {
            Renderer.drawLine(lastVec.x + 0.25, lastVec.y, lastVec.z, lastVec.x - 0.25, lastVec.y, lastVec.z, LineColor.single(col[0], col[1], col[2], 255), 1.75f);
            Renderer.drawLine(lastVec.x, lastVec.y + 0.25, lastVec.z, lastVec.x, lastVec.y - 0.25, lastVec.z, LineColor.single(col[0], col[1], col[2], 255), 1.75f);
            Renderer.drawLine(lastVec.x, lastVec.y, lastVec.z + 0.25, lastVec.x, lastVec.y, lastVec.z - 0.25, LineColor.single(col[0], col[1], col[2], 255), 1.75f);
            for (Box box : hitbox.getBoundingBoxes()) {
                Renderer.drawBoxOutline(box, QuadColor.single(col[0], col[1], col[2], 190), 1f);
            }
        }
    }
}
Also used : PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) EggEntity(net.minecraft.entity.projectile.thrown.EggEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) EnderPearlEntity(net.minecraft.entity.projectile.thrown.EnderPearlEntity) VoxelShape(net.minecraft.util.shape.VoxelShape) ArrayList(java.util.ArrayList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box) Vec3d(net.minecraft.util.math.Vec3d) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 20 with Box

use of net.minecraft.util.math.Box in project BleachHack by BleachDrinker420.

the class StorageESP method onWorldRender.

@BleachSubscribe
public void onWorldRender(EventWorldRender.Post event) {
    if (getSetting(0).asMode().getMode() == 0) {
        // Manually render blockentities because of culling
        for (BlockEntity be : WorldUtils.getBlockEntities()) {
            int[] color = getColorForBlock(be);
            if (color != null) {
                BlockEntityRenderer<BlockEntity> renderer = mc.getBlockEntityRenderDispatcher().get(be);
                MatrixStack matrices = Renderer.matrixFrom(be.getPos().getX(), be.getPos().getY(), be.getPos().getZ());
                if (renderer != null) {
                    renderer.render(be, mc.getTickDelta(), matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()), LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV);
                } else {
                    BlockState state = be.getCachedState();
                    mc.getBlockRenderManager().getModelRenderer().renderFlat(mc.world, mc.getBlockRenderManager().getModel(state), state, be.getPos(), matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()).getBuffer(RenderLayers.getMovingBlockLayer(state)), false, new Random(), 0L, OverlayTexture.DEFAULT_UV);
                }
            }
        }
        colorVertexer.draw();
        shader.render();
        shader.drawFramebufferToMain("main");
    } else {
        float width = getSetting(2).asSlider().getValueFloat();
        int fill = getSetting(3).asSlider().getValueInt();
        for (Entity e : mc.world.getEntities()) {
            int[] color = getColorForEntity(e);
            Box box = e.getBoundingBox();
            if (e instanceof ItemFrameEntity && ((ItemFrameEntity) e).getHeldItemStack().getItem() == Items.FILLED_MAP) {
                Axis axis = e.getHorizontalFacing().getAxis();
                box = box.expand(axis == Axis.X ? 0 : 0.125, axis == Axis.Y ? 0 : 0.125, axis == Axis.Z ? 0 : 0.125);
            }
            if (color != null) {
                if (width != 0)
                    Renderer.drawBoxOutline(box, QuadColor.single(color[0], color[1], color[2], 255), width);
                if (fill != 0)
                    Renderer.drawBoxFill(box, QuadColor.single(color[0], color[1], color[2], fill));
            }
        }
        Set<BlockPos> skip = new HashSet<>();
        for (BlockEntity be : WorldUtils.getBlockEntities()) {
            if (skip.contains(be.getPos()))
                continue;
            int[] color = getColorForBlock(be);
            Box box = be.getCachedState().getOutlineShape(mc.world, be.getPos()).getBoundingBox().offset(be.getPos());
            Direction dir = getChestDirection(be);
            if (dir != null) {
                box = Boxes.stretch(box, dir, 0.94);
                skip.add(be.getPos().offset(dir));
            }
            if (color != null) {
                if (width != 0)
                    Renderer.drawBoxOutline(box, QuadColor.single(color[0], color[1], color[2], 255), width);
                if (fill != 0)
                    Renderer.drawBoxFill(box, QuadColor.single(color[0], color[1], color[2], fill));
            }
        }
    }
}
Also used : ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) FurnaceMinecartEntity(net.minecraft.entity.vehicle.FurnaceMinecartEntity) Entity(net.minecraft.entity.Entity) HopperMinecartEntity(net.minecraft.entity.vehicle.HopperMinecartEntity) ChestMinecartEntity(net.minecraft.entity.vehicle.ChestMinecartEntity) MatrixStack(net.minecraft.client.util.math.MatrixStack) Box(net.minecraft.util.math.Box) Direction(net.minecraft.util.math.Direction) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) BlockPos(net.minecraft.util.math.BlockPos) Axis(net.minecraft.util.math.Direction.Axis) HashSet(java.util.HashSet) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Aggregations

Box (net.minecraft.util.math.Box)150 Vec3d (net.minecraft.util.math.Vec3d)56 LivingEntity (net.minecraft.entity.LivingEntity)50 PlayerEntity (net.minecraft.entity.player.PlayerEntity)46 Entity (net.minecraft.entity.Entity)43 BlockPos (net.minecraft.util.math.BlockPos)43 PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)18 Direction (net.minecraft.util.math.Direction)18 List (java.util.List)15 VoxelShape (net.minecraft.util.shape.VoxelShape)14 BlockState (net.minecraft.block.BlockState)13 ItemStack (net.minecraft.item.ItemStack)12 ArrayList (java.util.ArrayList)11 Comparator (java.util.Comparator)11 World (net.minecraft.world.World)11 Random (java.util.Random)10 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)10 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)10 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)10 DemonEntity (mod.azure.doom.entity.DemonEntity)9