Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.13.2] Set block harvest level and tool without overriding functions


Daniel Rollins
 Share

Recommended Posts

Hi, is there a way to set the block harvest level and tool without having to override the getHarvestTool and getHarvestLevel functions? Basically, how can I set the internal harvestTool and harvestLevel variables? Preferably I would like to be able to set them without putting them in the custom block classes. In my mod I tried to have less actual block classes by basically doing this:

BlockList.new_block1 = new Block(Block.Properties.create(Material.IRON).hardnessAndResistance(20.0F, 27.0F).lightValue(0).sound(SoundType.METAL)).setRegistryName(location("new_block1")) # Using vanilla block class

BlockList.new_block2 = new Block(Block.Properties.create(Material.IRON).hardnessAndResistance(5.0F, 3.0F).lightValue(0).sound(SoundType.METAL)).setRegistryName(location("new_block2")) # Using vanilla block class

or

BlockList.custom_block1 = new CustomBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(5.0F, 1.0F).lightValue(15).sound(SoundType.GLASS)).setRegistryName(location("custom_block1")) # Using custom block class

BlockList.custom_block2= new CustomBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(30.0F, 15.0F).lightValue(0).sound(SoundType.GLASS)).setRegistryName(location("custom_block2")) # Using same custom block class

 

Is there a way to set the harvest info similar to how I set the hardness and resistance so I don't have to create custom classes just for different harvest settings?

 

Thanks

Link to comment
Share on other sites

6 minutes ago, Daniel Rollins said:

Is there a way to set the harvest info similar to how I set the hardness and resistance so I don't have to create custom classes just for different harvest settings?

 

No. In this case a custom block class is acceptable.

 

I mean, the fields are technically not final, just private, so you could use reflection but why?

see https://github.com/MinecraftForge/MinecraftForge/issues/5560 for reasons as to why there isn't a setter.

  • Thanks 1
Link to comment
Share on other sites

Thank you for your reply. If I have to create more classes then I guess I have to but I was wondering if there was anything I could do with this (found in Block Class):

static {
      net.minecraftforge.common.ForgeHooks.setBlockToolSetter((block, tool, level) -> {
         block.harvestTool = tool;
         block.harvestLevel = level;
      });

 

I'm not super great with Java yet so I'm not sure how I would use this or if it would be easier to just create the extra classes.

 

Thanks

Link to comment
Share on other sites

I am only coding for version 1.12.2 and the net.minecraftforge.common.ForgeHooks.setBlockToolSetter() does not seem to exist, so I cannot help you with that. But I do have some alternatives for setting the harvest level without making custom classes (that may or may not work).

First Option:

// First Option
Block option1 = new Block(Material.STONE) {
    @Override
    public int getHarvestLevel(IBlockState state) {
      //Return whatever
    }
};

Second Option:

// Second Option (might not work, never tried this before)
Block option2 = new Block(Material.STONE) {
    private int[] harvestLevel = new int[] {/* Your values here */};
};

Third Option:

// Third Option (might be 1.12.2 only)
Block option3 = new Block(Material.STONE).setHarvestLevel(String, int/*, IBlockState*/);

 

I hope one of these works!

Link to comment
Share on other sites

17 minutes ago, ItsWormy said:

I am only coding for version 1.12.2 and the net.minecraftforge.common.ForgeHooks.setBlockToolSetter() does not seem to exist, so I cannot help you with that.

The OP stated that they are using 1.13.2 in the title.

 

17 minutes ago, ItsWormy said:

First Option:

18 minutes ago, ItsWormy said:

without making custom classes

You are making a custom class in your first option...

 

18 minutes ago, ItsWormy said:

Second Option:

Yeah, this does nothing.

 

18 minutes ago, ItsWormy said:

Third Option:

This is 1.12 only.

 

1 hour ago, Daniel Rollins said:

Thank you for your reply. If I have to create more classes then I guess I have to but I was wondering if there was anything I could do with this (found in Block Class):

This is an internal forge hook for setting harvest tool/level for vanilla blocks. The method even says that modders shouldn't use it so...

Link to comment
Share on other sites

14 minutes ago, V0idWa1k3r said:

The OP stated that they are using 1.13.2 in the title.

 

That is why I stated that I used 1.12.2

14 minutes ago, V0idWa1k3r said:

This is 1.12 only.

And I said that it might only exist for 1.12.2

 

Edit: I thank you for the feedback about the other options though, I had no idea what the second one would do. And I had no idea that the first option was considered making a new custom class.

Edited by ItsWormy
Link to comment
Share on other sites

2 hours ago, V0idWa1k3r said:

This is an internal forge hook for setting harvest tool/level for vanilla blocks. The method even says that modders shouldn't use it so...

 

Sorry, didn't see that. I'll just go with more classes and using the getHarvestLevel & getHarvestTool methods. Thank you

Link to comment
Share on other sites

4 hours ago, ItsWormy said:

without making custom classes

Options 1 & 2 are making new anonymous classes. Anonymous classes are custom classes

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • 1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • ---- Minecraft Crash Report ---- WARNING: coremods are present:   TransformLoader (DynamicSurroundings-1.12.2-3.6.1.0.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   MovingWorldCore (movingworld-1.12-6.353-full.jar)   Quark Plugin (Quark-r1.6-179.jar)   CorePlugin (ForgeEndertech-1.12.2-4.5.5.0-build.0561.jar)   CTMCorePlugin (CTM-MC1.12.2-1.0.2.31.jar)   FarseekCoreMod (Farseek-1.12-2.5.1.jar)   FutureMC (future-mc-1.12.2-0.2.6.1.jar) Contact their authors BEFORE contacting forge // Surprise! Haha. Well, this is awkward. Time: 9/20/21 10:59 AM Description: Ticking block entity java.lang.NullPointerException: Ticking block entity     at net.minecraftforge.fluids.FluidStack.<init>(FluidStack.java:72)     at ic2.core.block.transport.TileEntityFluidPipe$PipeFluidHandler.drain(TileEntityFluidPipe.java:350)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:332)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:323)     at ic2.core.block.machine.tileentity.TileEntityPump.pump(TileEntityPump.java:204)     at ic2.core.block.machine.tileentity.TileEntityPump.operate(TileEntityPump.java:177)     at ic2.core.block.machine.tileentity.TileEntityPump.canoperate(TileEntityPump.java:146)     at ic2.core.block.machine.tileentity.TileEntityPump.updateEntityServer(TileEntityPump.java:123)     at ic2.core.block.TileEntityBlock.func_73660_a(TileEntityBlock.java:326)     at net.minecraft.world.World.func_72939_s(World.java:1838)     at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613)     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)     at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace:     at net.minecraftforge.fluids.FluidStack.<init>(FluidStack.java:72)     at ic2.core.block.transport.TileEntityFluidPipe$PipeFluidHandler.drain(TileEntityFluidPipe.java:350)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:332)     at ic2.core.util.LiquidUtil.drainTile(LiquidUtil.java:323)     at ic2.core.block.machine.tileentity.TileEntityPump.pump(TileEntityPump.java:204)     at ic2.core.block.machine.tileentity.TileEntityPump.operate(TileEntityPump.java:177)     at ic2.core.block.machine.tileentity.TileEntityPump.canoperate(TileEntityPump.java:146)     at ic2.core.block.machine.tileentity.TileEntityPump.updateEntityServer(TileEntityPump.java:123)     at ic2.core.block.TileEntityBlock.func_73660_a(TileEntityBlock.java:326) -- Block entity being ticked -- Details:     Name: ic2:pump // ic2.core.block.machine.tileentity.TileEntityPump     Block type: ID #388 (ic2.te // ic2.core.block.BlockTileEntity // ic2:te)     Block data value: 1 / 0x1 / 0b0001     Block location: World: (137,34,-88), Chunk: (at 9,2,8 in 8,-6; contains blocks 128,0,-96 to 143,255,-81), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)     Actual block type: ID #388 (ic2.te // ic2.core.block.BlockTileEntity // ic2:te)     Actual block data value: 1 / 0x1 / 0b0001 Stacktrace:     at net.minecraft.world.World.func_72939_s(World.java:1838)     at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613) -- Affected level -- Details:     Level name: world     All players: 1 total; [EntityPlayerMP['ZtiromDE'/383, l='world', x=136.18, y=35.14, z=-88.54]]     Chunk stats: ServerChunkCache: 137 Drop: 0     Level seed: 6427110845652378783     Level generator: ID 00 - default, ver 1. Features enabled: false     Level generator options:     Level spawn location: World: (0,0,0), Chunk: (at 0,0,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)     Level time: 0 game time, 0 day time     Level dimension: 0     Level storage version: 0x00000 - Unknown?     Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)     Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false Stacktrace:     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)     at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source) -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_301, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 2877134552 bytes (2743 MB) / 4130340864 bytes (3939 MB) up to 8388608000 bytes (8000 MB)     JVM Flags: 1 total; -Xmx9000M     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 7     FML: MCP 9.42 Powered by Forge 14.23.5.2854 58 mods loaded, 58 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State  | ID                                           | Version            | Source                                        | Signature                                |     |:------ |:-------------------------------------------- |:------------------ |:--------------------------------------------- |:---------------------------------------- |     | LCHIJA | minecraft                                    | 1.12.2             | minecraft.jar                                 | None                                     |     | LCHIJA | mcp                                          | 9.42               | minecraft.jar                                 | None                                     |     | LCHIJA | FML                                          | 8.0.99.99          | server.jar                                    | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | forge                                        | 14.23.5.2854       | server.jar                                    | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | com.elytradev.movingworld.common.asm.coremod |                    | minecraft.jar                                 | None                                     |     | LCHIJA | forgeendertech                               | 1.12.2-4.5.5.0     | ForgeEndertech-1.12.2-4.5.5.0-build.0561.jar  | None                                     |     | LCHIJA | adpoles                                      | 1.12.2-2.0.3.0     | AdPoles-1.12.2-2.0.3.0-build.0552.jar         | None                                     |     | LCHIJA | crafttweaker                                 | 4.1.20             | CraftTweaker2-1.12-4.1.20.660.jar             | None                                     |     | LCHIJA | jei                                          | 4.16.1.301         | jei_1.12.2-4.16.1.301.jar                     | None                                     |     | LCHIJA | quark                                        | r1.6-179           | Quark-r1.6-179.jar                            | None                                     |     | LCHIJA | autoreglib                                   | 1.3-32             | AutoRegLib-1.3-32.jar                         | None                                     |     | LCHIJA | biomesoplenty                                | 7.0.1.2441         | BiomesOPlenty-1.12.2-7.0.1.2441-universal.jar | None                                     |     | LCHIJA | bookshelf                                    | 2.3.590            | Bookshelf-1.12.2-2.3.590.jar                  | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | chisel                                       | MC1.12.2-1.0.2.45  | Chisel-MC1.12.2-1.0.2.45.jar                  | None                                     |     | LCHIJA | chiselsandbits                               | 14.33              | chiselsandbits-14.33.jar                      | None                                     |     | LCHIJA | clumps                                       | 3.1.2              | Clumps-3.1.2.jar                              | None                                     |     | LCHIJA | collective                                   | 2.64               | collective-1.12.2-2.64.jar                    | None                                     |     | LCHIJA | cosmeticarmorreworked                        | 1.12.2-v5a         | CosmeticArmorReworked-1.12.2-v5a.jar          | aaaf83332a11df02406e9f266b1b65c1306f0f76 |     | LCHIJA | crafttweakerjei                              | 2.0.3              | CraftTweaker2-1.12-4.1.20.660.jar             | None                                     |     | LCHIJA | movingworld                                  | 1.12-6.353         | movingworld-1.12-6.353-full.jar               | None                                     |     | LCHIJA | davincisvessels                              | @DVESSELSVER@      | davincisvessels-1.12-6.340-full.jar           | None                                     |     | LCHIJA | orelib                                       | 3.6.0.1            | OreLib-1.12.2-3.6.0.1.jar                     | 7a2128d395ad96ceb9d9030fbd41d035b435753a |     | LCHIJA | dsurround                                    | 3.6.1.0            | DynamicSurroundings-1.12.2-3.6.1.0.jar        | 7a2128d395ad96ceb9d9030fbd41d035b435753a |     | LCHIJA | farseek                                      | 2.5.1              | Farseek-1.12-2.5.1.jar                        | None                                     |     | LCHIJA | forgelin                                     | 1.8.4              | Forgelin-1.8.4.jar                            | None                                     |     | LCHIJA | futuremc                                     | 0.2.6              | future-mc-1.12.2-0.2.6.1.jar                  | None                                     |     | LCHIJA | gamestages                                   | 2.0.123            | GameStages-1.12.2-2.0.123.jar                 | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | geographicraft                               | 0.8.7              | GeographiCraft-1.12-0.8.9b.jar                | None                                     |     | LCHIJA | grapplemod                                   | 1.12.2-v11.1       | grapplemod-v11.1-1.12.2.jar                   | None                                     |     | LCHIJA | gravestone                                   | 1.10.3             | gravestone-1.10.3.jar                         | None                                     |     | LCHIJA | happytrails                                  | 1.0.0.5            | HappyTrails-1.12.2-1.0.0.5.jar                | None                                     |     | LCHIJA | waila                                        | 1.8.26             | Hwyla-1.8.26-B41_1.12.2.jar                   | None                                     |     | LCHIJA | ichunutil                                    | 7.2.2              | iChunUtil-1.12.2-7.2.2.jar                    | 4db5c2bd1b556f252a5b8b54b256d381b2a0a6b8 |     | LCHIJA | ido                                          | 1.0.6              | ido-1.12.2-1.1.0.jar                          | None                                     |     | LCHIJA | ic2                                          | 2.8.170-ex112      | industrialcraft-2-2.8.170-ex112.jar           | de041f9f6187debbc77034a344134053277aa3b0 |     | LCHIJA | mantle                                       | 1.12-1.3.3.55      | Mantle-1.12-1.3.3.55.jar                      | None                                     |     | LCHIJA | inspirations                                 | 1.12.2-0.2.9       | Inspirations-1.12.2-0.2.9.jar                 | None                                     |     | LCHIJA | ironchest                                    | 1.12.2-7.0.67.844  | ironchest-1.12.2-7.0.72.847.jar               | None                                     |     | LCHIJA | journeymap                                   | 1.12.2-5.7.1       | journeymap-1.12.2-5.7.1.jar                   | None                                     |     | LCHIJA | guilib                                       | $version           | morepaintings-paintings-1.12.2-5.0.1.2.jar    | None                                     |     | LCHIJA | paintingselgui                               | $version           | morepaintings-paintings-1.12.2-5.0.1.2.jar    | None                                     |     | LCHIJA | morepaintings                                | $version           | morepaintings-paintings-1.12.2-5.0.1.2.jar    | None                                     |     | LCHIJA | naturescompass                               | 1.8.5              | NaturesCompass-1.12.2-1.8.5.jar               | None                                     |     | LCHIJA | netherendingores                             | 1.12.2-1.4.2       | Netherending-Ores-1.12.2-1.4.2.jar            | None                                     |     | LCHIJA | examplemod                                   | 1.0                | NuclearCraft-2.18z-1.12.2.jar                 | None                                     |     | LCHIJA | nuclearcraft                                 | 2.18z              | NuclearCraft-2.18z-1.12.2.jar                 | None                                     |     | LCHIJA | pixelmon                                     | 8.2.0              | Pixelmon-1.12.2-8.2.0-universal.jar           | None                                     |     | LCHIJA | placeableitems                               | 3.3                | placeableitems-3.3.jar                        | None                                     |     | LCHIJA | refinedstorage                               | 1.6.16             | refinedstorage-1.6.16.jar                     | 57893d5b90a7336e8c63fe1c1e1ce472c3d59578 |     | LCHIJA | spartanshields                               | 1.5.4              | SpartanShields-1.12.2-1.5.4.jar               | None                                     |     | LCHIJA | spartanweaponry                              | beta 1.3.8         | SpartanWeaponry-1.12.2-beta-1.3.8.jar         | None                                     |     | LCHIJA | streams                                      | 0.4.9              | Streams-1.12-0.4.9.jar                        | None                                     |     | LCHIJA | tinymobfarm                                  | 1.0.5              | TinyMobFarm-1.12.2-1.0.5.jar                  | None                                     |     | LCHIJA | travelersbackpack                            | 1.0.35             | TravelersBackpack-1.12.2-1.0.35.jar           | None                                     |     | LCHIJA | treeharvester                                | 3.2                | treeharvester_1.12.2-3.2.jar                  | None                                     |     | LCHIJA | wailastages                                  | 2.0.23             | WailaStages-1.12.2-2.0.23.jar                 | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | waystones                                    | 4.1.0              | Waystones_1.12.2-4.1.0.jar                    | None                                     |     | LCHIJA | rtg                                          | 6.1.0.0-snapshot.1 | RTG-1.12.2-6.1.0.0-snapshot.1.jar             | None                                     |     Loaded coremods (and transformers): TransformLoader (DynamicSurroundings-1.12.2-3.6.1.0.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   MovingWorldCore (movingworld-1.12-6.353-full.jar)   Quark Plugin (Quark-r1.6-179.jar)   vazkii.quark.base.asm.ClassTransformer CorePlugin (ForgeEndertech-1.12.2-4.5.5.0-build.0561.jar)   CTMCorePlugin (CTM-MC1.12.2-1.0.2.31.jar)   team.chisel.ctm.client.asm.CTMTransformer FarseekCoreMod (Farseek-1.12-2.5.1.jar)   farseek.core.FarseekClassTransformer FutureMC (future-mc-1.12.2-0.2.6.1.jar)   thedarkcolour.futuremc.asm.CoreTransformer     Pulsar/inspirations loaded Pulses:         - InspirationsShared (Enabled/Forced)         - InspirationsBuilding (Enabled/Not Forced)         - InspirationsUtility (Enabled/Not Forced)         - InspirationsTools (Enabled/Not Forced)         - InspirationsRecipes (Enabled/Not Forced)         - InspirationsTweaks (Enabled/Not Forced)         - InspirationsShared (Enabled/Forced)         - WailaPlugin (Enabled/Not Forced)     Profiler Position: N/A (disabled)     Player Count: 2 / 20; [EntityPlayerMP['T3rm1n6t0r'/17, l='world', x=9.98, y=73.00, z=99.44], EntityPlayerMP['ZtiromDE'/383, l='world', x=136.18, y=35.14, z=-88.54]]     Is Modded: Definitely; Server brand changed to 'fml,forge'     Type: Dedicated Server (map_server.txt)
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.