Jump to content

[1.10.2] [Solved] Chest animation remake doesn't count players in gui


Recommended Posts

Posted

So i'm trying to make a custom chest with an animation heavily inspired by the normal chest code, but it doesn't work. While debugging i noticed that it doesn't detect if players are in the gui, and i can't seem to figure out why... Any help is appreciated!

 

 

 

Some of the important bits of code in my TileEntity:

public float lidAngle = 0;
private int playerCount = 0;
private int ticksSinceSync = 0;


public void update() {
        //System.out.println(playerCount); // <-- ALWAYS 0

        int i = this.pos.getX();
        int j = this.pos.getY();
        int k = this.pos.getZ();
        ++this.ticksSinceSync;

        if (!this.worldObj.isRemote && this.playerCount != 0 && (this.ticksSinceSync + i + j + k) % 200 == 0) {
		playerCount = 0;
		for(EntityPlayer pl : this.worldObj.getEntitiesWithinAABB(
                            EntityPlayer.class, new AxisAlignedBB(
                                this.pos.getX() - 5, this.pos.getY() - 5, 
                                this.pos.getZ() - 5, this.pos.getX() + 5,
                                this.pos.getY() + 5, this.pos.getZ() + 5))) {
                        // wow thats a long line of code

			if(pl.openContainer instanceof ContainerTinyChest) {
				playerCount++;
			}
		}
	}

	if(this.playerCount == 0 && lidAngle > 0.0f || this.playerCount > 0 && lidAngle < 1.0f) {
		if(playerCount > 0) {
			lidAngle += 0.1f;
		} else {
			lidAngle -= 0.1f;
		}

		if(lidAngle > 1.0f) {
			lidAngle = 1.0f;
		}

		if(lidAngle < 0.0f) {
                lidAngle = 0.0f;
            }
	}
}

public boolean receiveClientEvent(int id, int type) {
	//System.out.println("open");
	if(id == 1) {
		playerCount = type;
		return true;
	} else {
		return super.receiveClientEvent(id, type);
	}
}

public void openInventory(EntityPlayer player) {
	if(!player.isSpectator()) {
		if (this.playerCount < 0)
            {
                this.playerCount = 0;
            }

            this.playerCount++;
            this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.playerCount);
	}
}
public void closeInventory(EntityPlayer player) {
	if(!player.isSpectator() && this.getBlockType() instanceof BlockTinyChest) {
            this.playerCount--;
            this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.playerCount);
	}
}

 

 

 

EDIT: found out that

openInventory()

is not called, am i missing something, like that it needs something to be called?

EDIT2: oh yep my feeling was right,

openInventory()

is not automatic, why do i always find solutions after i posted the problem...

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.