Search in sources :

Example 56 with VoxelShape

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

the class EntityMixin method isInsideWall.

/**
 * @author 2No2Name
 * @reason Avoid stream code, use optimized chunk section iteration order
 */
@Overwrite
public boolean isInsideWall() {
    // [VanillaCopy] The whole method functionality including bug below. Cannot use ChunkAwareBlockCollisionSweeper due to special bug behavior and ignoring of oversized blocks
    if (this.noClip) {
        return false;
    }
    Vec3d eyePos = this.getEyePos();
    double suffocationRadius = Math.abs((double) (this.dimensions.width * 0.8f) / 2.0);
    BlockPos incorrectSuffocationPos = new BlockPos(eyePos);
    double suffocationMinX = eyePos.x - suffocationRadius;
    double suffocationMinY = eyePos.y - 5.0E-7;
    double suffocationMinZ = eyePos.z - suffocationRadius;
    double suffocationMaxX = eyePos.x + suffocationRadius;
    double suffocationMaxY = eyePos.y + 5.0E-7;
    double suffocationMaxZ = eyePos.z + suffocationRadius;
    int minX = MathHelper.floor(suffocationMinX);
    int minY = MathHelper.floor(suffocationMinY);
    int minZ = MathHelper.floor(suffocationMinZ);
    int maxX = MathHelper.floor(suffocationMaxX);
    int maxY = MathHelper.floor(suffocationMaxY);
    int maxZ = MathHelper.floor(suffocationMaxZ);
    World world = this.world;
    BlockPos.Mutable blockPos = new BlockPos.Mutable();
    VoxelShape suffocationShape = null;
    for (int y = minY; y <= maxY; y++) {
        for (int z = minZ; z <= maxZ; z++) {
            for (int x = minX; x <= maxX; x++) {
                blockPos.set(x, y, z);
                BlockState blockState = world.getBlockState(blockPos);
                // [VanillaCopy] https://bugs.mojang.com/browse/MC-242543 (incorrectly marked as cannot reproduce)
                if (!blockState.isAir() && blockState.shouldSuffocate(this.world, incorrectSuffocationPos)) {
                    if (suffocationShape == null) {
                        suffocationShape = VoxelShapes.cuboid(new Box(suffocationMinX, suffocationMinY, suffocationMinZ, suffocationMaxX, suffocationMaxY, suffocationMaxZ));
                    }
                    if (VoxelShapes.matchesAnywhere(blockState.getCollisionShape(this.world, incorrectSuffocationPos).offset(eyePos.x, eyePos.y, // [VanillaCopy] This is broken. Should be offset by blockPos. But vanilla does it like this. Causes https://bugs.mojang.com/browse/MC-245416
                    eyePos.z), suffocationShape, BooleanBiFunction.AND)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 57 with VoxelShape

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

the class PistonBlockEntityMixin method skipVoxelShapeUnion.

/**
 * Avoid calling {@link VoxelShapes#union(VoxelShape, VoxelShape)} whenever possible - use precomputed merged piston head + base shapes and
 * cache the results for all union calls with an empty shape as first argument. (these are all other cases)
 */
@Inject(method = "getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/shape/VoxelShape;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;getOffsetX()I", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void skipVoxelShapeUnion(BlockView world, BlockPos pos, CallbackInfoReturnable<VoxelShape> cir, VoxelShape voxelShape, Direction direction, BlockState blockState, float f) {
    if (this.extending || !this.source || !(this.pushedBlock.getBlock() instanceof PistonBlock)) {
        // here voxelShape2.isEmpty() is guaranteed, vanilla code would call union() which calls simplify()
        VoxelShape blockShape = blockState.getCollisionShape(world, pos);
        // we cache the simplified shapes, as the simplify() method costs a lot of CPU time and allocates several objects
        VoxelShape offsetAndSimplified = getOffsetAndSimplified(blockShape, Math.abs(f), f < 0f ? this.facing.getOpposite() : this.facing);
        cir.setReturnValue(offsetAndSimplified);
    } else {
        // retracting piston heads have to act like their base as well, as the base block is replaced with the moving block
        // f >= 0f is guaranteed (assuming no other mod interferes)
        int index = getIndexForMergedShape(f, this.facing);
        cir.setReturnValue(PISTON_BASE_WITH_MOVING_HEAD_SHAPES[index]);
    }
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) PistonBlock(net.minecraft.block.PistonBlock) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 58 with VoxelShape

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

the class TestOptimizedVoxelShapeMatchesAnywhere method getRandomTestWithComplexShape.

private static VoxelShapeVoxelShapePair getRandomTestWithComplexShape(Random random) {
    VoxelShape complexShape = Util.getRandom(TESTED_COMPLEX_SHAPES, random);
    if (random.nextInt(8) > 1) {
        complexShape = complexShape.offset(getFuzzy(random.nextInt(5) - 2, random, 0, 0.25f, 0.5f, 0f), getFuzzy(random.nextInt(5) - 2, random, 0, 0.25f, 0.5f, 0f), getFuzzy(random.nextInt(5) - 2, random, 0, 0.25f, 0.5f, 0f));
    }
    double x = 0.5D * (complexShape.getMin(Direction.Axis.X) + complexShape.getMax(Direction.Axis.X));
    double y = 0.5D * (complexShape.getMin(Direction.Axis.Y) + complexShape.getMax(Direction.Axis.Y));
    double z = 0.5D * (complexShape.getMin(Direction.Axis.Z) + complexShape.getMax(Direction.Axis.Z));
    double xRadius = 0.5D * (complexShape.getMax(Direction.Axis.X) - complexShape.getMin(Direction.Axis.X));
    double yRadius = 0.5D * (complexShape.getMax(Direction.Axis.Y) - complexShape.getMin(Direction.Axis.Y));
    double zRadius = 0.5D * (complexShape.getMax(Direction.Axis.Z) - complexShape.getMin(Direction.Axis.Z));
    double xRadius2 = random.nextInt(3) + random.nextDouble() - 0.01;
    double yRadius2 = random.nextInt(3) + random.nextDouble() - 0.01;
    double zRadius2 = random.nextInt(3) + random.nextDouble() - 0.01;
    Direction touchSide = Direction.random(random);
    if (random.nextInt(8) > 0) {
        x += touchSide.getOffsetX() * (xRadius + xRadius2);
        y += touchSide.getOffsetY() * (yRadius + yRadius2);
        z += touchSide.getOffsetZ() * (zRadius + zRadius2);
    }
    x = getFuzzy(x, random, xRadius + xRadius2, 0.25f, 0.25f, 0.25f);
    y = getFuzzy(y, random, yRadius + yRadius2, 0.25f, 0.25f, 0.25f);
    z = getFuzzy(z, random, zRadius + zRadius2, 0.25f, 0.25f, 0.25f);
    Box b = new Box(x - xRadius2, y - yRadius2, z - zRadius2, x + xRadius2, y + yRadius2, z + zRadius2);
    BooleanBiFunction function = Util.getRandom(FUNCTIONS, random);
    if (random.nextBoolean()) {
        return new VoxelShapeVoxelShapePair(complexShape, cuboid(b), function);
    }
    return new VoxelShapeVoxelShapePair(cuboid(b), complexShape, function);
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) BooleanBiFunction(net.minecraft.util.function.BooleanBiFunction) Box(net.minecraft.util.math.Box) Direction(net.minecraft.util.math.Direction) AxisCycleDirection(net.minecraft.util.math.AxisCycleDirection)

Example 59 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project Neutrino by FrostWizard4.

the class SummonEvokerFangs method conjureFangs.

private static void conjureFangs(Entity entity, double x, double z, double maxY, double y, float yaw, int warmup) {
    BlockPos blockPos = new BlockPos(x, y, z);
    boolean bl = false;
    double d = 0.0D;
    do {
        BlockPos blockPos2 = blockPos.down();
        BlockState blockState = entity.world.getBlockState(blockPos2);
        if (blockState.isSideSolidFullSquare(entity.world, blockPos2, Direction.UP)) {
            if (!entity.world.isAir(blockPos)) {
                BlockState blockState2 = entity.world.getBlockState(blockPos);
                VoxelShape voxelShape = blockState2.getCollisionShape(entity.world, blockPos);
                if (!voxelShape.isEmpty()) {
                    d = voxelShape.getMax(Direction.Axis.Y);
                }
            }
            bl = true;
            break;
        }
        blockPos = blockPos.down();
    } while (blockPos.getY() >= MathHelper.floor(maxY) - 1);
    if (bl) {
        entity.world.spawnEntity(new EvokerFangsEntity(entity.world, x, (double) blockPos.getY() + d, z, yaw, warmup, (LivingEntity) entity));
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos) EvokerFangsEntity(net.minecraft.entity.mob.EvokerFangsEntity)

Example 60 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project BleachHack by BleachDrinker420.

the class MixinBlockCollisionSpliterator method calculatePushVelocity_getCollisionShape.

@Redirect(method = "offerBlockShape", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"))
private VoxelShape calculatePushVelocity_getCollisionShape(BlockState blockState, BlockView world, BlockPos pos, ShapeContext context) {
    VoxelShape shape = blockState.getCollisionShape(world, pos, context);
    EventBlockShape event = new EventBlockShape((BlockState) blockState, pos, shape);
    BleachHack.eventBus.post(event);
    if (event.isCancelled()) {
        return VoxelShapes.empty();
    }
    return event.getShape();
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) EventBlockShape(org.bleachhack.event.events.EventBlockShape) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

VoxelShape (net.minecraft.util.shape.VoxelShape)62 BlockState (net.minecraft.block.BlockState)22 BlockPos (net.minecraft.util.math.BlockPos)22 Box (net.minecraft.util.math.Box)14 Vec3d (net.minecraft.util.math.Vec3d)10 Direction (net.minecraft.util.math.Direction)7 DoomFireEntity (mod.azure.doom.entity.projectiles.entity.DoomFireEntity)6 Inject (org.spongepowered.asm.mixin.injection.Inject)5 ArrayList (java.util.ArrayList)4 ChunkAwareBlockCollisionSweeper (me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)4 Entity (net.minecraft.entity.Entity)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