Search in sources :

Example 11 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project lithium-fabric by CaffeineMC.

the class PistonBlockEntityMixin method getOffsetAndSimplified.

/**
 * We cache the offset and simplified VoxelShapes that are otherwise constructed on every call of getCollisionShape.
 * For each offset direction and distance (6 directions, 2 distances each, and no direction with 0 distance) we
 * store the offset and simplified VoxelShapes in the original VoxelShape when they are accessed the first time.
 * We use safe publication, because both the Render and Server thread are using the cache.
 *
 * @param blockShape the original shape, must not be modified after passing it as an argument to this method
 * @param offset     the offset distance
 * @param direction  the offset direction
 * @return blockShape offset and simplified
 */
private static VoxelShape getOffsetAndSimplified(VoxelShape blockShape, float offset, Direction direction) {
    VoxelShape offsetSimplifiedShape = ((OffsetVoxelShapeCache) blockShape).getOffsetSimplifiedShape(offset, direction);
    if (offsetSimplifiedShape == null) {
        // create the offset shape and store it for later use
        offsetSimplifiedShape = blockShape.offset(direction.getOffsetX() * offset, direction.getOffsetY() * offset, direction.getOffsetZ() * offset).simplify();
        ((OffsetVoxelShapeCache) blockShape).setShape(offset, direction, offsetSimplifiedShape);
    }
    return offsetSimplifiedShape;
}
Also used : OffsetVoxelShapeCache(me.jellysquid.mods.lithium.common.shapes.OffsetVoxelShapeCache) VoxelShape(net.minecraft.util.shape.VoxelShape)

Example 12 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project lithium-fabric by CaffeineMC.

the class PistonBlockEntityMixin method precomputePistonBaseWithMovingHeadShapes.

/**
 * Precompute all 18 possible configurations for the merged piston base and head shape.
 *
 * @return The array of the merged VoxelShapes, indexed by {@link PistonBlockEntityMixin#getIndexForMergedShape(float, Direction)}
 */
private static VoxelShape[] precomputePistonBaseWithMovingHeadShapes() {
    float[] offsets = { 0f, 0.5f, 1f };
    Direction[] directions = Direction.values();
    VoxelShape[] mergedShapes = new VoxelShape[offsets.length * directions.length];
    for (Direction facing : directions) {
        VoxelShape baseShape = Blocks.PISTON.getDefaultState().with(PistonBlock.EXTENDED, true).with(PistonBlock.FACING, facing).getCollisionShape(null, null);
        for (float offset : offsets) {
            // this cache is only required for the merged piston head + base shape.
            // this shape is only used when !this.extending
            // here: isShort = this.extending != 1.0F - this.progress < 0.25F can be simplified to:
            // isShort = f < 0.25F , because f = getAmountExtended(this.progress) can be simplified to f == 1.0F - this.progress
            // therefore isShort is dependent on the offset:
            boolean isShort = offset < 0.25f;
            VoxelShape headShape = (Blocks.PISTON_HEAD.getDefaultState().with(PistonHeadBlock.FACING, facing)).with(PistonHeadBlock.SHORT, isShort).getCollisionShape(null, null);
            VoxelShape offsetHead = headShape.offset(facing.getOffsetX() * offset, facing.getOffsetY() * offset, facing.getOffsetZ() * offset);
            mergedShapes[getIndexForMergedShape(offset, facing)] = VoxelShapes.union(baseShape, offsetHead);
        }
    }
    return mergedShapes;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) Direction(net.minecraft.util.math.Direction)

Example 13 with VoxelShape

use of net.minecraft.util.shape.VoxelShape 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 14 with VoxelShape

use of net.minecraft.util.shape.VoxelShape 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 15 with VoxelShape

use of net.minecraft.util.shape.VoxelShape 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)

Aggregations

VoxelShape (net.minecraft.util.shape.VoxelShape)59 BlockState (net.minecraft.block.BlockState)22 BlockPos (net.minecraft.util.math.BlockPos)22 Box (net.minecraft.util.math.Box)13 Vec3d (net.minecraft.util.math.Vec3d)8 Direction (net.minecraft.util.math.Direction)7 DoomFireEntity (mod.azure.doom.entity.projectiles.entity.DoomFireEntity)6 ArrayList (java.util.ArrayList)4 ChunkAwareBlockCollisionSweeper (me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)4 EventHandler (mathax.client.eventbus.EventHandler)3 EventHandler (meteordevelopment.orbit.EventHandler)3 Block (net.minecraft.block.Block)3 EvokerFangsEntity (net.minecraft.entity.mob.EvokerFangsEntity)3 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 IMatrix4f (dev.hypnotic.utils.mixin.IMatrix4f)2 Color (java.awt.Color)2 Iterator (java.util.Iterator)2 List (java.util.List)2 OffsetVoxelShapeCache (me.jellysquid.mods.lithium.common.shapes.OffsetVoxelShapeCache)2