Jump to content

[1.17.1] Custom chests not rendering in inventory


Kitteh6660

Recommended Posts

Hello fellow modder, just thought I would like to ask as I have some issues.

You see, I have custom 3D block entity, namely custom chests. Basically just work the same as vanilla chests but with different textures. Problem is, they don't render in inventory even though they do render placed in world.

Putting the debug line reveals that it does output and fire but it won't render.

ModBEWLR.java

Spoiler
package kittehmod.morecraft.client;

import com.mojang.blaze3d.vertex.PoseStack;

import kittehmod.morecraft.MoreCraft;
import kittehmod.morecraft.block.ModBlocks;
import kittehmod.morecraft.blockentity.ModChestBlockEntity;
import kittehmod.morecraft.blockentity.ModTrappedChestBlockEntity;
import kittehmod.morecraft.item.ModItems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;

public class ModBEWLR extends BlockEntityWithoutLevelRenderer
{
	public static ModBEWLR INSTANCE = new ModBEWLR(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels());
	
	private final ModChestBlockEntity netherwood_chest = new ModChestBlockEntity(BlockPos.ZERO, ModBlocks.NETHERWOOD_CHEST.get().defaultBlockState());
	private final ModTrappedChestBlockEntity netherwood_trapped_chest = new ModTrappedChestBlockEntity(BlockPos.ZERO, ModBlocks.NETHERWOOD_CHEST_TRAPPED.get().defaultBlockState());
	private final BlockEntityRenderDispatcher blockEntityRenderDispatcher;

	
	public ModBEWLR(BlockEntityRenderDispatcher berd, EntityModelSet ems) {
		super(berd, ems);
		this.blockEntityRenderDispatcher = berd;
	}

	@Override
	public void renderByItem(ItemStack p_108830_, ItemTransforms.TransformType p_108831_, PoseStack p_108832_, MultiBufferSource p_108833_, int p_108834_, int p_108835_) {
		Item item = p_108830_.getItem();
		BlockEntity blockentity;
		if (item instanceof BlockItem) {
			if (item == ModItems.NETHERWOOD_CHEST.get()) {
				blockentity = this.netherwood_chest;
			}
			else if (item == ModItems.NETHERWOOD_TRAPPED_CHEST.get()) {
				blockentity = this.netherwood_trapped_chest;
			}
			else {
				blockentity = this.netherwood_chest;
			}
			MoreCraft.LOGGER.info("Attempting to render the item: " + blockentity); // This line will be removed when everything is working properly.
			this.blockEntityRenderDispatcher.renderItem(blockentity, p_108832_, p_108833_, p_108834_, p_108835_);
		}
	}
	
}

 

ModChestItem.java

Spoiler
package kittehmod.morecraft.item;

import java.util.function.Consumer;

import kittehmod.morecraft.client.ModBEWLR;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.IItemRenderProperties;

public class ModChestItem extends BlockItem
{
	
	public ModChestItem(Block block, Properties properties) {
		super(block, properties);
	}
	
	@Override
	public void initializeClient(Consumer<IItemRenderProperties> consumer) {
		super.initializeClient(consumer);
		consumer.accept(RenderProperty.INSTANCE);
	}
}

class RenderProperty implements IItemRenderProperties {
	
	public static RenderProperty INSTANCE = new RenderProperty();
	
	@Override
	public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
		return ModBEWLR.INSTANCE;
	}
}

 

Here's the screenshot. The chest does render properly placed in world but won't render in inventory. You can tell by item name tooltips. If more code is needed, I will only be too happy to show.

6FefFw1.png

What am I missing? I had mod BEWLR instance declared, had the chests hooked and firing.

Link to comment
Share on other sites

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.