Lambda Posted December 13, 2016 Posted December 13, 2016 Hey there, So I'm in need of dropping an item when a block is broken, I have the event but i need to spawn the item in. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
EscapeMC Posted December 13, 2016 Posted December 13, 2016 Do you want this item to always drop? Or have a random chance from breaking this block? Quote I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But...... https://www.youtube.com/watch?v=6t0GlXWx_PY ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2 TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2 If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.
Lambda Posted December 13, 2016 Author Posted December 13, 2016 Random chance, but know how to handle that Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 13, 2016 Author Posted December 13, 2016 How would I override an event like that? one of the first times messing with them. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
larsgerrits Posted December 13, 2016 Posted December 13, 2016 For your own blocks: override getDrops . For other mods/Minecraft's blocks: use the HarvestDrops event. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Yes like this: @SubscribeEvent public static void HarvestDropsEvent(BlockEvent.HarvestDropsEvent event) { Minecraft mc = Minecraft.getMinecraft(); if(event.getHarvester() instanceof EntityPlayer) { if(!event.isSilkTouching()) { if(event.getDrops() == Blocks.COBBLESTONE) { } } } } So when cobble is dropped I want it to drop the cobble and x Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Draco18s Posted December 14, 2016 Posted December 14, 2016 event.getDrops().add(...) Seriously, look at the event object and see what's there. Quote 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.
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Oh, Yeah figured that out before you commented. Thanks either way... Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Okay this: if(event.getDrops() == Blocks.COBBLESTONE) { event.getDrops().add(new ItemStack(InitBlocks.block_fire_opal_ore)); } seems not to drop when a block drops cobblestone (ex. stone), and also, is there a way to find the block that I'm mining, other than finding the drop? Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Lambda Posted December 14, 2016 Author Posted December 14, 2016 ah yes, so look for a ItemStack like this? if(event.getHarvester() instanceof EntityPlayer) { if(!event.isSilkTouching()) { if(event.getDrops().contains(new ItemStack(Blocks.COBBLESTONE))) { event.getDrops().add(new ItemStack(InitBlocks.block_fire_opal_ore)); } } } However, still doesnt seem to drop Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Draco18s Posted December 14, 2016 Posted December 14, 2016 You can't use contains in this context. ItemStack does not override equals so it will never find a match. Quote 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.
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Then how would I do it, I tried making a list and comparing the list, however didnt seem to work:/ Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Draco18s Posted December 14, 2016 Posted December 14, 2016 for(ItemStack stack : event.getDrops()) { //loop over everyting if(stack.getItem() == Item.getItemFromBlock(Blocks.COBBLESTONE)) { //check if each item is cobblestone } } Quote 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.
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Thanks! However, the random chance thing seems to drop nothing, not even the cobble: if (event.getHarvester() instanceof EntityPlayer) { if (!event.isSilkTouching()) { for(ItemStack stack : event.getDrops()) { if(stack.getItem() == Item.getItemFromBlock(Blocks.COBBLESTONE)) { if(rand.nextInt(2) == 1) { event.getDrops().add(new ItemStack(InitItems.item_gems, 1, 0)); event.getDrops().add(new ItemStack(InitItems.item_gems, 1, 1)); event.getDrops().add(new ItemStack(InitItems.item_gems, 1, 2)); event.getDrops().add(new ItemStack(InitItems.item_gems, 1, 3)); event.getDrops().add(new ItemStack(Blocks.COBBLESTONE, 1)); } event.getDrops().add(new ItemStack(Blocks.COBBLESTONE, 1)); } } } } Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Draco18s Posted December 14, 2016 Posted December 14, 2016 By "not even the cobble" you mean that you're not getting two cobble stone (the statement outside the if(rand) statement)? Quote 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.
Lambda Posted December 14, 2016 Author Posted December 14, 2016 No I added the second one because cobble wasnt even dropping when I added the rand. Even if the rand was false. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Draco18s Posted December 14, 2016 Posted December 14, 2016 Assign it to a variable and print it out or use the debugger to figure out what value is coming out of it every time. Odds are you've messed up initializing your random object. Quote 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.
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Okay, So I seem to be getting this error: [22:05:00] [server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.util.ConcurrentModificationException at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:27) [util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91] Caused by: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) ~[?:1.8.0_91] at java.util.ArrayList$Itr.next(ArrayList.java:851) ~[?:1.8.0_91] at com.lambda.plentifulmisc.events.CommonEvents.HarvestDropsEvent(CommonEvents.java:83) ~[CommonEvents.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_CommonEvents_HarvestDropsEvent_HarvestDropsEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) ~[EventBus.class:?] at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:260) ~[ForgeEventFactory.class:?] at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:692) ~[block.class:?] at net.minecraft.block.Block.dropBlockAsItem(Block.java:681) ~[block.class:?] at net.minecraft.block.Block.harvestBlock(Block.java:889) ~[block.class:?] at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:355) ~[PlayerInteractionManager.class:?] at net.minecraft.server.management.PlayerInteractionManager.blockRemoving(PlayerInteractionManager.java:264) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:664) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) ~[CPacketPlayerDigging.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) ~[CPacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?] ... 5 more [22:05:01] [server thread/ERROR]: Exception caught during firing event net.minecraftforge.event.world.BlockEvent$HarvestDropsEvent@2ae16890: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) ~[?:1.8.0_91] at java.util.ArrayList$Itr.next(ArrayList.java:851) ~[?:1.8.0_91] at com.lambda.plentifulmisc.events.CommonEvents.HarvestDropsEvent(CommonEvents.java:83) ~[CommonEvents.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_CommonEvents_HarvestDropsEvent_HarvestDropsEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) [EventBus.class:?] at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:260) [ForgeEventFactory.class:?] at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:692) [block.class:?] at net.minecraft.block.Block.dropBlockAsItem(Block.java:681) [block.class:?] at net.minecraft.block.Block.harvestBlock(Block.java:889) [block.class:?] at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:355) [PlayerInteractionManager.class:?] at net.minecraft.server.management.PlayerInteractionManager.blockRemoving(PlayerInteractionManager.java:264) [PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:664) [NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) [CPacketPlayerDigging.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) [CPacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) [PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_91] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:26) [util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91] [22:05:01] [server thread/ERROR]: Index: 1 Listeners: [22:05:01] [server thread/ERROR]: 0: NORMAL [22:05:01] [server thread/ERROR]: 1: ASM: class com.lambda.plentifulmisc.events.CommonEvents HarvestDropsEvent(Lnet/minecraftforge/event/world/BlockEvent$HarvestDropsEvent;)V [22:05:01] [server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.util.ConcurrentModificationException at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:27) [util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91] Caused by: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) ~[?:1.8.0_91] at java.util.ArrayList$Itr.next(ArrayList.java:851) ~[?:1.8.0_91] at com.lambda.plentifulmisc.events.CommonEvents.HarvestDropsEvent(CommonEvents.java:83) ~[CommonEvents.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_CommonEvents_HarvestDropsEvent_HarvestDropsEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) ~[EventBus.class:?] at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:260) ~[ForgeEventFactory.class:?] at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:692) ~[block.class:?] at net.minecraft.block.Block.dropBlockAsItem(Block.java:681) ~[block.class:?] at net.minecraft.block.Block.harvestBlock(Block.java:889) ~[block.class:?] at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:355) ~[PlayerInteractionManager.class:?] at net.minecraft.server.management.PlayerInteractionManager.blockRemoving(PlayerInteractionManager.java:264) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:664) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) ~[CPacketPlayerDigging.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) ~[CPacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_91] at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?] ... 5 more On line: for(ItemStack stack : event.getDrops()) { This, however doesnt crash my game. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
MFMods Posted December 14, 2016 Posted December 14, 2016 you can not modify a collection while you are iterating over it. make a local boolean variable hasStoneOrWhatever and fill it if you find whatever. then, outside the loop, use it to decide how to edit the list of item stacks. Quote
Lambda Posted December 14, 2016 Author Posted December 14, 2016 Thanks! That seemed to fix it! Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
Recommended Posts
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.