Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

  • Author

a) Alright done :)

b) When I use xCoord, yCoord, zCoord. Problem is they always are 0, 0, 0

c) Ahh never knew that :D

 

So how could I get xCoord, yCoord, zCoord not to be 0, 0, 0?  ???

 

 

 

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!

 

  • Author

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! :)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.