Posted August 30, 201411 yr 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)
August 30, 201411 yr 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. If you don't know basic Java yet, go and follow these tutorials.
August 30, 201411 yr 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
September 5, 201411 yr 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. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
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.