Search in sources :

Example 1 with IItemEntity

use of meteordevelopment.meteorclient.mixininterface.IItemEntity in project meteor-client by MeteorDevelopment.

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();
    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 b = ((BlockItem) event.itemEntity.getStack().getItem()).getBlock();
        VoxelShape shape = b.getOutlineShape(b.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) {
        if (((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();
    event.setCancelled(true);
}
Also used : SkullBlock(net.minecraft.block.SkullBlock) AliasedBlockItem(net.minecraft.item.AliasedBlockItem) AliasedBlockItem(net.minecraft.item.AliasedBlockItem) BlockItem(net.minecraft.item.BlockItem) Vec3d(net.minecraft.util.math.Vec3d) Item(net.minecraft.item.Item) AliasedBlockItem(net.minecraft.item.AliasedBlockItem) BlockItem(net.minecraft.item.BlockItem) VoxelShape(net.minecraft.util.shape.VoxelShape) IItemEntity(meteordevelopment.meteorclient.mixininterface.IItemEntity) BakedModel(net.minecraft.client.render.model.BakedModel) SkullBlock(net.minecraft.block.SkullBlock) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) EventHandler(meteordevelopment.orbit.EventHandler)

Aggregations

IItemEntity (meteordevelopment.meteorclient.mixininterface.IItemEntity)1 EventHandler (meteordevelopment.orbit.EventHandler)1 Block (net.minecraft.block.Block)1 SkullBlock (net.minecraft.block.SkullBlock)1 BakedModel (net.minecraft.client.render.model.BakedModel)1 AliasedBlockItem (net.minecraft.item.AliasedBlockItem)1 BlockItem (net.minecraft.item.BlockItem)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 Vec3d (net.minecraft.util.math.Vec3d)1 VoxelShape (net.minecraft.util.shape.VoxelShape)1