Futurecraft Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Futurecraft Forums

A forum dedicated to communication and innovation!
 
HomeLatest imagesSearchRegisterLog in
Welcome, one and all, to the Futurecraft Forums!

 

 Tile Entitys

Go down 
3 posters
AuthorMessage
Danice123
DEV
DEV
Danice123


Posts : 607
Join date : 2012-01-06
Age : 30
Location : The Dankins

Tile Entitys Empty
PostSubject: Tile Entitys   Tile Entitys Icon_minitimeTue 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
Back to top Go down
http://wbcentral.com
ectrimble20
DEV
DEV
ectrimble20


Posts : 441
Join date : 2011-11-07

Tile Entitys Empty
PostSubject: Re: Tile Entitys   Tile Entitys Icon_minitimeWed 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.
Back to top Go down
fr0stbyte124
Super Developrator
Super Developrator
fr0stbyte124


Posts : 1835
Join date : 2011-10-13

Tile Entitys Empty
PostSubject: Re: Tile Entitys   Tile Entitys Icon_minitimeWed 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.
Back to top Go down
Danice123
DEV
DEV
Danice123


Posts : 607
Join date : 2012-01-06
Age : 30
Location : The Dankins

Tile Entitys Empty
PostSubject: Re: Tile Entitys   Tile Entitys Icon_minitimeWed 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...
Back to top Go down
http://wbcentral.com
fr0stbyte124
Super Developrator
Super Developrator
fr0stbyte124


Posts : 1835
Join date : 2011-10-13

Tile Entitys Empty
PostSubject: Re: Tile Entitys   Tile Entitys Icon_minitimeWed 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?
Back to top Go down
Danice123
DEV
DEV
Danice123


Posts : 607
Join date : 2012-01-06
Age : 30
Location : The Dankins

Tile Entitys Empty
PostSubject: Re: Tile Entitys   Tile Entitys Icon_minitimeWed 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...
Back to top Go down
http://wbcentral.com
Sponsored content





Tile Entitys Empty
PostSubject: Re: Tile Entitys   Tile Entitys Icon_minitime

Back to top Go down
 
Tile Entitys
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Futurecraft Forums :: General Area :: Off-Topic Area-
Jump to: