Jump to content

Recommended Posts

Posted

I'm working on a new mod, but I've become insistent upon extending the progression tree. Doing this, however, would require modifying a few different enums as well as changing the properties of multiple blocks and items to match.
I have limited experience with Java, I do have experience, but not nearly enough to know how to modify these values.

What I want to do, explicitly, is this:

  • Modify harvest levels of blocks and tool tiers to insert new tiers in between for certain ores, creating a more Terraria-like progression
  • Potentially override vanilla values with modded ones, without forcibly prying into the vanilla values to modify them on loadup

 

Any clues as to how to accomplish either or both of these tasks?

Posted
  On 2/20/2021 at 1:30 AM, peefTube said:

Modify harvest levels of blocks and tool tiers to insert new tiers in between for certain ores, creating a more Terraria-like progression

Expand  

you can use events to modify blocks and tools

- PlayerEvent#HarvestCheck -> harvestLevel
- PlayerEvent#BreakSpeed -> breakSpeed
- LivingDamageEvent -> damage of tools
- LivingEntityUseItemEvent -> durablity

read the description of the events for more information about the function of the events and what they do

 

  On 2/20/2021 at 1:30 AM, peefTube said:

Potentially override vanilla values with modded ones, without forcibly prying into the vanilla values to modify them on loadup

Expand  

what kind of values do you mean exactly can you give an example of that what you want to change?

 

  • Thanks 1
Posted
  On 2/20/2021 at 9:39 AM, Luis_ST said:

what kind of values do you mean exactly can you give an example of that what you want to change?

Expand  

I want to change specifically the values already mentioned, though what you've provided solves both questions, so thank you!

Posted
  On 2/20/2021 at 9:39 AM, Luis_ST said:

you can use events to modify blocks and tools

- PlayerEvent#HarvestCheck -> harvestLevel
- PlayerEvent#BreakSpeed -> breakSpeed
- LivingDamageEvent -> damage of tools
- LivingEntityUseItemEvent -> durablity

read the description of the events for more information about the function of the events and what they do

Expand  

I'm working with events but I cannot figure out for the life of me how to access harvestLevel or breakSpeed :/

Posted
  On 2/20/2021 at 12:29 PM, peefTube said:

I'm working with events but I cannot figure out for the life of me how to access harvestLevel or breakSpeed

Expand  

do you mean how you use the event?

then use this:

	@SubscribeEvent
	public static void HarvestCheck(PlayerEvent.HarvestCheck event) {
		
	}
	
	@SubscribeEvent
	public static void BreakSpeed(PlayerEvent.BreakSpeed event) {
		
	}

 

Posted (edited)
  On 2/21/2021 at 11:05 AM, peefTube said:

Well, now I've made progress thanks to the help of the Slimeknights server
But I have these two files and the latter is not running when called:

Expand  

do not use:

item.getItem().equals(Items.WOODEN_PICKAXE) || item.getItem().equals(Items.GOLDEN_PICKAXE)

use instead:

item.getItem() == Items.WOODEN_PICKAXE

 

Edit: that should fix your problem

Edited by Luis_ST
Posted (edited)

That NOT including the OR statement, yea?
Regardless, that wouldn't change anything. It acknowledges things this way just fine.

Edited by peefTube
Posted
  On 2/21/2021 at 11:14 AM, peefTube said:

That NOT including the OR statement, yea?

Expand  

no no no.

the equals method comes from the java object class and minecrft item class does not overwrite this method

so again don't use:

item.getItem().equals(Items.WOODEN_PICKAXE) || item.getItem().equals(Items.GOLDEN_PICKAXE)

use instead:

item.getItem() == Items.WOODEN_PICKAXE || item.getItem() == Items.GOLDEN_PICKAXE

 

Posted
  On 2/21/2021 at 11:23 AM, diesieben07 said:

The two do exactly the same thing here.

Expand  

but why? vanilla not overwirte the equals methode

 

  On 2/21/2021 at 11:05 AM, peefTube said:

Well, now I've made progress thanks to the help of the Slimeknights server
But I have these two files and the latter is not running when called:

Expand  

I think there is still a better way.

check whether the item is an instance of AxeItem / PickaxeItem / ShovelItem

then your vanillaToolTier sets to: ItemInstance#getTier#getHarvestLevel so like this:

you then have to set the ToolType

		Item item = player.getHeldItemMainhand().getItem();
		int vanillaToolTier = 0;
		
		if (item instanceof PickaxeItem) {
			
			vanillaToolTier = ((PickaxeItem) item).getTier().getHarvestLevel();
			
		} else if (item instanceof AxeItem) {
			
			vanillaToolTier = ((AxeItem) item).getTier().getHarvestLevel();
			
		} else if (item instanceof ShovelItem) {
			
			vanillaToolTier = ((ShovelItem) item).getTier().getHarvestLevel();
			
		}

 

Posted
  On 2/21/2021 at 11:43 AM, Luis_ST said:

I think there is still a better way.

check whether the item is an instance of AxeItem / PickaxeItem / ShovelItem

then your vanillaToolTier sets to: ItemInstance#getTier#getHarvestLevel so like this:

you then have to set the ToolType

		Item item = player.getHeldItemMainhand().getItem();
		int vanillaToolTier = 0;
		
		if (item instanceof PickaxeItem) {
			
			vanillaToolTier = ((PickaxeItem) item).getTier().getHarvestLevel();
			
		} else if (item instanceof AxeItem) {
			
			vanillaToolTier = ((AxeItem) item).getTier().getHarvestLevel();
			
		} else if (item instanceof ShovelItem) {
			
			vanillaToolTier = ((ShovelItem) item).getTier().getHarvestLevel();
			
		}

 

Expand  

This is completely ignoring the issue I'm running into. The method being called to my reflection file is not actually being called. It's simply not running.

Posted
  On 2/21/2021 at 11:45 AM, peefTube said:

This is completely ignoring the issue I'm running into. The method being called to my reflection file is not actually being called. It's simply not running.

Expand  

I'm trying to understand your code and why it doesn't work

Posted (edited)
  On 2/21/2021 at 11:45 AM, peefTube said:

This is completely ignoring the issue I'm running into. The method being called to my reflection file is not actually being called. It's simply not running

Expand  

sorry but i have to ask that. what do you want to change with the posted code?
if I understand correctly you check whether the tool is a gold pickaxe in the player's hand then you set the block harvest level to 1 so that the player can destroy the block

Am I right?

Edited by Luis_ST
Posted
  On 2/21/2021 at 12:22 PM, Luis_ST said:

sorry but i have to ask that. what do you want to change with the posted code?
if I understand correctly you check whether the tool is a gold pickaxe in the player's hand then you set the block harvest level to 1 so that the player can destroy the block

Am I right?

Expand  

I don't want to change anything unless it fixes the error of the setToolHL() call not actually doing anything, which it absolutely should be doing something

Posted
  On 2/21/2021 at 12:25 PM, peefTube said:

I don't want to change anything unless it fixes the error of the setToolHL() call not actually doing anything, which it absolutely should be doing something

Expand  

then i try to understand the setToolHL method and to fix the error

Posted (edited)
  On 2/21/2021 at 12:32 PM, Luis_ST said:

then i try to understand the setToolHL method and to fix the error

Expand  

No need, it just started working and I have zero clue why because I changed none of the functionality

UPDATE: Just removed something I'd added (a console printline) and for whatever stupid reason, that broke it again. Absolutely no clue why this is behaving this way but I'm certainly getting a laugh out of it.

Edited by peefTube
learned something
Posted (edited)
  On 2/21/2021 at 12:33 PM, peefTube said:

No need, it just started working and I have zero clue why because I changed none of the functionality

Expand  

But you should use ObfuscationReflectionHelper to get the fields and use the SRG names

 

Edit: You should definitely use SRG names otherwise your code won't work outside of the IDE

Edited by Luis_ST
Posted
  On 2/21/2021 at 12:36 PM, Luis_ST said:

But you should use ObfuscationReflectionHelper to get the fields and use the SRG names

 

Edit: You should definitely use SRG names otherwise your code won't work outside of the IDE

Expand  

Well, I may look into that later. For now, I have finally determined the cause as one specific oversight:

        if(vanillaToolTier >= vanillaBlockTier)
        {

This single line was keeping my code from running with a gold tool on iron ore, thus rendering the code useless. I have since removed it.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.