1
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)
Block code
Tile entity code
Thanks for any help.
-Unlocked
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
Create an account or sign in to comment.
11
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
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.
help.... please...
BUMP!!!
bump
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
I would prefer not joke answers.
BUMP! Can someone please help?
Help?
BUMP!
bump!