Danice123 DEV
Posts : 607 Join date : 2012-01-06 Age : 30 Location : The Dankins
| Subject: Tile Entitys Tue Jan 10, 2012 10:15 pm | |
| Can anyone tell me how to make this Tile Entity work? I've tried everything, but still the stupid thing returns null... TileEntityPower.java - Code:
-
package net.minecraft.src;
public class TileEntityPower extends TileEntity {
public int level;
public TileEntityPower() { level = 0; }
public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setInteger("level", level); }
public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); level = nbttagcompound.getInteger("level"); if(level < 0) { level = 0; } }
public void changePower(int power) { level = level + power; onInventoryChanged(); } } - Code:
-
created by: world.setBlockTileEntity(i, j, k, new TileEntityPower());
referenced by: TileEntityPower power = (TileEntityPower)world.getBlockTileEntity(i, j, k); int l = power.level;
Mod file has ModLoader.RegisterTileEntity(TileEntityPower.class, "power"); in load() I have no clue... Obviously missing something | |
|
ectrimble20 DEV
Posts : 441 Join date : 2011-11-07
| Subject: Re: Tile Entitys Wed Jan 11, 2012 12:04 am | |
| I'm looking into this, I don't have a lot of experience with the tile entities, will have to dig around a bit.
Just out of curiosity what is referencing the entity and initializing the int l variable to set the power?
I'd have to see how the whole thing works to wrap my head around it.
I'm going to go take a look at the MC entities and see if I can speed learn how they're laid out. | |
|
fr0stbyte124 Super Developrator
Posts : 1835 Join date : 2011-10-13
| Subject: Re: Tile Entitys Wed Jan 11, 2012 1:37 am | |
| I'm not sure. It looks right to me... PM me your test code. I'd like to try it out on my own machine. | |
|
Danice123 DEV
Posts : 607 Join date : 2012-01-06 Age : 30 Location : The Dankins
| Subject: Re: Tile Entitys Wed Jan 11, 2012 8:12 am | |
| I am referencing it from BlockClicked within a Block. I was thinking at first that the x,y, and z were wrong and that it might be searching for the tile entity in the wrong block, but BlockCLicked should return itself... | |
|
fr0stbyte124 Super Developrator
Posts : 1835 Join date : 2011-10-13
| Subject: Re: Tile Entitys Wed Jan 11, 2012 3:32 pm | |
| Found the problem. A tile entity must extend BlockContainer to be treated as a tile entity by the chunk manager. In your case I made BlockPowered extend BlockContainer (which in turn extends Block) and made BlockPowered abstract, since I didn't know what you wanted to do with it. Will that work?
You're also missing a null check in calculateCurrentChanges(). It seems like you should be able to bail out after the first exception, but I couldn't figure out what the code was doing, so maybe not? | |
|
Danice123 DEV
Posts : 607 Join date : 2012-01-06 Age : 30 Location : The Dankins
| Subject: Re: Tile Entitys Wed Jan 11, 2012 4:13 pm | |
| Ohh i see... Thanks a bunch. I do remember seeing something about extending BlockContainer now that I think about it... | |
|
Sponsored content
| Subject: Re: Tile Entitys | |
| |
|