Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED][1.9] TileEntity not saving Data


Recommended Posts

My tileenetity is not saving its items. I can place items in the slots but once I leave and save the world and go back in the items are deleted.

 

TileEntity:

package com.waffle.to.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;

import java.util.ArrayList;

public class TOTileEntity extends TileEntity implements IInventory{

    private ItemStack[] stacks = new ItemStack[9];

    private boolean aBoolean;
    private byte aByte;
    private short aShort;
    private int anInt;
    private long aLong;
    private float aFloat;
    private double aDouble;
    private String aString;
    private byte[] aByteArray;
    private int[] anIntArray;



    private ItemStack anItemStack;

    private ArrayList aList = new ArrayList();

  private ItemStack[] inventory;
  private String customName;

    public TOTileEntity(){
        this.inventory = new ItemStack[this.getSizeInventory()];
    }

    public String getCustomName(){
        return this.customName;
    }

    public void setCustomName(String customName){
        this.customName = customName;
    }

    @Override
    public String getName(){
        return this.hasCustomName() ? this.customName : "container.to_tile_entity";
    }

    @Override
    public boolean hasCustomName(){
        return this.customName != null && !this.customName.equals("");
    }

    @Override
    public ITextComponent getDisplayName() {
        return null;
    }

    @Override //How many slots
    public int getSizeInventory(){
        return 9;
    }

    @Override
    public ItemStack getStackInSlot(int index) {
        if (index < 0 || index >= this.getSizeInventory())
            return null;
        return this.inventory[index];
    }

    @Override
    public ItemStack decrStackSize(int index, int count) {
        if (this.getStackInSlot(index) != null) {
            ItemStack itemstack;

            if (this.getStackInSlot(index).stackSize <= count) {
                itemstack = this.getStackInSlot(index);
                this.setInventorySlotContents(index, null);
                this.markDirty();
                return itemstack;
            } else {
                itemstack = this.getStackInSlot(index).splitStack(count);

                if (this.getStackInSlot(index).stackSize <= 0) {
                    this.setInventorySlotContents(index, null);
                } else {
                    //Just to show that changes happened
                    this.setInventorySlotContents(index, this.getStackInSlot(index));
                }

                this.markDirty();
                return itemstack;
            }
        } else {
            return null;
        }
    }

    @Override
    public ItemStack removeStackFromSlot(int index) {
        return null;
    }

    //@Override
    public ItemStack getStackInSlotOnClosing(int index) {
        ItemStack stack = this.getStackInSlot(index);
        this.setInventorySlotContents(index, null);
        return stack;
    }

    @Override
    public void setInventorySlotContents(int index, ItemStack stack) {
        if (index < 0 || index >= this.getSizeInventory())
            return;

        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
            stack.stackSize = this.getInventoryStackLimit();

        if (stack != null && stack.stackSize == 0)
            stack = null;

        this.inventory[index] = stack;
        this.markDirty();
    }

    @Override //Stack Limit per slot
    public int getInventoryStackLimit(){
        return 64;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer player) {
        return false;
    }

    //@Override
    public boolean isUsableByPlayer(EntityPlayer player){
        return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64;
    }

    @Override
    public void openInventory(EntityPlayer player) {
    }

    @Override
    public void closeInventory(EntityPlayer player) {
    }

    @Override
    public boolean isItemValidForSlot(int index, ItemStack stack){
        return true;
    }

    @Override
    public int getField(int id) {
        return 0;
    }

    @Override
    public void setField(int id, int value) {
    }

    @Override
    public int getFieldCount() {
        return 0;
    }

    @Override
    public void clear(){
        for (int i = 0; i < this.getSizeInventory(); i++)
            this.setInventorySlotContents(i, null);
    }

    @Override
    public void  writeToNBT(NBTTagCompound nbt) {
        super.writeToNBT(nbt);

        NBTTagList list = new NBTTagList();
        for (int i = 0; i < this.getSizeInventory(); ++i) {
            if (this.getStackInSlot(i) != null) {
                NBTTagCompound stackTag = new NBTTagCompound();
                stackTag.setByte("Slot", (byte) i);
                this.getStackInSlot(i).writeToNBT(stackTag);
                list.appendTag(stackTag);
            }
            nbt.setTag("Items", list);

            if (this.hasCustomName()) {
                nbt.setString("CustomName", this.getCustomName());
            }
        }
    }
    @Override
    public void readFromNBT(NBTTagCompound nbt){
        super.readFromNBT(nbt);
        NBTTagList list = nbt.getTagList("Items", 10);
        for (int i = 0; i < list.tagCount(); ++i) {
            NBTTagCompound stackTag = list.getCompoundTagAt(i);
            int slot = stackTag.getByte("Slot") & 255;
            this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
        }
        if (nbt.hasKey("CustomName", ){
            this.setCustomName(nbt.getString("CustomName"));
        }

    }





    //Implement ITickable for this to print
   /*@Override
    public void update(){
        if (!this.worldObj.isRemote)
        System.out.println("TestBlock TileEntity");
    }*/
}

Link to post
Share on other sites

There is server and there is client.

 

Without even looking at code:

 

1. Do you actually know that NBT is not saving/loading? Meaning - have you printed it in those methods, is it empty?

2. If yes - Fix your NBT code, if no - you are out of sync. Why? Becaouse you don't send description packet.

You need the getDescriptionPacket and onDataPacket methods for it to save.

 

1st one should return TE data packed in Packet (server), 2nd one should decrypt it. Look into vanilla.

1.7.10 is no longer supported by forge, you are on your own.

Link to post
Share on other sites

Ok so I added 2 lines to print both the reading and writing and its printing both but not sure if its actually doing it.

 

[00:27:16] [server thread/INFO]: [com.waffle.to.tileentity.TOTileEntity:writeToNBT:208]: WRITING NBT DATA

[00:27:10] [server thread/INFO]: [com.waffle.to.tileentity.TOTileEntity:readFromNBT:185]: READING NBT DATA

 

Link to post
Share on other sites

I think I implemented the getDescriptionPacket and onDataPacket but nothing happened the same thing is still happening.

 

  @Override
    public Packet getDescriptionPacket(){
        NBTTagCompound data = new NBTTagCompound();
        writeToNBT(data);
        return new SPacketUpdateTileEntity(this.pos, 1, data);
    }

    @Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
        readFromNBT(pkt.getNbtCompound());
        worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
    }

Link to post
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.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Trying to figure out the cause of this, unsure what it is i get this error anytime i launch a custom mod pack i created,looked to see if there was invalid depndencies or missing mods, couldnt see anything https://pastebin.com/2ZxW8SVc
    • 1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • If someone know what to do pls help me do i need to reinstall mods or delete some?   ---- Minecraft Crash Report ---- WARNING: coremods are present:   Quark Plugin (Quark-r1.6-178.jar)   SteveKunGLibPlugin (SteveKunG's-Lib-1.12.2-1.1.9.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   MovingWorldCore (movingworld-1.12-6.353-full.jar)   MekanismCoremod (Mekanism-1.12.2-9.8.3.390.jar)   MicdoodlePlugin (MicdoodleCore-1.12.2-4.0.2.280.jar)   TransformLoader (DynamicSurroundings-1.12.2-3.6.2.1.jar)   FutureMC (future-mc-1.12.2-0.2.6.1.jar) Contact their authors BEFORE contacting forge // You should try our sister game, Minceraft! Time: 4/11/21 11:03 PM Description: There was a severe problem during mod loading that has caused the game to fail net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from �3Dynamic Surroundings (dsurround) Caused by: java.lang.ExceptionInInitializerError   at org.orecruncher.dsurround.registry.RegistryManager.initialize(RegistryManager.java:103)   at org.orecruncher.dsurround.proxy.Proxy.loadCompleted(Proxy.java:92)   at org.orecruncher.dsurround.ModBase.loadCompleted(ModBase.java:178)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   at java.lang.reflect.Method.invoke(Method.java:498)   at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:637)   at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   at java.lang.reflect.Method.invoke(Method.java:498)   at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)   at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)   at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)   at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)   at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)   at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)   at com.google.common.eventbus.EventBus.post(EventBus.java:217)   at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)   at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   at java.lang.reflect.Method.invoke(Method.java:498)   at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)   at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)   at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)   at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)   at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)   at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)   at com.google.common.eventbus.EventBus.post(EventBus.java:217)   at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)   at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:757)   at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:336)   at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:535)   at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)   at net.minecraft.client.main.Main.main(SourceFile:123)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   at java.lang.reflect.Method.invoke(Method.java:498)   at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)   at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Caused by: java.lang.IllegalArgumentException: No enum constant net.minecraft.util.SoundCategory.DS_FOOTSTEPS   at java.lang.Enum.valueOf(Enum.java:238)   at net.minecraft.util.SoundCategory.valueOf(SourceFile:8)   at org.orecruncher.dsurround.registry.sound.SoundRegistry.<clinit>(SoundRegistry.java:67)   ... 43 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:   Minecraft Version: 1.12.2   Operating System: Windows 10 (amd64) version 10.0   Java Version: 1.8.0_271, Oracle Corporation   Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation   Memory: 2114811232 bytes (2016 MB) / 4294967296 bytes (4096 MB) up to 16777216000 bytes (16000 MB)   JVM Flags: 10 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx16000M -Xms4096M -Xss1M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M   IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0   FML: MCP 9.42 Powered by Forge 14.23.5.2854 39 mods loaded, 39 mods active   States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored   | State  | ID                                           | Version           | Source                                        | Signature                                |   |:------ |:-------------------------------------------- |:----------------- |:--------------------------------------------- |:---------------------------------------- |   | LCHIJA | minecraft                                    | 1.12.2            | minecraft.jar                                 | None                                     |   | LCHIJA | mcp                                          | 9.42              | minecraft.jar                                 | None                                     |   | LCHIJA | FML                                          | 8.0.99.99         | forge-1.12.2-14.23.5.2854.jar                 | e3c3d50c7c986df74c645c0ac54639741c90a557 |   | LCHIJA | forge                                        | 14.23.5.2854      | forge-1.12.2-14.23.5.2854.jar                 | e3c3d50c7c986df74c645c0ac54639741c90a557 |   | LCHIJA | micdoodlecore                                |                   | minecraft.jar                                 | None                                     |   | LCHIJA | com.elytradev.movingworld.common.asm.coremod |                   | minecraft.jar                                 | None                                     |   | LCHIJA | aether_legacy                                | 1.5.3             | aether-1.12.2-v1.5.3.jar                      | None                                     |   | LCHIJA | jei                                          | 4.16.1.301        | jei_1.12.2-4.16.1.301.jar                     | None                                     |   | LCHIJA | quark                                        | r1.6-178          | Quark-r1.6-178.jar                            | None                                     |   | LCHIJA | autoreglib                                   | 1.3-32            | AutoRegLib-1.3-32.jar                         | None                                     |   | LCHIJA | backpack                                     | 3.0.2             | backpack-3.0.2-1.12.2.jar                     | None                                     |   | LCHIJA | bettercaves                                  | 1.12.2            | bettercaves-1.12.2-2.0.4.jar                  | None                                     |   | LCHIJA | bettermineshafts                             | 1.12.2-2.2.1      | BetterMineshaftsForge-1.12.2-2.2.1.jar        | None                                     |   | LCHIJA | bibliocraft                                  | 2.4.5             | BiblioCraft[v2.4.5][MC1.12.2].jar             | None                                     |   | LCHIJA | biomesoplenty                                | 7.0.1.2443        | BiomesOPlenty-1.12.2-7.0.1.2443-universal.jar | None                                     |   | LCHIJA | chameleon                                    | 1.12-4.1.3        | Chameleon-1.12-4.1.3.jar                      | None                                     |   | LCHIJA | chesttransporter                             | 2.8.8             | ChestTransporter-1.12.2-2.8.8.jar             | None                                     |   | LCHIJA | mantle                                       | 1.12-1.3.3.55     | Mantle-1.12-1.3.3.55.jar                      | None                                     |   | LCHIJA | twilightforest                               | 3.11.1021         | twilightforest-1.12.2-3.11.1021-universal.jar | None                                     |   | LCHIJA | tconstruct                                   | 1.12.2-2.13.0.183 | TConstruct-1.12.2-2.13.0.183.jar              | None                                     |   | LCHIJA | conarm                                       | 1.2.5.10          | conarm-1.12.2-1.2.5.10.jar                    | b33d2c8df492beff56d1bbbc92da49b8ab7345a1 |   | LCHIJA | movingworld                                  | 1.12-6.353        | movingworld-1.12-6.353-full.jar               | None                                     |   | LCHIJA | davincisvessels                              | @DVESSELSVER@     | davincisvessels-1.12-6.340-full.jar           | None                                     |   | LCHIJA | galacticraftcore                             | 4.0.2.280         | GalacticraftCore-1.12.2-4.0.2.280.jar         | None                                     |   | LCHIJA | orelib                                       | 3.6.0.1           | OreLib-1.12.2-3.6.0.1.jar                     | 7a2128d395ad96ceb9d9030fbd41d035b435753a |   | LCHIJE | dsurround                                    | 3.6.2.1           | DynamicSurroundings-1.12.2-3.6.2.1.jar        | 7a2128d395ad96ceb9d9030fbd41d035b435753a |   | LCHIJ  | fastleafdecay                                | v14               | FastLeafDecay-v14.jar                         | None                                     |   | LCHIJ  | forgelin                                     | 1.8.4             | Forgelin-1.8.4.jar                            | None                                     |   | LCHIJ  | futuremc                                     | 0.2.6             | future-mc-1.12.2-0.2.6.1.jar                  | None                                     |   | LCHIJ  | galacticraftplanets                          | 4.0.2.280         | Galacticraft-Planets-1.12.2-4.0.2.280.jar     | None                                     |   | LCHIJ  | gravestone                                   | 1.10.1            | gravestone-1.10.1.jar                         | None                                     |   | LCHIJ  | waila                                        | 1.8.26            | Hwyla-1.8.26-B41_1.12.2.jar                   | None                                     |   | LCHIJ  | ironchest                                    | 1.12.2-7.0.67.844 | ironchest-1.12.2-7.0.72.847.jar               | None                                     |   | LCHIJ  | mekanism                                     | 1.12.2-9.8.3.390  | Mekanism-1.12.2-9.8.3.390.jar                 | None                                     |   | LCHIJ  | stevekung's_lib                              | 1.1.9             | SteveKunG's-Lib-1.12.2-1.1.9.jar              | None                                     |   | LCHIJ  | moreplanets                                  | 2.2.1             | More-Planets-1.12.2-2.2.1-GC280.jar           | None                                     |   | LCHIJ  | stg                                          | 1.12.2-1.2.3      | stg-1.12.2-1.2.3.jar                          | None                                     |   | LCHIJ  | storagedrawers                               | 1.12.2-5.4.0      | StorageDrawers-1.12.2-5.4.0.jar               | None                                     |   | LCHIJ  | waystones                                    | 4.1.0             | Waystones_1.12.2-4.1.0.jar                    | None                                     |   Loaded coremods (and transformers):  Quark Plugin (Quark-r1.6-178.jar)   vazkii.quark.base.asm.ClassTransformer SteveKunGLibPlugin (SteveKunG's-Lib-1.12.2-1.1.9.jar)    ForgelinPlugin (Forgelin-1.8.4.jar)    MovingWorldCore (movingworld-1.12-6.353-full.jar)    MekanismCoremod (Mekanism-1.12.2-9.8.3.390.jar)   mekanism.coremod.KeybindingMigrationHelper MicdoodlePlugin (MicdoodleCore-1.12.2-4.0.2.280.jar)   micdoodle8.mods.miccore.MicdoodleTransformer TransformLoader (DynamicSurroundings-1.12.2-3.6.2.1.jar)    FutureMC (future-mc-1.12.2-0.2.6.1.jar)   thedarkcolour.futuremc.asm.CoreTransformer   GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 465.89' Renderer: 'NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2'   Pulsar/tconstruct loaded Pulses:      - TinkerCommons (Enabled/Forced)     - TinkerWorld (Enabled/Not Forced)     - TinkerTools (Enabled/Not Forced)     - TinkerHarvestTools (Enabled/Forced)     - TinkerMeleeWeapons (Enabled/Forced)     - TinkerRangedWeapons (Enabled/Forced)     - TinkerModifiers (Enabled/Forced)     - TinkerSmeltery (Enabled/Not Forced)     - TinkerGadgets (Enabled/Not Forced)     - TinkerOredict (Enabled/Forced)     - TinkerIntegration (Enabled/Forced)     - TinkerFluids (Enabled/Forced)     - TinkerMaterials (Enabled/Forced)     - TinkerModelRegister (Enabled/Forced)     - wailaIntegration (Enabled/Not Forced)     - quarkIntegration (Enabled/Not Forced) [23:03:47] [Client thread/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:func_179870_a:553]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\Piotroxx\AppData\Roaming\Crystal-Launcher\instances\u.PiotroxxPack1\.minecraft\crash-reports\crash-2021-04-11_23.03.47-client.txt  
    • The client log shows you trying to connect to a vanilla server. The server log is from a forge server, but it ends (based on the timestamps) before the client log even shows the connection attempt. The server log shows several successful logins.
    • After removing Botania, it has been stable. So there was definitely something not happy there.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.