Jump to content

Recommended Posts

Posted

So I'm using the render method from BlockEntityRenderer (the class extends GeoBlockRenderer as the block is a geo model but the render method in BlockEntityRenderer works the same as the actuallyRender method used here) but I cant get more than one of the items in my block entity to load at once, the rendering itself works fine just need a pointer in how to get more than one to render at once. So if there's an item in slot one and an item in slot two for example they both render at the same time.

BlockEntityRenderer:

Spoiler


 

package com.derpz.nukaisles.client.renderer;

import com.derpz.nukaisles.block.custom.NukaColaMachineBlock;
import com.derpz.nukaisles.block.entity.NukaColaMachineBlockEntity;
import com.derpz.nukaisles.client.models.NukaColaMachineBlockModel;
import com.derpz.nukaisles.item.custom.NukaColaItem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.renderer.GeoBlockRenderer;

import java.util.Objects;


public class NukaColaMachineBlockEntityRenderer extends GeoBlockRenderer<NukaColaMachineBlockEntity> {
    public NukaColaMachineBlockEntityRenderer(BlockEntityRendererProvider.Context ignoredContext) {
        super(new NukaColaMachineBlockModel());
    }

    @Override
    public void actuallyRender(PoseStack pPoseStack, NukaColaMachineBlockEntity pBlockEntity, BakedGeoModel model, RenderType renderType, MultiBufferSource pBufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
        super.actuallyRender(pPoseStack, pBlockEntity, model, renderType, pBufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
        ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
        ItemStack itemStack = pBlockEntity.getRenderStack();
        if(itemStack.getItem() instanceof NukaColaItem) {
            pPoseStack.pushPose();
            //1st slot render
            if (pBlockEntity.itemHandler.getStackInSlot(1).getItem() instanceof NukaColaItem) {
                pPoseStack.translate(0.1f, 0.74f, 0.72f);
                pPoseStack.scale(0.24f, 0.24f, 0.24f);
                pPoseStack.mulPose(Axis.XP.rotationDegrees(90));
                pPoseStack.mulPose(Axis.YP.rotationDegrees(90));
                pPoseStack.mulPose(Axis.XN.rotationDegrees(-25));
            } else if (pBlockEntity.itemHandler.getStackInSlot(2).getItem() instanceof NukaColaItem) {
                pPoseStack.translate(0.13f, 0.74f, 0.75f);
                pPoseStack.scale(0.24f, 0.24f, 0.24f);
                pPoseStack.mulPose(Axis.XP.rotationDegrees(90));
                pPoseStack.mulPose(Axis.YP.rotationDegrees(90));
                pPoseStack.mulPose(Axis.XN.rotationDegrees(25));
            }

            switch (pBlockEntity.getBlockState().getValue(NukaColaMachineBlock.FACING)) {
                case NORTH -> pPoseStack.mulPose(Axis.ZP.rotationDegrees(0));
                case EAST -> pPoseStack.mulPose(Axis.ZP.rotationDegrees(90));
                case SOUTH -> pPoseStack.mulPose(Axis.ZP.rotationDegrees(180));
                case WEST -> pPoseStack.mulPose(Axis.ZP.rotationDegrees(270));
            }

            itemRenderer.m_269128_(itemStack, ItemDisplayContext.GUI, getLightLevel(Objects.requireNonNull(pBlockEntity.getLevel()),
                            pBlockEntity.getBlockPos()),
                    OverlayTexture.NO_OVERLAY, pPoseStack, pBufferSource, pBlockEntity.getLevel(), pBlockEntity.getRenderStack().getCount());
            pPoseStack.popPose();
        }
        /// TODO: 5/25/2023 Rendering all bottles
    }
    private int getLightLevel(Level level, BlockPos pos) {
        int bLight = level.getBrightness(LightLayer.BLOCK, pos);
        int sLight = level.getBrightness(LightLayer.SKY, pos);
        return LightTexture.pack(bLight, sLight);
    };
}

 

Methods called to from my actual BlockEntity class:
 

Spoiler
public ItemStack getRenderStack() {
        int stackWithItem = 0;

        for (int i = 1; i < itemHandler.getSlots(); i++) {
            if (!itemHandler.getStackInSlot(i).isEmpty()) {
                stackWithItem = i;
            }
        }

        if (!itemHandler.getStackInSlot(stackWithItem).isEmpty() && stackWithItem != 0) {
            return itemHandler.getStackInSlot(stackWithItem);
        }
        else {
            return itemHandler.getStackInSlot(1);
        }
    }

    public void setHandler(ItemStackHandler itemStackHandler) {
        for(int i = 0; i < itemStackHandler.getSlots(); i++) {
            itemHandler.setStackInSlot(i, itemStackHandler.getStackInSlot(i));
        }
    }

 

I apologize in advance if the solution to this is really obvious haven't been modding very long

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.