1

Tile entity not seeming to spawn

Unlocked 9/25/14 9:23 pm
891
10/2/2014 8:14 pm
Hi! I have a block called the portal block which contains a tile entity. However, the tile entity does not appear to exist. When I run the code that gets the tile entity, it returns null even though I am certain I got all of the code for spawning one right. Here is my code:

Base mod code (relating to the tile entity)

GameRegistry.registerTileEntity(PortalBlockTileEntity.class, "portalBlockEntity");

Block code
package com.unlocked.stuff_things.blocks;

import com.unlocked.stuff_things.StuffAndThingsMod;
import com.unlocked.stuff_things.entity.PortalBlockTileEntity;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class PortalBlock extends Block {

PortalBlockTileEntity t;
double x;
double y;
double z;
int myX;
int myY;
int myZ;
World myWorld;
int dimension;
boolean set;

public PortalBlock(boolean local){

super(Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setHardness(1.5f);
this.setResistance(10f);
if (local){
this.setBlockName("portal_block_local");
this.setBlockTextureName("stuffthings:portal_block_local");
}
else
{
this.setBlockName("portal_block_trans");
this.setBlockTextureName("stuffthings:portal_block_trans");
}
}

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack){
myX = x;
myY = y;
myZ = z;
myWorld = world;
}

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

public TileEntity createNewTileEntity(World par1World, int metadata)
{
return new PortalBlockTileEntity();
}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
{
float f = 1F;
return AxisAlignedBB.getBoundingBox((float)i + f, j, (float)k + f, (float)(i + 1) - f, (float)(j + 1) - f, (float)(k + 1) - f);
}

public void SetX(double x, World world){
t = (PortalBlockTileEntity) world.getTileEntity(myX, myY, myZ);
if (t != null){
t.SetX(x);
this.x = x;
t.setSet(true);
}
}

public void SetY(double y){
if (t != null){
t.SetY(y);
this.y = y;
}
}

public void SetZ(double z){
if (t != null){
t.SetZ(z);
this.z = z;
}
}

public void SetDimension(int dimension) {
if (t != null){
t.SetDimension(dimension);
this.dimension = dimension;
}
}

public double GetX(World world){
t = (PortalBlockTileEntity) world.getTileEntity(myX, myY, myZ);
if (t != null){
x = t.GetX();
}
return x;
}

public double GetY(){
if (t != null){
y = t.GetY();
}
return y;
}

public double GetZ(){
if (t != null){
z = t.GetZ();
}
return z;
}

public int GetDimension(){
if (t != null){
dimension = t.GetDimension();
}
return dimension;
}

public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity){
t = (PortalBlockTileEntity) world.getTileEntity(i, j, k);
if (t != null){
if (t.getSet()){
if (t != null){
t.onCollide(world, i, j, k, entity);
}
}
}
}
}


Tile entity code

package com.unlocked.stuff_things.entity;

import com.unlocked.stuff_things.StuffAndThingsMod;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.src.*;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class PortalBlockTileEntity extends TileEntity{

private double x;
private double y;
private double z;
private int dimension;
private boolean set = false;

public Entity onCollide(World world, int i, int j, int k, Entity entity){
if (world.isRemote){
entity.setPosition(this.x, this.y, this.z);
entity.fallDistance = 0f;

if (world.getBlock(i, j, k) == StuffAndThingsMod.portalBlockTrans && entity.dimension != this.dimension){
entity.travelToDimension(this.dimension);
}
}
return entity;
}

@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.x = nbt.getDouble("x");
this.y = nbt.getDouble("y");
this.z = nbt.getDouble("z");
this.dimension = nbt.getInteger("dim");
this.set = nbt.getBoolean("set");
}

public boolean getSet(){
return set;
}

public void setSet(boolean set){
this.set = set;
}

public void SetX(double x){
this.x = x;
}

public void SetY(double y){
this.y = y;
}

public void SetZ(double z){
this.z = z;
}

public void SetDimension(int dimension) {
this.dimension = dimension;
}

public double GetX(){
return x;
}

public double GetY(){
return y;
}

public double GetZ(){
return z;
}

public int GetDimension(){
return dimension;
}

@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setDouble("x", x);
nbt.setDouble("y", y);
nbt.setDouble("z", z);
nbt.setInteger("dim", dimension);
nbt.setBoolean("set", set);
}

}


Thanks for any help.

-Unlocked
Posted by
Unlocked
Level 30 : Artisan Dragon
10

  Have something to say?

JoinSign in

11

Karrfis
10/02/2014 7:40 pm
They/Them • Level 35 : Artisan uwu uwu
have you tried asking in the minecraft forums also? there are lots of experienced modders who hang around in there, more than hang around the pmc forums
1
Unlocked
10/02/2014 8:14 pm
Level 30 : Artisan Dragon
Good idea. I kinda wanted to keep each topic to one post but I guess I will be sitting here for a while if I do.
1
Unlocked
10/02/2014 7:26 pm
Level 30 : Artisan Dragon
help.... please...
1
Unlocked
10/01/2014 7:20 pm
Level 30 : Artisan Dragon
BUMP!!!
1
Unlocked
09/30/2014 9:53 pm
Level 30 : Artisan Dragon
bump
1
_Hellcat_
09/29/2014 8:37 pm
Level 34 : Artisan Toast
Problem solved! All you need to do is to go into the mod folders, click on troubleshooting, find the file: helpme.txt, go into it, type in #pizzawithcheese, dial 911, call the ambulance and ask for a donut
1
Unlocked
09/29/2014 10:18 pm
Level 30 : Artisan Dragon
I would prefer not joke answers.
1
Unlocked
09/29/2014 7:00 pm
Level 30 : Artisan Dragon
BUMP! Can someone please help?
1
Unlocked
09/28/2014 11:08 am
Level 30 : Artisan Dragon
Help?
1
Unlocked
09/27/2014 9:33 am
Level 30 : Artisan Dragon
BUMP!
1
Unlocked
09/26/2014 7:10 pm
Level 30 : Artisan Dragon
bump!
1

Welcome