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;
}
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]);
}
}
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);
}
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));
}
}
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();
}
Aggregations