Search in sources :

Example 6 with VoxelShape

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

the class MancubusEntity 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.mancubus_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 7 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project Blockus by Brandcraf06.

the class Barrier method getShapeMap.

private Map<BlockState, VoxelShape> getShapeMap(float f, float g, float h, float i, float j, float k) {
    float l = 8.0F - f;
    float m = 8.0F + f;
    float n = 8.0F - g;
    float o = 8.0F + g;
    VoxelShape voxelShape = Block.createCuboidShape(l, 0.0D, l, m, h, m);
    VoxelShape voxelShape2 = Block.createCuboidShape(n, i, 0.0D, o, j, o);
    VoxelShape voxelShape3 = Block.createCuboidShape(n, i, n, o, j, 16.0D);
    VoxelShape voxelShape4 = Block.createCuboidShape(0.0D, i, n, o, j, o);
    VoxelShape voxelShape5 = Block.createCuboidShape(n, i, n, 16.0D, j, o);
    VoxelShape voxelShape6 = Block.createCuboidShape(n, i, 0.0D, o, k, o);
    VoxelShape voxelShape7 = Block.createCuboidShape(n, i, n, o, k, 16.0D);
    VoxelShape voxelShape8 = Block.createCuboidShape(0.0D, i, n, o, k, o);
    VoxelShape voxelShape9 = Block.createCuboidShape(n, i, n, 16.0D, k, o);
    Builder<BlockState, VoxelShape> builder = ImmutableMap.builder();
    Iterator var21 = UP.getValues().iterator();
    while (var21.hasNext()) {
        Boolean boolean_ = (Boolean) var21.next();
        Iterator var23 = EAST_SHAPE.getValues().iterator();
        while (var23.hasNext()) {
            WallShape wallShape = (WallShape) var23.next();
            Iterator var25 = NORTH_SHAPE.getValues().iterator();
            while (var25.hasNext()) {
                WallShape wallShape2 = (WallShape) var25.next();
                Iterator var27 = WEST_SHAPE.getValues().iterator();
                while (var27.hasNext()) {
                    WallShape wallShape3 = (WallShape) var27.next();
                    Iterator var29 = SOUTH_SHAPE.getValues().iterator();
                    while (var29.hasNext()) {
                        WallShape wallShape4 = (WallShape) var29.next();
                        VoxelShape voxelShape10 = VoxelShapes.empty();
                        voxelShape10 = method_24426(voxelShape10, wallShape, voxelShape5, voxelShape9);
                        voxelShape10 = method_24426(voxelShape10, wallShape3, voxelShape4, voxelShape8);
                        voxelShape10 = method_24426(voxelShape10, wallShape2, voxelShape2, voxelShape6);
                        voxelShape10 = method_24426(voxelShape10, wallShape4, voxelShape3, voxelShape7);
                        if (boolean_) {
                            voxelShape10 = VoxelShapes.union(voxelShape10, voxelShape);
                        }
                        BlockState blockState = this.getDefaultState().with(UP, boolean_).with(EAST_SHAPE, wallShape).with(WEST_SHAPE, wallShape3).with(NORTH_SHAPE, wallShape2).with(SOUTH_SHAPE, wallShape4);
                        builder.put(blockState.with(WATERLOGGED, false), voxelShape10);
                        builder.put(blockState.with(WATERLOGGED, true), voxelShape10);
                    }
                }
            }
        }
    }
    return builder.build();
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) WallShape(net.minecraft.block.enums.WallShape) Iterator(java.util.Iterator)

Example 8 with VoxelShape

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

the class LithiumEntityCollisions method getBlockCollisions.

/**
 * [VanillaCopy] CollisionView#getBlockCollisions(Entity, Box)
 * This is a much, much faster implementation which uses simple collision testing against full-cube block shapes.
 * Checks against the world border are replaced with our own optimized functions which do not go through the
 * VoxelShape system.
 */
public static List<VoxelShape> getBlockCollisions(CollisionView world, Entity entity, Box box) {
    ArrayList<VoxelShape> shapes = new ArrayList<>();
    ChunkAwareBlockCollisionSweeper sweeper = new ChunkAwareBlockCollisionSweeper(world, entity, box);
    while (sweeper.hasNext()) {
        shapes.add(sweeper.next());
    }
    return shapes;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) ArrayList(java.util.ArrayList) ChunkAwareBlockCollisionSweeper(me.jellysquid.mods.lithium.common.entity.movement.ChunkAwareBlockCollisionSweeper)

Example 9 with VoxelShape

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

the class LithiumEntityCollisions method getEntityWorldBorderCollisionIterable.

/**
 * [VanillaCopy] EntityView#getEntityCollisions
 * Re-implements the function named above without stream code or unnecessary allocations. This can provide a small
 * boost in some situations (such as heavy entity crowding) and reduces the allocation rate significantly.
 */
public static Iterable<VoxelShape> getEntityWorldBorderCollisionIterable(EntityView view, Entity entity, Box box, boolean includeWorldBorder) {
    assert !includeWorldBorder || entity != null;
    return new Iterable<>() {

        private List<Entity> entityList;

        private int nextFilterIndex;

        @NotNull
        @Override
        public Iterator<VoxelShape> iterator() {
            return new AbstractIterator<>() {

                int index = 0;

                boolean consumedWorldBorder = false;

                @Override
                protected VoxelShape computeNext() {
                    // Initialize list that is shared between multiple iterators as late as possible
                    if (entityList == null) {
                        /*
                             * In case entity's class is overriding Entity#collidesWith(Entity), all types of entities may be (=> are assumed to be) required.
                             * Otherwise only get entities that override Entity#isCollidable(), as other entities cannot collide.
                             */
                        entityList = WorldHelper.getEntitiesForCollision(view, box, entity);
                        nextFilterIndex = 0;
                    }
                    List<Entity> list = entityList;
                    Entity otherEntity;
                    do {
                        if (this.index >= list.size()) {
                            // get the world border at the end
                            if (includeWorldBorder && !this.consumedWorldBorder) {
                                this.consumedWorldBorder = true;
                                WorldBorder worldBorder = entity.world.getWorldBorder();
                                if (!isWithinWorldBorder(worldBorder, box) && isWithinWorldBorder(worldBorder, entity.getBoundingBox())) {
                                    return worldBorder.asVoxelShape();
                                }
                            }
                            return this.endOfData();
                        }
                        otherEntity = list.get(this.index);
                        if (this.index >= nextFilterIndex) {
                            /*
                                 * {@link Entity#isCollidable()} returns false by default, designed to be overridden by
                                 * entities whose collisions should be "hard" (boats and shulkers, for now).
                                 *
                                 * {@link Entity#collidesWith(Entity)} only allows hard collisions if the calling entity is not riding
                                 * otherEntity as a vehicle.
                                 */
                            if (entity == null) {
                                if (!otherEntity.isCollidable()) {
                                    otherEntity = null;
                                }
                            } else if (!entity.collidesWith(otherEntity)) {
                                otherEntity = null;
                            }
                            nextFilterIndex++;
                        }
                        this.index++;
                    } while (otherEntity == null);
                    return VoxelShapes.cuboid(otherEntity.getBoundingBox());
                }
            };
        }
    };
}
Also used : Entity(net.minecraft.entity.Entity) VoxelShape(net.minecraft.util.shape.VoxelShape) WorldBorder(net.minecraft.world.border.WorldBorder) ArrayList(java.util.ArrayList) List(java.util.List) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 10 with VoxelShape

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

the class ChunkAwareBlockCollisionSweeper method computeNext.

/**
 * Advances the sweep forward until finding a block with a box-colliding VoxelShape
 *
 * @return null if no VoxelShape is left in the area, otherwise the next VoxelShape
 */
@Override
public VoxelShape computeNext() {
    while (true) {
        if (this.cIterated >= this.cTotalSize) {
            if (!this.nextSection()) {
                break;
            }
        }
        this.cIterated++;
        final int x = this.cX;
        final int y = this.cY;
        final int z = this.cZ;
        // Linearly accessing arrays is faster than other access patterns.
        if (this.cX < this.cEndX) {
            this.cX++;
        } else if (this.cZ < this.cEndZ) {
            this.cX = this.cStartX;
            this.cZ++;
        } else {
            this.cX = this.cStartX;
            this.cZ = this.cStartZ;
            this.cY++;
        // stop condition was already checked using this.cIterated at the start of the method
        }
        // using < minX and > maxX instead of <= and >= in vanilla, because minX, maxX are the coordinates
        // of the box that wasn't extended for oversized blocks yet.
        final int edgesHit = this.sectionOversizedBlocks ? (x < this.minX || x > this.maxX ? 1 : 0) + (y < this.minY || y > this.maxY ? 1 : 0) + (z < this.minZ || z > this.maxZ ? 1 : 0) : 0;
        if (edgesHit == 3) {
            continue;
        }
        final BlockState state = this.cachedChunkSection.getBlockState(x & 15, y & 15, z & 15);
        if (!canInteractWithBlock(state, edgesHit)) {
            continue;
        }
        this.pos.set(x, y, z);
        VoxelShape collisionShape = state.getCollisionShape(this.view, this.pos, this.context);
        if (collisionShape != VoxelShapes.empty()) {
            VoxelShape collidedShape = getCollidedShape(this.box, this.shape, collisionShape, x, y, z);
            if (collidedShape != null) {
                return collidedShape;
            }
        }
    }
    return this.endOfData();
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape)

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