makromoo Posted July 5, 2014 Posted July 5, 2014 Hello Everybody! I'm having issues getting a TileEntity from using: worldObj.getTileEntity(xCoord, yCoord, zCoord); I just get null pointer exceptions... -Using try/catch solved the crash but doesn't fix the issue... Below is the TileEntity Class: package com.example.examplemod.entity; import net.minecraft.tileentity.TileEntity; public class TileMultiBlock extends TileEntity { public TileMultiBlock(int x, int y, int z) { System.out.println(String.format("X: %d y: %d Z: %d", x, y, z)); // Returns block's co-ordinates System.out.println(String.format("X: %d y: %d Z: %d", xCoord, yCoord, zCoord)); // Returns 0, 0, 0 try { TileEntity TE = worldObj.getTileEntity(xCoord, yCoord, zCoord); System.out.println(TE.blockMetadata); } catch (Exception e) { e.printStackTrace(); } //updateEntity(); //TileEntity tileEnt2 = worldObj.getTileEntity(x, y, z); } And below here is the Block Class: I have it passing it's co-ordinates to the TileEntity.. package com.example.examplemod.blocks; import com.example.examplemod.entity.TileMultiBlock; import com.example.examplemod.misc.CreativeTab; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class BlockMainBlock extends BlockContainer { int x; int y; int z; public BlockMainBlock(Material mat) { super(mat); setBlockName("mainBlock"); setCreativeTab(CreativeTab.tabSlime); } @Override public void onBlockAdded(World world, int x, int y, int z) { this.x = x; this.y = y; this.z = z; } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { return new TileMultiBlock(x, y, z); } } Thanks for all your troubles! Quote
makromoo Posted July 6, 2014 Author Posted July 6, 2014 a) Alright done b) When I use xCoord, yCoord, zCoord. Problem is they always are 0, 0, 0 c) Ahh never knew that So how could I get xCoord, yCoord, zCoord not to be 0, 0, 0? Quote
FLUFFY2 Posted July 6, 2014 Posted July 6, 2014 Why are you want to get a TileEntity in your TileEntity class? Thats stupid! Your tile entity is already defined with "this."!!! Your case: this.blockMetadata; If you create a new TE for your block the cordinates are already "connected" together! BUT be careful TE can be null and crash the game! Quote
makromoo Posted July 6, 2014 Author Posted July 6, 2014 Ah I see at what you getting at @Kriki98, @diesieben07 I also figured out why it was returning 0, 0, 0. I shouldn't put that in the constructor but in the updateEntity() method. Thanks for all your help! Quote
Recommended Posts
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.