Jump to content

[1.12.1] Custom Criteria approach, registration and test method


Recommended Posts

Posted (edited)

I'm porting my mods to 1.12.1 and moving achievements to advancements. I understand that many advancements can be implemented just by using JSON, and there are a lot of interesting vanilla triggers, but my advancements are usually more complex. As an example, I've got mobs with their own taming system that don't extend ITameable so the vanilla tame_an_animal trigger won't fire but I want to make similar advancement (taming eagles leads to "falconer" advancement, taming a big cat leads to "lion tamer" advancement). There probably is a way to wrangle NBT to use JSON only, but it is much easier for me just to fire a trigger that doesn't need further testing...

 

So i decided to make my own flexible custom criterion system. It works fine but I'm wondering if I'm reinventing something or if there are other side effects of my approach.

 

My main idea is that I want to fire criteria that don't need testing. In other words, I fire the "tame_bird" using my TAME_BIRD.trigger() method and only pass it the player since that is minimum needed to attach the trigger to the player. Everytime I trigger it will test as true -- no other predicate testing.

 

To make it flexible, I have a single criteria class which has constructor to take in the name (i.e. the "tame_bird") so that associated JSON will work.

 

The JSON is very simple. Just has the display and parent and then associated the criteria with the single trigger.

 

The only hurdle I faced was registering a custom criterion. As far as I could tell, there is no registry event for it and the registry field and the register method on the build-in registry (CriteriaTriggers class) are private. So I used some simple Java Reflection and it worked fine.

 

So everything works -- trigger fires and the advancement works as expected, shows toast message, is displayed in advancement tree, so forth.

 

But I have two questions:

1) Does forge provide a method for registering custom criteria? Any time I use reflection I assume I'm missing out on some hook that already exists...

2) Is there any side effect for not using predicates in my test method? Would it affect my (or resource packs') ability to combine criteria in a more complicated JSON? 

 

Otherwise it is really slick system. I simply register a new instance with new name, trigger it wherever I want in code, and copy a very simple JSON to hook it into the advancement tree.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
1 hour ago, jabelar said:

But I have two questions:

1) Does forge provide a method for registering custom criteria? Any time I use reflection I assume I'm missing out on some hook that already exists...

2) Is there any side effect for not using predicates in my test method? Would it affect my (or resource packs') ability to combine criteria in a more complicated JSON? 

 

Otherwise it is really slick system. I simply register a new instance with new name, trigger it wherever I want in code, and copy a very simple JSON to hook it into the advancement tree.

1) Not currently. However, this works:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/EasyRegistry.java#L210-L222

 

2) Not sure what you mean, but feel free to take a look at some of my criterion
https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/java/com/draco18s/hardlib/api/advancement

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.

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.