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.

Featured Replies

Posted

Hey I was thinking that it could be great if forge can handle these 2 events

 

They would be called when a slot from the player inventory or armor inventory changed

 

Because actually, the only way I found to check armor changes is to check the player stuff every tick, which is quite hardcodded

 

(I hope my English wasn't too awful)

It's not hard to check. PlayerTickEvent or LivingUpdateEvent, with a flag set to true. It would look something like this:

 

private boolean flag = true;

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event)
{
if(event.phase == TickEvent.Phase.START && event.side == Side.SERVER)
{
	if(flag)
	{
		if(event.player.inventory.armorInventory[0] == MyItem)
		{
			flag = false;
			// DO STUFF
		}
	}
	else
	{
		if(event.player.inventory.armorInventory[0] == null)
		{
			flag = true;
		}
	}
}
}

 

This is a very minimal amount of processing required to be done every tick, I doubt it would ever interfere with performance.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

  • Author

public Item[] armor = new Item[4];


public void updateArmor()
{
	 for (int i = 0; i < 4; i++)
	 {
		 ItemStack is = this.player.inventory.armorInventory[i];
		 if (is != null)
		 {
			 Item item = is.getItem();
			 if (item != this.armor[i])
			 {
				 if (item instanceof ItemArmorM)
				 {
                                                  //the player equipped my item
				 }
				 this.armor[i] = item;
			 }	 
		 }
		 else if (is == null && this.armor[i] != null)
		 {
			 if (this.armor[i] instanceof ItemArmorM)
			 {
                                        //The player unequipped my item
			 }
			 this.armor[i] = null;
		 }
	 }		
}

 

I never said this code was hard to made...

 

I'm just suggesting to create this event, which would necessarily improve game performance

 

EDIT: i mean, if a player install 10 armor mods, it is non sense checking this 10 differents times :(

A more effective solution would be:

A. add an event PlayerEvent.armorChangeEvent with properties Item oldArmor, newArmor

B. Post the even in these methods:

  • InventoryPlayer#clearInventory - armor removed
  • InventoryPlayer#copyInventory - armor changed
  • InventoryPlayer#damageArmor - armor removed (if damaged beyond repair)
  • InventoryPlayer#decrStackSize - when stack is armorInventory slot
  • InventoryPlayer#dropAllItems - obviously, armor removed
  • InventoryPlayer#getStackInSlotOnClosing - why this removes armor is a mystery
  • InventoryPlayer#setInventorySlotContents - change, add, or remove
  • InventoryPlayer#readFromNBT - donning armor

 

Then armor can listen for the change and add/remove effects.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

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.