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

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.

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

    • when i tried joining a world my mc crashed exit code -805306369
    • Hello There! In the 73rd episode of Bed Wars we get into a lobby with a guy who had a cool name and for some reason Ben is very impressed with the name and thus the title!  
    • I have been trying to install forge, but I can't even get the installer to run. I'm really not sure what the issue is, first let me make sure I am even using the installer right, I downloaded the forge installer matching my minecraft version (1.19.2), if I double click the .jar from the download then I see a flash of a black window that immediately disappears. If I use a command prompt, I receive the following output: C:\Users\austi> java -jar forge-1.19.2-43.0.19-installer.jar Error: Unable to access jarfile forge-1.19.2-43.0.19-installer.jar   I feel like this is more likely a java issue than a forge issue but I was hoping that people here might be able to help. I've tried a couple versions of java, at first I was using 8 I believe because all of the install guides for forge were a bit older so they linked to the java website rather than oracle. I tried version 18 from the oracle site and received the same result from command prompt. It is also entirely possible that I am doing something else wrong that is blatantly obvious to everyone else.
    • Here is my configuration: % java -version java version "18.0.2" 2022-07-19 Java(TM) SE Runtime Environment (build 18.0.2+9-61) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing) forge-1.19-41.1.0-mdk on macOS Monterey 12.5 I ran the command: ./gradlew genEclipseRuns and was hoping it will generate the Eclipse project files for me. The run log is at https://gist.github.com/arun-gupta/06b983a6976b4c0a0f510d0dc225ddd3 and the generated directory structure is at https://gist.github.com/arun-gupta/3f5bfc70ec5d3d903b0f97d42840abda. In previous versions (1.12-ish), it used to generate an eclipse directory but 1.19 does not seem to have it. I tried opening the top-level forge directory but Eclipse does not recognize it as a project as well. How do I open this project in Eclipse now?  
    • I didn't put in credentials, I used it only for testing installing forge. But still the problem mentioned above.
  • Topics

  • Create New...

Important Information

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