Jump to content

Tile Entity Problems


Recommended Posts

Ok so i have a Tile Entity and block to go with it. I want one of my entities to set that block, then modify something in it's tile Entity. It keeps coming up with a NullPointerException.






package com.apmods.magicraft.block;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class BlockPortkey extends BlockBase{

public BlockPortkey(String name) {
	// TODO Auto-generated constructor stub

public boolean hasTileEntity(int metadata)
    return true;

public TileEntity createNewTileEntity(World par1World)
        return new TileEntityPortkey();
    catch (Exception var3)
        throw new RuntimeException(var3);
public void setPortkeyCoords(EntityPlayer player, World world, int x, int y, int z, int x1, int y1, int z1){
		TileEntityPortkey p = (TileEntityPortkey)world.getTileEntity(x, y, z);
		p.setPortkeyCoords(world, x1, y1, z1);
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
                        TileEntityPortkey t = (TileEntityPortkey) world.getTileEntity(par2, par3, par4);
                        t.teleport(world, par5EntityPlayer);
                return true;




Relevant Entity code:


Block block = this.worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ);
   Material mat = this.worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ).getMaterial();
   BlockPortkey portkey = (BlockPortkey) BlockManager.portkey;
   this.worldObj.setBlock(mop.blockX, mop.blockY, mop.blockZ, portkey);
   TileEntityPortkey p = (TileEntityPortkey) portkey.createNewTileEntity(worldObj);
   p.setPortkeyCoords(worldObj, this.getCoord(1), this.getCoord(2), this.getCoord(3));





package com.apmods.magicraft.block;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class TileEntityPortkey extends TileEntity{
int prevx = 0;
int prevy = 0;
int prevz = 0;
 int x = 0;
 int y = 0;
 int z = 0;
public void readFromNBT(NBTTagCompound nbt)
    this.x = nbt.getInteger("xcoord");
    this.y = nbt.getInteger("ycoord");
    this.z = nbt.getInteger("zcoord");
    this.prevx = nbt.getInteger("prevxcoord");
    this.prevy = nbt.getInteger("prevycoord");
    this.prevz = nbt.getInteger("prevzcoord");
public void writeToNBT(NBTTagCompound nbt)
    nbt.setInteger("xcoord", x);
    nbt.setInteger("ycoord", y);
    nbt.setInteger("xcoord", z);
    nbt.setInteger("prevxcoord", prevx);
    nbt.setInteger("prevycoord", prevy);
    nbt.setInteger("prevzcoord", prevz);
public void setPortkeyCoords(World world, int x1, int y1, int z1) {
	x = x1;
	y = y1;
	z = z1;
	world.notifyBlockChange(x, y, z, BlockManager.portkey);

public void teleport(World world, EntityPlayer par5EntityPlayer) {
	if(world.isAirBlock(x, y, z)){
		prevx = (int) par5EntityPlayer.posX;
		prevy = (int) par5EntityPlayer.posY;
		prevz = (int) par5EntityPlayer.posZ;
		par5EntityPlayer.setPositionAndUpdate(x, y, z);





Crash Report:


Caused by: java.lang.NullPointerException
at com.apmods.magicraft.block.BlockPortkey.onBlockActivated(BlockPortkey.java:41) ~[blockPortkey.class:?]
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409) ~[itemInWorldManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?]
... 5 more



Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

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.

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.

  • Create New...

Important Information

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