Search in sources :

Example 1 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project roadrunner by MaxNeedsSnacks.

the class SideShapeTypeCache method isSupporting.

public static boolean isSupporting(SideShapeType supportType, BlockState state, Direction direction) {
    ThreadState threadState = threadLocalState.get();
    VoxelShape shape = threadState.getShape(state);
    ShapeResultCache specificCache = threadState.cachedResults.computeIfAbsent(shape, $ -> new ShapeResultCache());
    return specificCache.getOrCompute(shape, direction, supportType);
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape)

Example 2 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project roadrunner by MaxNeedsSnacks.

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", 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 voxelShape2, Direction direction, BlockState blockState2, float f) {
    if (this.extending || !this.source) {
        // here voxelShape2.isEmpty() is guaranteed, vanilla code would call union() which calls simplify()
        VoxelShape blockShape = blockState2.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) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project MCDoom by AzureDoom.

the class ArchvileEntity method conjureFangs.

private void conjureFangs(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 = this.world.getBlockState(blockPos2);
        if (blockState.isSideSolidFullSquare(this.world, blockPos2, Direction.UP)) {
            if (!this.world.isAir(blockPos)) {
                BlockState blockState2 = this.world.getBlockState(blockPos);
                VoxelShape voxelShape = blockState2.getCollisionShape(this.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) {
        DoomFireEntity fang = new DoomFireEntity(this.world, x, (double) blockPos.getY() + d, z, yaw, warmup, this, config.archvile_ranged_damage);
        fang.setFireTicks(age);
        fang.isInvisible();
        this.world.spawnEntity(fang);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) DoomFireEntity(mod.azure.doom.entity.projectiles.entity.DoomFireEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project MCDoom by AzureDoom.

the class SummonerEntity method conjureFangs.

private void conjureFangs(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 = this.world.getBlockState(blockPos2);
        if (blockState.isSideSolidFullSquare(this.world, blockPos2, Direction.UP)) {
            if (!this.world.isAir(blockPos)) {
                BlockState blockState2 = this.world.getBlockState(blockPos);
                VoxelShape voxelShape = blockState2.getCollisionShape(this.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) {
        DoomFireEntity fang = new DoomFireEntity(this.world, x, (double) blockPos.getY() + d, z, yaw, warmup, this, config.summoner_ranged_damage);
        fang.setFireTicks(age);
        fang.isInvisible();
        this.world.spawnEntity(fang);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) DoomFireEntity(mod.azure.doom.entity.projectiles.entity.DoomFireEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project MCDoom by AzureDoom.

the class IconofsinEntity method spawnFlames.

public void spawnFlames(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.75D;
    do {
        BlockPos blockPos2 = blockPos.down();
        BlockState blockState = this.world.getBlockState(blockPos2);
        if (blockState.isSideSolidFullSquare(this.world, blockPos2, Direction.UP)) {
            if (!this.world.isAir(blockPos)) {
                BlockState blockState2 = this.world.getBlockState(blockPos);
                VoxelShape voxelShape = blockState2.getCollisionShape(this.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) {
        DoomFireEntity fang = new DoomFireEntity(this.world, x, (double) blockPos.getY() + d, z, yaw, warmup, this, config.icon_melee_damage);
        fang.setFireTicks(age);
        fang.isInvisible();
        fang.age = -150;
        this.world.spawnEntity(fang);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) DoomFireEntity(mod.azure.doom.entity.projectiles.entity.DoomFireEntity) BlockPos(net.minecraft.util.math.BlockPos)

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