Jump to content

Recommended Posts

Posted

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.

 

Code:

 

Block:

 

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) {
	super(name);
	// TODO Auto-generated constructor stub
}

public boolean hasTileEntity(int metadata)
{
    return true;
}

public TileEntity createNewTileEntity(World par1World)
{
    try
    {
        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){
	if(!world.isRemote){
		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)
    {
                if(!world.isRemote)
                {
                        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;
   portkey.createNewTileEntity(worldObj);
   this.worldObj.setBlock(mop.blockX, mop.blockY, mop.blockZ, portkey);
   System.out.println("setBlock");
   TileEntityPortkey p = (TileEntityPortkey) portkey.createNewTileEntity(worldObj);
   p.setPortkeyCoords(worldObj, this.getCoord(1), this.getCoord(2), this.getCoord(3));
   this.setDead();

 

 

TileEntity:

 

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;
@Override
public void readFromNBT(NBTTagCompound nbt)
{
    super.readFromNBT(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");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
    super.writeToNBT(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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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