Jump to content

Recommended Posts

Posted

[11:57:59] [server thread/ERROR] [FML]: A TileEntity type com.zombiesurvival.tileentity.GoldChestTileEntity has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class com.zombiesurvival.tileentity.GoldChestTileEntity is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:93) ~[TileEntity.class:?]
at com.zombiesurvival.tileentity.GoldChestTileEntity.writeToNBT(GoldChestTileEntity.java:197) ~[GoldChestTileEntity.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:410) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:193) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:266) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:332) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:976) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:419) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:454) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:356) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:593) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]

GoldChest Tile Entity

package com.zombiesurvival.tileentity;

import java.util.ArrayList;

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.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;

public class GoldChestTileEntity extends TileEntity implements IUpdatePlayerListBox, IInventory
{
//Declaring Variables
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[] inv;
private String test;

public GoldChestTileEntity()
{
	this.inv = new ItemStack[this.getSizeInventory()];
}
public String getCustomName()
{
	return this.test;
}
public void setCustomName(String test)
{
	this.test = test;
}
@Override
public String getName()
{
	return this.hasCustomName() ? this.test : "container.goldchest_tile_entity";
}

@Override
public boolean hasCustomName()
{
	return this.test != null && !this.test.equals("");
}
@Override
public IChatComponent getDisplayName()
{
	return this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName());
}
@Override
public int getSizeInventory()
{
	return 9;
}
@Override
public ItemStack getStackInSlot(int index)
{
	if(index < 0 || index >= this.getSizeInventory())
		return null;
	return this.inv[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 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.inv[index] = stack;
	this.markDirty();
}
@Override 
public int getInventoryStackLimit()
{
	return 64;
}
@Override 
public boolean isUseableByPlayer(EntityPlayer p)
{
	return this.worldObj.getTileEntity(this.getPos()) == this && p.getDistanceSq(this.pos.add(0.5,0.5,0.5)) <= 64;

}
@Override
public void openInventory(EntityPlayer p)
{

}
@Override
public void closeInventory(EntityPlayer p)
{

}
@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 update()
{

}





@Override
public void writeToNBT(NBTTagCompound c)
{
	super.writeToNBT(c);
/**	
	//Primitives
	c.setBoolean("aBoolean", this.aBoolean);
	c.setByte("aByte", this.aByte);
	c.setShort("aShort", this.aShort);
	c.setInteger("anInt", this.anInt);
	c.setLong("aLong", this.aLong);
	c.setFloat("aFloat", this.aFloat);
	c.setDouble("aDouble", this.aDouble);
	c.setString("aString", this.aString);
	c.setByteArray("aByteArray", this.aByteArray);
	c.setIntArray("anIntArray", this.anIntArray);

	//Item Stack
	NBTTagCompound s = new NBTTagCompound();
	this.anItemStack.writeToNBT(s);
	c.setTag("anItemStack", s);

	//TagList of Integer Tags
	NBTTagList l = new NBTTagList();
	for(int i = 0; i < this.aList.size(); i++)
	{
	NBTTagCompound n = new NBTTagCompound();
	n.setInteger("id", i);
	n.setInteger("value", (Integer) this.aList.get(i));
	l.appendTag(n);

	}
	c.setTag("aList", l);*/

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

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

	/**Primitives
	this.aBoolean = c.getBoolean("aBoolean");
	this.aByte = c.getByte("aByte");
	this.aShort = c.getShort("aShort");
	this.anInt = c.getInteger("aInt");
	this.aLong = c.getLong("aLong");
	this.aFloat = c.getFloat("aFloat");
	this.aDouble = c.getDouble("aDouble");
	this.aString = c.getString("aString");
	this.aByteArray = c.getByteArray("aByteArray");
	this.anIntArray = c.getIntArray("anIntArray");

	//ItemStack
	this.anItemStack = ItemStack.loadItemStackFromNBT(c.getCompoundTag("anItemStack"));

	//TagList of IntegerTags
	NBTTagList l = c.getTagList("aList", 10);
	this.aList.clear();
	for(int i = 0; i < l.tagCount(); i++)
	{
		NBTTagCompound n = l.getCompoundTagAt(i);
		int id = n.getInteger("id");
		int value = n.getInteger("value");
		this.aList.ensureCapacity(id);
		this.aList.set(id, value);
	}
	*/
	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("gold", 9))
	{
		this.setCustomName(nbt.getString("gold"));
	}
}

}

ModTileEntities <- Where TileEntities Are Registered

package com.zombiesurvival.tileentity;

import com.zombiesurvival.power.pipes.TileEntityPipe;

import net.minecraftforge.fml.common.registry.GameRegistry;

public final class ModTileEntities
{
public static void init()
{
	GameRegistry.registerTileEntity(IronChestTileEntity.class, "ironchest_tile_entity");
	GameRegistry.registerTileEntity(IronChestTileEntity.class, "goldchest_tile_entity");
	GameRegistry.registerTileEntity(LargeBackpackTileEntity.class, "largebackpack_tile_entity");
	GameRegistry.registerTileEntity(ElectricFurnaceTileEntity.class, "electric_furnace_tile_entity");
	GameRegistry.registerTileEntity(TileEntityPipe.class, "pipe_tile_entity");
}
}

 

 

Main Class

package com.zombiesurvival;

import com.zombiesurvival.blocks.ModBlocks;
import com.zombiesurvival.gui.handlers.EventHandlerOverlay;
import com.zombiesurvival.gui.handlers.ModGuiHandler;
import com.zombiesurvival.gui.hud.ItemHUDactivator;
import com.zombiesurvival.gui.hud.StatusBarRenderer;
import com.zombiesurvival.items.ModItems;
import com.zombiesurvival.proxy.CommonProxy;
import com.zombiesurvival.utils.FuelManager;
import com.zombiesurvival.utils.KeyBindings;
import com.zombiesurvival.utils.KeyInputHandler;
import com.zombiesurvival.utils.crafting.CraftingManager;

import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@Mod(modid=Main.MODID, name=Main.MODNAME, version=Main.MODVER) 
public class Main 
{
/**TODO: 
* WINDMILLS (3D Modeled with Spinning Rotor).
* Power Systems
* Energy Pipes
* Item Pipes
* Fluid Pipes
* Energy Cables
*/
    public static final String MODID = "zombiesurvival";
    //Set the "Name" of the mod.
    public static final String MODNAME = "Main";
    //Set the version of the mod.
    public static final String MODVER = "0.0.1 Alpha";
    
    @Instance(value = Main.MODID)
    public static Main instance;
    //Items
    public static Item rifle22;
    public static Item bullets22;
    public static Item steelIngot;
    public static Item brassIngot;
    public static Item nickelIngot;
    public static Item bronzeIngot;
    //Creative Tabs
    public static CreativeTabs test = new CreativeTabs("Test") {
        @Override
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem() {
            return Items.iron_ingot;
        }
    };
    public static ItemHUDactivator itemHUDactivator; 
@SidedProxy(clientSide="com.zombiesurvival.proxy.ClientProxy", serverSide="com.zombiesurvival.proxy.CommonProxy")
public static CommonProxy proxy;
    @EventHandler
    public void preInit(FMLPreInitializationEvent e)
    {
    	FMLCommonHandler.instance().bus().register(new KeyInputHandler());
    	KeyBindings.init();
    	ModItems.init();
    	ModBlocks.init();
    	CraftingManager.init();
    	proxy.registerRenderers();
    	GameRegistry.registerFuelHandler(new FuelManager());

    	/**
    	 * to fix
    	 */
    //	EntityRegistrar.init();
    }
    
    @EventHandler
    public void Init(FMLInitializationEvent e)
    {
    	NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new ModGuiHandler());
    	
    }
    private static StatusBarRenderer statusBarRenderer;
    @EventHandler
    public void postInit(FMLPostInitializationEvent e)
    {

    }
    


}

 

 

 

Why am i getting the error i'm really confused.

Posted

Hey Lord, I know this isn't on topic with this thread but would you be able to give me asome pointers about creating a simple energy system, i just want to be able to connect a pipe to a stone block and then if its connected to my block (named test) it to just say hi in console. I've gave it a go but im a bit stuck. Any help would be lovelyyyyyyyy.

Posted

Ok so I created a block called PowerTest.

Please bare in mind im not the best modder out there im still learning im making this mod to learn more :P.


package com.zombiesurvival.blocks;

import com.zombiesurvival.power.pipes.BlockPipe;
import com.zombiesurvival.tileentity.PowerTestTileEntity;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;

public class PowerTest extends BlockContainer 
{

public PowerTest(String unlocalizedName, Material mat) {
	super(Material.iron);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setUnlocalizedName(unlocalizedName);
}
public boolean activated = false;

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) 
{
	return new PowerTestTileEntity();
}
public void onNeighborBlockChange(World w, BlockPos pos, IBlockState state, Block nb)
{
	if (!w.isRemote)
        {
		//TODO: If Power is already on then it cannot be turned on again
		if(nb != ModBlocks.pipe)
				{
					System.out.println("Power On");
					if(BlockPipe.isPoweredGlobal == true)
					{
						System.out.println(" We Have Power");
					}
					else if(BlockPipe.isPoweredGlobal == false)
					{
						System.out.println(" We Don't Have Power");
					}
					else
					{
						System.out.println(" Error");
					}
				}
		//TODO Change to Else If Statement to check for errors else then it's an error
				else
				{
					System.out.println("Power off");
				}
        }
}
public boolean pipeNext(World w,int x,int y,int z)
{


	return activated;


}
public void onBlockActivated()
{

}

}

 

I kow that the stuff im doing in onNeighborBlockChange should be in a method that checks for updates on every tick but it was for testing.

In My Block Pipes i created 2 booleans one that's static, (probably so wrong)

I honestly think  i should be saving this boolean somewhere else but i don't know how/ where.

package com.zombiesurvival.power.pipes;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockPipe extends BlockContainer
{
public boolean isPowered;
public static boolean isPoweredGlobal;
public BlockPipe(String unlocalizedName, Material mat) 
{
	super(mat);
	float pixel = 1F/16F;
	//Minx,miny,minz,maxx,maxy,maxz
	this.setBlockBounds(11*pixel/2,11*pixel/2, 11*pixel/2, 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setUnlocalizedName(unlocalizedName);
}

public int getRenderType()
{
	return -1;
}
public boolean isOpaqueCube()
{
	return false;
}
public boolean renderAsNormalBlock()
{
	return false;
}
public TileEntity createNewTileEntity(World w, int i)
{
	return new TileEntityPipe();
}
@SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer()
    {
        return EnumWorldBlockLayer.CUTOUT;
    }
public void onNeighborBlockChange(World w, BlockPos pos, IBlockState state, Block nb)
{
	if (!w.isRemote)
        {
		//TODO: If Power is already on then it cannot be turned on again
		if(nb == Blocks.stone)
				{

					isPowered = true;
					if(isPowered = true)
					{

						isPoweredGlobal = true;
						System.out.println("Pipe has Power");
					}


				}
		//TODO Change to Else If Statement to check for errors else then it's an error
				else if (nb != Blocks.stone)
				{

					isPowered = false;
					if(isPowered = false)
					{
						System.out.println("Pipe doesn't have Power ");
						isPoweredGlobal = false;
					}
					else
					{
						//System.out.println("Pipe has Power");
						//isPoweredGlobal = true;
					}
				}
        }
}

}

 

 

So yeah Thats the code. :D

Posted

never. ever. under no circumstance. save that bool in the block class. every single block u place shares the same instance of block. if u want to save different values u need to use the tileentity, u can access that via world.getTileEntity

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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