Jump to content

[1.18.2] ItemStack in Renderer Empty after reloading the World


Recommended Posts

Hi, i am having a problem with my BlockEntityRenderer.

I am trying to render the Item that the BlockEntity is storing, but after i close and open the world again the itemRenderer dosn't render the item anymore.

public class StonePedestalRenderer implements BlockEntityRenderer<StonePedestalBlockEntity> {
    public final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();

    public StonePedestalRenderer(BlockEntityRendererProvider.Context pContext){

    public void render(StonePedestalBlockEntity pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, int pPackedOverlay) {
        ItemStack stack = new ItemStack(pBlockEntity.getItem());

        if (!stack.isEmpty()){
            pPoseStack.translate(0.5D, 1.3225D, 0.5D);
            float f3 = pBlockEntity.getSpin(pPartialTick);
            itemRenderer.renderStatic(Minecraft.getInstance().player,stack, ItemTransforms.TransformType.FIXED,false,pPoseStack,pBufferSource,Minecraft.getInstance().level,pPackedLight,pPackedOverlay,0);

and here is the code fore the Block Entity:

public class StonePedestalBlockEntity extends BlockEntity {
    protected ItemStackHandler itemHandler = new ItemStackHandler(1) {
        protected void onContentsChanged(int slot) {
    protected LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty();
    private float age = 0.0f;
    public final float bobOffs;
    private final Random random = new Random();;

    public StonePedestalBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
        super(BlockEntityRegistry.STONE_PEDESTAL_BLOCK_ENTITY.get(), pWorldPosition, pBlockState);
        this.bobOffs = this.random.nextFloat() * (float)Math.PI * 2.0F;

    public boolean setItem(ItemStack stack){
        if (this.itemHandler.getStackInSlot(0).isEmpty()){
            stack = new ItemStack(stack.getItem(),1);
            return true;
        return false;

    public Item getItem(){
        return this.itemHandler.getStackInSlot(0).getItem();

    public ItemStack getAndRemoveItem(){
        if (!this.itemHandler.getStackInSlot(0).isEmpty()){
            ItemStack stack = this.itemHandler.getStackInSlot(0);
            return stack;
        return this.itemHandler.getStackInSlot(0);

    public void removeItem(){

    public float getSpin(float pPartialTicks) {
        this.age += pPartialTicks;
        return (this.age) + this.bobOffs;

    public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {

        if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
            return lazyItemHandler.cast();
        return super.getCapability(cap, side);

    public void onLoad() {
        lazyItemHandler = LazyOptional.of(() -> itemHandler);

    public void invalidateCaps() {

    protected void saveAdditional(CompoundTag nbt) {
        nbt.put("inventory", itemHandler.serializeNBT());


    public void load(CompoundTag nbt) {

    public void drops() {
        SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots());
        for (int i = 0; i < itemHandler.getSlots(); i++) {
            inventory.setItem(i, itemHandler.getStackInSlot(i));

        Containers.dropContents(this.level, this.worldPosition, inventory);

When I click on the Block i get the Item back i put in even after logging out and back in. It is only the Renderer that dosen't work.

what am I missing here?

full source code: https://github.com/TobiasFiller/MiltenMagic

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.

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.


  • Create New...

Important Information

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