SureShotM Posted October 21, 2014 Posted October 21, 2014 Before I start I would like to note that I am a bit new to modding more specifically picked it back up, now that that is out of the way here's my question. I am currently having a mob drop my item using the LivingDropsEvent and it is working just fine but I read on how that even already applies if a sword has looting on it and drops more of the item based on that, when i go to test this it is always dropping the random amount that I have it set to in the code but never more based on, well again the looting. Code: [embed=425,349] public class dropHandler { public static double rand; public Random r = new Random(); @ForgeSubscribe public void sropHandler(LivingDropsEvent event) { if(event.entityLiving instanceof EntityOcelot) { if(!((EntityOcelot)entity).ischild)) { rand = Math.Random(); //sets drop rate to 50% if(rand < 0.5D) { //the r.nextInt sets it to drop a random number between 0-4 event.entityLiving.dropItem(ModItem.LionsTooth, r.nextInt(4)); } } } } } [/embed] all help is appreciated ~SureShotM/Leo~ ~SureShotM/Leo~ gaming coding all around fun!
SureShotM Posted October 22, 2014 Author Posted October 22, 2014 Okay so I guess my question would be on how to go by doing that, I have already tried to think of a way to do that but have come up blank, my first initial thought was something like this. [embed=425,349] if(LivingDropsEvent.lootingLevel == 1//not sure what to put here actualy) { //do previous code with different drop value } [/embed] I guess I am not looking in the right place to call the lootingLevel field because its not showing up anywhere for me. Thanks again for the help I apologize for my confusion. ~SureShotM/Leo~ ~SureShotM/Leo~ gaming coding all around fun!
jabelar Posted October 22, 2014 Posted October 22, 2014 Okay so I guess my question would be on how to go by doing that, I have already tried to think of a way to do that but have come up blank, my first initial thought was something like this. [embed=425,349] if(LivingDropsEvent.lootingLevel == 1//not sure what to put here actualy) { //do previous code with different drop value } [/embed] I guess I am not looking in the right place to call the lootingLevel field because its not showing up anywhere for me. Thanks again for the help I apologize for my confusion. ~SureShotM/Leo~ Each event has an instance passed in as a parameter, so you need to get the field from the parameter. In your code the parameter is called event, so you should be checking the value of event.lootingLevel After that, yes, you simply test the value and then code what you want. If looting level is 1, 2, or 3 just test and put code you want. Alternatively you could just multiply the looting level times the quantity to drop more. Anything you want -- it is your code. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
SureShotM Posted October 22, 2014 Author Posted October 22, 2014 Each event has an instance passed in as a parameter, so you need to get the field from the parameter. In your code the parameter is called event, so you should be checking the value of event.lootingLevel After that, yes, you simply test the value and then code what you want. If looting level is 1, 2, or 3 just test and put code you want. Alternatively you could just multiply the looting level times the quantity to drop more. Anything you want -- it is your code. Thank you Thank you Thank you that was exactly what i needed. Here is that updated code for the drops only and something I want to post for future readers. EntityItem dropItem = event.entityLiving.dropItem(ModItems.lionsTooth, 1 * event.lootingLevel + r.nextInt(5)); The above code works perfectly. EntityItem dropItem = event.entityLiving.dropItem(ModItems.lionsTooth, r.nextInt(5)* event.lootingLevel + 1 ); The above code will only read event.lootingLevel + 1 EntityItem dropItem = event.entityLiving.dropItem(ModItems.lionsTooth, r.nextInt(5 * event.lootingLevel + 1)) The above code will crash the game don't know fully why but it does Thanks again for all the help ~SureShotM/Leo~ ~SureShotM/Leo~ gaming coding all around fun!
Recommended Posts