1

Tile entity not seeming to spawn

Unlocked's Avatar Unlocked9/25/14 9:23 pm
10/2/2014 8:14 pm
Unlocked's Avatar Unlocked
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's Avatar
Unlocked
Level 28 : Expert Dragon
10

Create an account or sign in to comment.

11

Karrfis
10/02/2014 7:40 pm
They/Them • Level 35 : Artisan Birb Birb
Karrfis's Avatar
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 28 : Expert Dragon
Unlocked's Avatar
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 28 : Expert Dragon
Unlocked's Avatar
help.... please...
1
Unlocked
10/01/2014 7:20 pm
Level 28 : Expert Dragon
Unlocked's Avatar
BUMP!!!
1
Unlocked
09/30/2014 9:53 pm
Level 28 : Expert Dragon
Unlocked's Avatar
bump
1
_Hellcat_
09/29/2014 8:37 pm
Level 32 : Artisan Toast
_Hellcat_'s Avatar
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 28 : Expert Dragon
Unlocked's Avatar
I would prefer not joke answers.
1
Unlocked
09/29/2014 7:00 pm
Level 28 : Expert Dragon
Unlocked's Avatar
BUMP! Can someone please help?
1
Unlocked
09/28/2014 11:08 am
Level 28 : Expert Dragon
Unlocked's Avatar
Help?
1
Unlocked
09/27/2014 9:33 am
Level 28 : Expert Dragon
Unlocked's Avatar
BUMP!
1
Unlocked
09/26/2014 7:10 pm
Level 28 : Expert Dragon
Unlocked's Avatar
bump!
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome