Posted October 18, 20177 yr Hey everyone, I am new to modding and therefore not so familiar with how i should write my mods, please be gentle I have written this method in an event class and there seems something to be odd about it: first of all: is this the best way to achieve what i want (If the player stands in water, the armor should loose durability)? What i have done seems a bit inperformant.. second: If i try this out everything works as expected but sometimes the durability value increases by 1 even thou it should decrease every time. Is this normal? Thanks in advance, Schottky Here is the code: private static int ticks = 0; private static final LinkedList<Item> DIRT_ARMOR_SET = ModItems.getDirtArmorSet(); @SubscribeEvent public static void armorInFluid(TickEvent.PlayerTickEvent event) { if(ticks == 200) { EntityPlayer player = event.player; if(player.isInWater()) { for(ItemStack armor: player.getArmorInventoryList()) { if(DIRT_ARMOR_SET.contains(armor.getItem())) { int armorDamage = armor.getItemDamage(); if((armor.getMaxDamage() - armorDamage) <= 1) { armor.setCount(0); player.playSound(SoundEvents.ENTITY_ITEM_BREAK, 1.0f, 0); } else { armor.setItemDamage(armorDamage +1); } } } ticks = 0; } } else { ++ticks; } }
October 18, 20177 yr Don't use setItemDamage, instead use damageItem. That allows the item stack to resist the damage (unbreakable) as well as a few other things. Edited October 18, 20177 yr by Draco18s Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
October 18, 20177 yr Author thanks a lot, but still this doesn't solve the problem that the durability decreases but sometimes also increases even thou i have no method that should increase it... any solutions for that?
October 18, 20177 yr The code you posted should never result in that effect. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
October 18, 20177 yr 1 hour ago, Schottky said: thanks a lot, but still this doesn't solve the problem that the durability decreases but sometimes also increases even thou i have no method that should increase it... any solutions for that? stack.damageItem(1, playerIn); should do. Otherwise, if it updates to full durability after it is damaged, you need to execute the method server-side.
October 18, 20177 yr Author hmm here is an example of what i mean... Maybe the error is not in the method i posted but in some other code, maybe where i initialize the armor itself?
October 26, 20177 yr Author Sry for not writing so long! Thank you so much for that tip, after that everything worked as intended (and i hopefully understand now the difference between Client and Server :P) Just one more question: why shouldn't i use LinkedLists's? In this content off it doesn't make a lot of sense but if i want to make something different where i might need Lists, what should i use instead? thx, Schottky
October 26, 20177 yr Use an ArrayList. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.