Jump to content

[1.16.5] Cannot get data from TileEntity in TileEntityRenderer


MIssNalgas

Recommended Posts

Hello there! I am once again asking for your Modding support.

So I made a TileEntityRenderer and it all works find. It renders and everything is wonderful. The thing is, in the "render" function when I try to access data from the TileEntity, it is always empty. While debugging I noticed that the instance of my TileEntity is different from the one in the TER. For example:

if i get it from the Block or the TileEntity itself : "com.example.examplemod.MyTileEntity@7158bcf2"

If I get it from the TER: "com.example.examplemod.MyTileEntity@4251b1ed"

 

 

@Override
public void render(MyTileEntity tileEntity, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer renderTypeBuffer, int light, int overlay) {

        float item = tileEntity.getItem(); //This always returns "Air" no matter what I do :c


        this.render(matrixStack, ivertexbuilder, this.lid, this.lock, this.bottom, openness, light, overlay);
    }

Thank you! n.n

Link to comment
Share on other sites

12 minutes ago, MIssNalgas said:

While debugging I noticed that the instance of my TileEntity is different from the one in the TER.

Shocker, there's a server side copy and a client side copy.

$100 says you didn't sync your data.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

6 minutes ago, Draco18s said:

Shocker, there's a server side copy and a client side copy.

$100 says you didn't sync your data.

public void load(BlockState state, CompoundNBT nbt) {
        super.load(state, nbt);
        this.items = NonNullList.withSize(10, ItemStack.EMPTY);
        ItemStackHelper.loadAllItems(nbt, this.items);

}

public CompoundNBT save(CompoundNBT nbt) {
        super.save(nbt);
        ItemStackHelper.saveAllItems(nbt, this.items);
        return nbt;
}

@Override
    public SUpdateTileEntityPacket getUpdatePacket() {
        return new SUpdateTileEntityPacket(this.worldPosition, 24, getUpdateTag());
    }

    @Override
    public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
        load(this.getBlockState(), pkt.getTag());
    }

    public CompoundNBT getUpdateTag() {
        return this.saveMetadataAndItems(new CompoundNBT());
    }

    private CompoundNBT saveMetadataAndItems(CompoundNBT p_213983_1_) {
        super.save(p_213983_1_);
        ItemStackHelper.saveAllItems(p_213983_1_, this.items, true);
        return p_213983_1_;
    }



    @Override
    public void handleUpdateTag(BlockState blockState, CompoundNBT tag)
    {
        this.load(blockState, tag);
    }

Im kinda new to this. Is there anything else I should override?

Link to comment
Share on other sites

Post your entire TE class. It appears you are using IInventory, which you should not be using.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

9 minutes ago, Draco18s said:

Post your entire TE class. It appears you are using IInventory, which you should not be using.

package com.example.examplemod;

import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.LockableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;

public class ChestingTableTileEntity extends LockableTileEntity implements ITickableTileEntity {

    private NonNullList<ItemStack> items = NonNullList.withSize(10, ItemStack.EMPTY);
    private int openCount = 0;
    private float openness = 0.0f;

    public ChestingTableTileEntity(TileEntityType<?> entityType) {
        super(entityType);
        ExampleMod.LOGGER.info("Created tile entity chest: "+this);
    }

    public ChestingTableTileEntity() {
        this(ExampleMod.myChestTileEntity.get());
        ExampleMod.LOGGER.info("fechasimportantes");
    }

    @Override
    protected Container createMenu(int i, PlayerInventory inventory) {
        return new MyChestContainer(inventory, i, this);
    }

    @Override
    public void tick() {

        if (this.openCount > 0 && this.openness < 1.0f || this.openCount == 0 && this.openness > 0.0f) {
            if (this.openCount > 0) {
                this.openness += 0.1f;
            } else {
                this.openness -= 0.1f;
            }
            if (this.openness < 0.0f) {
                this.openness = 0.0f;
            }

        }

    }

    @OnlyIn(Dist.CLIENT)
    public float getOpenness() {
        return this.openness;
    }

    public void load(BlockState state, CompoundNBT nbt) {
        super.load(state, nbt);
        this.items = NonNullList.withSize(10, ItemStack.EMPTY);
        ItemStackHelper.loadAllItems(nbt, this.items);

    }

    public CompoundNBT save(CompoundNBT nbt) {
        super.save(nbt);
        ItemStackHelper.saveAllItems(nbt, this.items);
        return nbt;
    }

    @Override
    protected ITextComponent getDefaultName() {
        return new StringTextComponent("Chesting table");
    }

    @Override
    public int getContainerSize() {
        return this.items.size();
    }

    @Override
    public boolean isEmpty() {
        for (ItemStack item : this.items) {
            if (!item.isEmpty()) {
                return false;
            }
        }
        return true;
    }

    @Override
    public ItemStack getItem(int i) {
        return this.items.get(i);
    }

    @Override
    public ItemStack removeItem(int i1, int i2) {
        return ItemStackHelper.removeItem(this.items, i1, i2);
    }

    @Override
    public ItemStack removeItemNoUpdate(int i) {
        return ItemStackHelper.takeItem(this.items, i);
    }

    @Override
    public void setItem(int index, ItemStack item) {
        ExampleMod.LOGGER.info("SetItem: "+this);
        this.items.set(index, item);
    }

    @Override
    public boolean stillValid(PlayerEntity p_70300_1_) {
        return true;
    }

    @Override
    public void clearContent() {
        this.items.clear();
    }

    public void startOpen(PlayerEntity p_174889_1_) {
        this.openCount++;
    }

    public void stopOpen(PlayerEntity p_174886_1_) {
        if (this.openCount > 0) {
            this.openCount--;
        }
    }

    @Nullable
    @Override
    public SUpdateTileEntityPacket getUpdatePacket() {
        return new SUpdateTileEntityPacket(this.worldPosition, 24, getUpdateTag());
    }

    @Override
    public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
        BlockState state = this.getLevel().getBlockState(this.worldPosition);
        load(state, pkt.getTag());
    }

    public CompoundNBT getUpdateTag() {
        return this.saveMetadataAndItems(new CompoundNBT());
    }

    private CompoundNBT saveMetadataAndItems(CompoundNBT p_213983_1_) {
        super.save(p_213983_1_);
        ItemStackHelper.saveAllItems(p_213983_1_, this.items, true);
        return p_213983_1_;
    }



    @Override
    public void handleUpdateTag(BlockState blockState, CompoundNBT tag)
    {
        this.load(blockState, tag);
    }
}

Could be that the problem?

Link to comment
Share on other sites

17 minutes ago, MIssNalgas said:

extends LockableTileEntity

Yep, you're using IInventory. Check the class hierarchy for LockableTileEntity.

You should be using Capabilities instead.

 

https://mcforge.readthedocs.io/en/1.16.x/tileentities/tileentity/

https://mcforge.readthedocs.io/en/1.16.x/datastorage/capabilities/

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

4 hours ago, Draco18s said:

Yep, you're using IInventory. Check the class hierarchy for LockableTileEntity.

You should be using Capabilities instead.

 

https://mcforge.readthedocs.io/en/1.16.x/tileentities/tileentity/

https://mcforge.readthedocs.io/en/1.16.x/datastorage/capabilities/

Thank you for answering. But that didn't resolve my issue xd. I found out though that the tileentity does update when i reload the chunk

Link to comment
Share on other sites

Just now, MIssNalgas said:

Thank you for answering. But that didn't resolve my issue xd. I found out though that the tileentity does update when i reload the chunk

Forgot to say. When i found out i tried using #world.sendBlockUpdated() to update the block but if i do that the TER dissapears xdd.

I will be crying in the bathroom if you need me

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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