Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.