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


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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I may have simply needed to update the import. Sorry about that.
    • I'm using forge-1.17.1-37.0.15-mdk, and the empty project starts without any problems. I have no idea where the problem lies.
    • It happens with Language Support for Java. Because of this error, my code will not be able to resolve the reference. Please help me. Error Messages: ---------------------------------- [Warn  - 9:37:53] 2021/08/01 9:37:53 While loading class "org.eclipse.buildship.core.internal.util.gradle.PublishedGradleVersions$LookupStrategy", thread "Thread[Worker-1: Loading available Gradle versions,5,main]" timed out waiting (30035ms) for thread "Thread[pool-2-thread-1,5,main]" to finish starting bundle "org.eclipse.buildship.core_3.1.5.v20210112-1646-s [14]". To avoid deadlock, thread "Thread[Worker-1: Loading available Gradle versions,5,main]" is proceeding but "org.eclipse.buildship.core.internal.util.gradle.PublishedGradleVersions$LookupStrategy" may not be fully initialized. Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="3.1.5.v20210112-1646-s"; osgi.identity="org.eclipse.buildship.core"; singleton:="true" [id=14] STARTED [STARTED] org.osgi.framework.BundleException: Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="3.1.5.v20210112-1646-s"; osgi.identity="org.eclipse.buildship.core"; singleton:="true" [id=14] STARTED [STARTED]     at org.eclipse.osgi.container.Module.lockStateChange(Module.java:350)     at org.eclipse.osgi.container.Module.start(Module.java:419)     at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:511)     at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117)     at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:572)     at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:345)     at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:401)     at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:480)     at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:170)     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)     at org.eclipse.buildship.core.internal.util.gradle.PublishedGradleVersionsWrapper$LoadVersionsJob.run(PublishedGradleVersionsWrapper.java:60)     at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63) Caused by: java.util.concurrent.TimeoutException: Timeout after waiting 30 seconds to acquire the lock.     at org.eclipse.osgi.container.Module.lockStateChange(Module.java:347)     ... 11 more Caused by: org.eclipse.osgi.framework.util.ThreadInfoReport: Thread dump ... ----------------------------------  
    • Can someone please tell me why this is happening and help me find a solution. thanks. Edit: Nevermind I figured it out.
    • I am trying to store data through my ItemStack capability storage, but I stumbled upon a roadblock. My ItemStack Capability Storage: public class WandItemStorage implements Capability.IStorage<IWandCap> { @Nullable @Override public INBT writeNBT(Capability<IWandCap> capability, IWandCap instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.put("spells", instance.getSpells()); return tag; } @Override public void readNBT(Capability<IWandCap> capability, IWandCap instance, Direction side, INBT nbt) { } } My ItemStack Capability: public class WandCap implements IWandCap { private List<Spell> spells; public WandCap () { spells = new ArrayList<>(); } @Override public List<Spell> getSpells() { return this.spells; } @Override public void addSpells(Spell... spells) { this.spells.addAll(Arrays.asList(spells)); } @Override public void addSpell(Spell spell) { this.spells.add(spell); } @Override public void removeSpells(Spell... spells) { this.spells.removeAll(Arrays.asList(spells)); } @Override public void removeSpell(Spell spell) { this.spells.remove(spell); } @Override public boolean containsSpell(Spell spell) { return this.spells.contains(spell); } } I'm currently trying to put a List of Spells (my custom object) to the Write and Read NBT methods of my ItemStack cap storage, but CompoundNBT doesn't have a method for putting a custom object into a tag. All it has is the put() method from what I'm seeing, however the put() method requires an INBT for the second parameter, which I do not have. Would I need to convert my List of Spells to an INBT, and how would I go about doing that?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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