Jump to content

[1.7.10] [SOLVED] Getting Tile Entities


makromoo

Recommended Posts

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!

Link to comment
Share on other sites

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!

 

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.

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



×
×
  • Create New...

Important Information

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