Search in sources :

Example 26 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project Client by MatHax.

the class ItemPhysics method onRenderItemEntity.

@EventHandler
private void onRenderItemEntity(RenderItemEntityEvent event) {
    ItemStack itemStack = event.itemEntity.getStack();
    int seed = itemStack.isEmpty() ? 187 : Item.getRawId(itemStack.getItem()) + itemStack.getDamage();
    event.random.setSeed(seed);
    event.matrixStack.push();
    // TODO: Test
    BakedModel bakedModel = event.itemRenderer.getModel(itemStack, event.itemEntity.world, null, 0);
    boolean hasDepthInGui = bakedModel.hasDepth();
    int renderCount = getRenderedAmount(itemStack);
    IItemEntity rotator = (IItemEntity) event.itemEntity;
    boolean renderBlockFlat = false;
    if (event.itemEntity.getStack().getItem() instanceof BlockItem && !(event.itemEntity.getStack().getItem() instanceof AliasedBlockItem)) {
        Block block = ((BlockItem) event.itemEntity.getStack().getItem()).getBlock();
        VoxelShape shape = block.getOutlineShape(block.getDefaultState(), event.itemEntity.world, event.itemEntity.getBlockPos(), ShapeContext.absent());
        if (shape.getMax(Direction.Axis.Y) <= .5)
            renderBlockFlat = true;
    }
    Item item = event.itemEntity.getStack().getItem();
    if (item instanceof BlockItem && !(item instanceof AliasedBlockItem) && !renderBlockFlat)
        event.matrixStack.translate(0, -0.06, 0);
    if (!renderBlockFlat) {
        event.matrixStack.translate(0, .185, .0);
        event.matrixStack.multiply(Vec3f.POSITIVE_X.getRadialQuaternion(1.571F));
        event.matrixStack.translate(0, -.185, -.0);
    }
    boolean isAboveWater = event.itemEntity.world.getBlockState(event.itemEntity.getBlockPos()).getFluidState().getFluid().isIn(FluidTags.WATER);
    if (!event.itemEntity.isOnGround() && (!event.itemEntity.isSubmergedInWater() && !isAboveWater)) {
        // Calculate rotation based on age and ticks
        float rotation = ((float) event.itemEntity.getItemAge() + event.tickDelta) / 20.0F + event.itemEntity.uniqueOffset;
        if (!renderBlockFlat) {
            event.matrixStack.translate(0, .185, .0);
            event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion(rotation));
            event.matrixStack.translate(0, -.185, .0);
            rotator.setRotation(new Vec3d(0, 0, rotation));
        } else {
            event.matrixStack.multiply(Vec3f.POSITIVE_Y.getRadialQuaternion(rotation));
            rotator.setRotation(new Vec3d(0, rotation, 0));
            event.matrixStack.translate(0, -.065, 0);
        }
        if (event.itemEntity.getStack().getItem() instanceof AliasedBlockItem)
            event.matrixStack.translate(0, 0, .195);
        else if (!(event.itemEntity.getStack().getItem() instanceof BlockItem))
            event.matrixStack.translate(0, 0, .195);
    } else if (event.itemEntity.getStack().getItem() instanceof AliasedBlockItem) {
        event.matrixStack.translate(0, .185, .0);
        event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion((float) rotator.getRotation().z));
        event.matrixStack.translate(0, -.185, .0);
        event.matrixStack.translate(0, 0, .195);
    } else if (renderBlockFlat) {
        event.matrixStack.multiply(Vec3f.POSITIVE_Y.getRadialQuaternion((float) rotator.getRotation().y));
        event.matrixStack.translate(0, -.065, 0);
    } else {
        if (!(event.itemEntity.getStack().getItem() instanceof BlockItem))
            event.matrixStack.translate(0, 0, .195);
        event.matrixStack.translate(0, .185, .0);
        event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion((float) rotator.getRotation().z));
        event.matrixStack.translate(0, -.185, .0);
    }
    if (event.itemEntity.world.getBlockState(event.itemEntity.getBlockPos()).getBlock().equals(Blocks.SOUL_SAND))
        event.matrixStack.translate(0, 0, -.1);
    if (event.itemEntity.getStack().getItem() instanceof BlockItem && ((BlockItem) event.itemEntity.getStack().getItem()).getBlock() instanceof SkullBlock)
        event.matrixStack.translate(0, .11, 0);
    float scaleX = bakedModel.getTransformation().ground.scale.getX();
    float scaleY = bakedModel.getTransformation().ground.scale.getY();
    float scaleZ = bakedModel.getTransformation().ground.scale.getZ();
    float x;
    float y;
    if (!hasDepthInGui) {
        float r = -0.0F * (float) (renderCount) * 0.5F * scaleX;
        x = -0.0F * (float) (renderCount) * 0.5F * scaleY;
        y = -0.09375F * (float) (renderCount) * 0.5F * scaleZ;
        event.matrixStack.translate(r, x, y);
    }
    for (int u = 0; u < renderCount; ++u) {
        event.matrixStack.push();
        if (u > 0) {
            if (hasDepthInGui) {
                x = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
                y = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
                float z = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
                event.matrixStack.translate(x, y, z);
            } else {
                x = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F;
                y = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F;
                event.matrixStack.translate(x, y, 0.0D);
                event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion(event.random.nextFloat()));
            }
        }
        event.itemRenderer.renderItem(itemStack, ModelTransformation.Mode.GROUND, false, event.matrixStack, event.vertexConsumerProvider, event.light, OverlayTexture.DEFAULT_UV, bakedModel);
        event.matrixStack.pop();
        if (!hasDepthInGui)
            event.matrixStack.translate(0.0F * scaleX, 0.0F * scaleY, 0.0625F * scaleZ);
    }
    event.matrixStack.pop();
    // mc.getEntityRenderDispatcher().getRenderer(event.itemEntity).render(event.itemEntity, event.f, event.tickDelta, event.matrixStack, event.vertexConsumerProvider, event.light);
    event.setCancelled(true);
}
Also used : SkullBlock(net.minecraft.block.SkullBlock) Vec3d(net.minecraft.util.math.Vec3d) VoxelShape(net.minecraft.util.shape.VoxelShape) IItemEntity(mathax.client.mixininterface.IItemEntity) BakedModel(net.minecraft.client.render.model.BakedModel) SkullBlock(net.minecraft.block.SkullBlock) Block(net.minecraft.block.Block) EventHandler(mathax.client.eventbus.EventHandler)

Example 27 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project Client by MatHax.

the class BreakIndicators method renderNormal.

private void renderNormal(Render3DEvent event) {
    Map<Integer, BlockBreakingInfo> blocks = ((WorldRendererAccessor) mc.worldRenderer).getBlockBreakingInfos();
    float ownBreakingStage = ((ClientPlayerInteractionManagerAccessor) mc.interactionManager).getBreakingProgress();
    BlockPos ownBreakingPos = ((ClientPlayerInteractionManagerAccessor) mc.interactionManager).getCurrentBreakingBlockPos();
    if (ownBreakingPos != null && mc.interactionManager.isBreakingBlock()) {
        BlockState state = mc.world.getBlockState(ownBreakingPos);
        VoxelShape shape = state.getOutlineShape(mc.world, ownBreakingPos);
        if (shape.isEmpty() || shape == null)
            return;
        Box orig = shape.getBoundingBox();
        Box box = orig;
        double shrinkFactor = 1d - ownBreakingStage;
        double progress = 1d - shrinkFactor;
        renderBlock(event, box, orig, ownBreakingPos, shrinkFactor, progress);
    }
    blocks.values().forEach(info -> {
        BlockPos pos = info.getPos();
        int stage = info.getStage();
        if (pos.equals(ownBreakingPos))
            return;
        BlockState state = mc.world.getBlockState(pos);
        VoxelShape shape = state.getOutlineShape(mc.world, pos);
        if (shape.isEmpty())
            return;
        Box orig = shape.getBoundingBox();
        Box box = orig;
        double shrinkFactor = (9 - (stage + 1)) / 9d;
        double progress = 1d - shrinkFactor;
        renderBlock(event, box, orig, pos, shrinkFactor, progress);
    });
}
Also used : WorldRendererAccessor(mathax.client.mixin.WorldRendererAccessor) ClientPlayerInteractionManagerAccessor(mathax.client.mixin.ClientPlayerInteractionManagerAccessor) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) BlockBreakingInfo(net.minecraft.client.render.BlockBreakingInfo) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box)

Example 28 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project Client by MatHax.

the class BreakIndicators method renderPacket.

private void renderPacket(Render3DEvent event, List<PacketMine.MyBlock> blocks) {
    for (PacketMine.MyBlock block : blocks) {
        if (block.mining && block.progress != Double.POSITIVE_INFINITY) {
            VoxelShape shape = block.blockState.getOutlineShape(mc.world, block.blockPos);
            if (shape.isEmpty())
                return;
            Box orig = shape.getBoundingBox();
            Box box = orig;
            double progressNormalised = block.progress > 1 ? 1 : block.progress;
            double shrinkFactor = 1d - progressNormalised;
            BlockPos pos = block.blockPos;
            renderBlock(event, box, orig, pos, shrinkFactor, progressNormalised);
        }
    }
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) PacketMine(mathax.client.systems.modules.world.PacketMine) Box(net.minecraft.util.math.Box) BlockPos(net.minecraft.util.math.BlockPos)

Example 29 with VoxelShape

use of net.minecraft.util.shape.VoxelShape in project wildmod by Osmiooo.

the class MangroveBoatEntity method method_7548.

public float method_7548() {
    Box box = this.getBoundingBox();
    Box box2 = new Box(box.minX, box.minY - 0.001D, box.minZ, box.maxX, box.minY, box.maxZ);
    int i = MathHelper.floor(box2.minX) - 1;
    int j = MathHelper.ceil(box2.maxX) + 1;
    int k = MathHelper.floor(box2.minY) - 1;
    int l = MathHelper.ceil(box2.maxY) + 1;
    int m = MathHelper.floor(box2.minZ) - 1;
    int n = MathHelper.ceil(box2.maxZ) + 1;
    VoxelShape voxelShape = VoxelShapes.cuboid(box2);
    float f = 0.0F;
    int o = 0;
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    for (int p = i; p < j; ++p) {
        for (int q = m; q < n; ++q) {
            int r = (p != i && p != j - 1 ? 0 : 1) + (q != m && q != n - 1 ? 0 : 1);
            if (r != 2) {
                for (int s = k; s < l; ++s) {
                    if (r <= 0 || s != k && s != l - 1) {
                        mutable.set(p, s, q);
                        BlockState blockState = this.world.getBlockState(mutable);
                        if (!(blockState.getBlock() instanceof LilyPadBlock) && VoxelShapes.matchesAnywhere(blockState.getCollisionShape(this.world, mutable).offset((double) p, (double) s, (double) q), voxelShape, BooleanBiFunction.AND)) {
                            f += blockState.getBlock().getSlipperiness();
                            ++o;
                        }
                    }
                }
            }
        }
    }
    return f / (float) o;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) BlockState(net.minecraft.block.BlockState) LilyPadBlock(net.minecraft.block.LilyPadBlock)

Example 30 with VoxelShape

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

the class BlockOcclusionCache method shouldDrawSide.

public boolean shouldDrawSide(BlockState state, BlockView view, BlockPos pos, Direction facing) {
    BlockPos adjPos = this.cpos.set(pos).setOffset(facing);
    BlockState adjState = view.getBlockState(adjPos);
    if (state.isSideInvisible(adjState, facing)) {
        return false;
    }
    if (adjState.isOpaque()) {
        NeighborGroup cache = this.cache;
        cache.self = state;
        cache.other = adjState;
        cache.facing = facing;
        Object2ByteOpenHashMap<NeighborGroup> map = this.map;
        byte cached = map.getByte(cache);
        if (cached != 127) {
            return cached != 0;
        }
        VoxelShape selfShape = state.getCullingFace(view, pos, facing);
        VoxelShape adjShape = adjState.getCullingFace(view, adjPos, facing.getOpposite());
        boolean ret = VoxelShapes.matchesAnywhere(selfShape, adjShape, BooleanBiFunction.ONLY_FIRST);
        map.put(cache.copy(), (byte) (ret ? 1 : 0));
        return ret;
    }
    return true;
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos)

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