Jump to content

TileEntity inventory without using IInventory?


memcallen

Recommended Posts

ok cool I got it to work. I changed my code to:

package com.example.gammacraft.TileEntity;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class MultiToolModifierTileEntity extends TileEntity {

public ItemStack[] inv;

public MultiToolModifierTileEntity() {
	inv=new ItemStack[10];
}

public Packet getDescriptionPacket() {
        NBTTagCompound nbtTag = new NBTTagCompound();
        this.writeToNBT(nbtTag);
        return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
        readFromNBT(packet.func_148857_g());
}

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

	for(int i =0;i!=inv.length;i++){
		NBTTagCompound NBT = new NBTTagCompound();
		if(inv[i]!=null){
		inv[i].writeToNBT(NBT);
		nbt.setTag("ItemStack"+i,NBT);
		}
		System.out.println("saving:"+i);
	}

	this.markDirty();
}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);

	for(int i =0;i!=inv.length;i++){
		NBTTagCompound itemstack = nbt.getCompoundTag("ItemStack"+i);

		try{
		inv[i]=ItemStack.loadItemStackFromNBT(itemstack);
		}catch(Exception e){
			e.printStackTrace();
		}

		System.out.println("reading:"+i);

	}

}

}

The proud(ish) developer of Ancients

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.