Posted March 21, 20169 yr So I'm making a mod, and I want a tool that, when mining certain blocks, has the block drop something different (not all blocks, just certain ones). For example, mining block A may drop block A, but mining block B will make it drop item C or block D. Kind of like Twilight Forest's fiery pick, except only for a few specific blocks (not anything with a smelting recipe). How would I go about doing this? Logically I'd go about doing something to the tool's onBlockDestroyed() method, but I don't know exactly what to do about it. And this is not something that I can easily search up modding tutorials for as it is not something commonly attempted. And, if one of the blocks I want to check for is stone, would this code be appropriate for checking if the block is stone? if(block.getIdFromBlock(block) == block.getIdFromBlock(Blocks.stone)) { //drop a different block here } And finally, what would be the code for spawning a dropped item? Not sure if I need it here or not, but I think it may help in the future.
March 21, 20169 yr Author How do I use a HarvestDropsEvent? Do I create a separate class to handle this, or can I put it in the code for my mod pickaxe class?
March 21, 20169 yr Author Thanks, I was able to use the harvesting event to get a block to drop something additional when a specific tool is used. I guess I could look this up but since I'm here, how to I get the event to remove a drop?
March 21, 20169 yr event.drops.clear() It's an array list, use it like one. 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.
March 21, 20169 yr Author Darn it, I've run into another problem. So I created a pickaxe that when mining stone drops my custom block, and has a 25% chance to set the player on fire when mining a block. Code for harvest event below: (Note: some of it is obfuscated with xxxx to keep names a secret) @SubscribeEvent public void xxxxPick(HarvestDropsEvent event) { ItemStack theTool = event.harvester.getCurrentEquippedItem(); if(theTool != null) { if(theTool.getItem() == ToolManager.xxxxPickaxe) { if(random.nextInt(4) == 0) { event.harvester.setFire(5); } if(event.block != null) { if(event.block == Blocks.stone) { event.drops.clear(); event.drops.add(new ItemStack(Item.getItemFromBlock(myBlocksClass.myCustomStone))); } } } } However, occasionally I get a crash report, stating a NullPointerException has occured doing my custom pick event. This really confuses me since I checked to see if both the block and the tool are not null before using them. Example below: // Hi. I'm Minecraft, and I'm a crashaholic. Time: 3/21/16 7:12 PM Description: Exception ticking world java.lang.NullPointerException: Exception ticking world at net.xxxxxx.events.HarvestingEvents.xxxxPick(HarvestingEvents.java:38) at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_HarvestingEvents_xxxxPick_HarvestDropsEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:162) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockBush.checkAndDropBlock(BlockBush.java:74) at net.minecraft.block.BlockBush.updateTick(BlockBush.java:64) at net.minecraft.world.WorldServer.func_147456_g(WorldServer.java:408) at net.minecraft.world.WorldServer.tick(WorldServer.java:191) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:692) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.xxxxxxx.events.HarvestingEvents.xxxxPick(HarvestingEvents.java:38) at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_HarvestingEvents_xxxxPick_HarvestDropsEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:162) at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806) at net.minecraft.block.Block.dropBlockAsItem(Block.java:795) at net.minecraft.block.BlockBush.checkAndDropBlock(BlockBush.java:74) at net.minecraft.block.BlockBush.updateTick(BlockBush.java:64) at net.minecraft.world.WorldServer.func_147456_g(WorldServer.java:408) at net.minecraft.world.WorldServer.tick(WorldServer.java:191) -- Affected level -- Details: Level name: New Worldwq346g344v632v2453v All players: 1 total; [EntityPlayerMP['Player189'/19119, l='New Worldwq346g344v632v2453v', x=-73.43, y=72.00, z=185.88]] Chunk stats: ServerChunkCache: 647 Drop: 0 Level seed: -2949494732709534244 Level generator: ID 00 - default, ver 1. Features enabled: true Level generator options: Level spawn location: World: (-69,64,258), Chunk: (at 11,4,2 in -5,16; contains blocks -80,0,256 to -65,255,271), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) Level time: 25685 game time, 25685 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 117553 (now: false), thunder time: 9149 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:692) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_73, Oracle Corporation Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 626505336 bytes (597 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 4 mods loaded, 4 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJAAAAAAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJAAAAAAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) UCHIJAAAAAAAAA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) UCHIJAAAAAAAAA xxxxxxxx{0.1} [xxxxxxxx] (bin) GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player189'/19119, l='New Worldwq346g344v632v2453v', x=-73.43, y=72.00, z=185.88]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' Any idea what could be causing it? It says "BlockBush" in the crash report somewhere but the crash tends to occur half a minute after breaking a dead bush, if I broke one.
March 21, 20169 yr What is at line 38 of your HarvestingEvents class? "at net.xxxxxx.events.HarvestingEvents.xxxxPick(HarvestingEvents.java:38)" This is saying that the error is on line 38, we'll need to see that line to know what's going on.
March 22, 20169 yr Author ItemStack theTool = event.harvester.getCurrentEquippedItem(); is at line 38.
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.