Jump to content

Recommended Posts

Posted

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

Posted
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.

Posted
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?

Posted

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.

Posted
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?

Posted
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.

Posted
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

Posted
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

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.