Jump to content

How Do I Change Vanilla Property Values?


peefTube

Recommended Posts

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?

Link to comment
Share on other sites

8 hours ago, 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

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

 

8 hours ago, peefTube said:

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

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

 

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, 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

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

Link to comment
Share on other sites

1 hour ago, peefTube said:

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

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) {
		
	}

 

Link to comment
Share on other sites

5 minutes ago, 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:

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
Link to comment
Share on other sites

1 minute ago, peefTube said:

That NOT including the OR statement, yea?

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

 

Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

The two do exactly the same thing here.

but why? vanilla not overwirte the equals methode

 

29 minutes ago, 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:

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();
			
		}

 

Link to comment
Share on other sites

1 minute ago, 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();
			
		}

 

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.

Link to comment
Share on other sites

37 minutes ago, 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

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
Link to comment
Share on other sites

Just now, 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?

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

Link to comment
Share on other sites

1 minute ago, Luis_ST said:

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

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
Link to comment
Share on other sites

7 minutes ago, peefTube said:

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

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
Link to comment
Share on other sites

15 minutes ago, 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

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.

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