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

[1.14.4] Get list of mod domains


Keheck
 Share

Recommended Posts

5 minutes ago, diesieben07 said:

What are you trying to achieve?

I want to get a list of mod domains so I can read asset data from them. Perferably during mod setup.

I explained in this post why exactly I want to load asset data.

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

Look at how Minecraft loads e.g. recipes. For example: RecipeManager.

Yea yea I already know that, the problem is though that I want to read the data during the mod's setup.

Unless I can still use the ReloadListener system?

Link to comment
Share on other sites

1 hour ago, Keheck said:

Yea yea I already know that, the problem is though that I want to read the data during the mod's setup.

Why there specifically? Anything reliant on data and assets must be able to be reloaded (when datapacks and / or resourcepacks change). That is why the reload listeners are used. Again, see RecipeManager for an example.

Link to comment
Share on other sites

11 hours ago, diesieben07 said:

Why there specifically?

I want to read the data of a FighterEntry while it's being initialized (so during a registry event, in it's constructor), so I can encapsulate the data with no way (except with reflection maybe) to change that data from the outside. I now realize that I don't really need a list of mod domains, since I can just read it's registry name and get the path from there (although maybe I could use the knowledge of getting that list in another I might make)

11 hours ago, diesieben07 said:

Anything reliant on data and assets must be able to be reloaded (when datapacks and / or resourcepacks change)

Is there a way to override this property? I only want to use the data/asset system because of this:

Quote

And since adding such a Fighter would also mean adding moves it can learn, i want other modders to be able to write it in a .json file where they just list the registry names of the moves and my mod picks out the correct moves, so the actual code of the other mods stay rather short and aren't littered with chained methods of adding moves.

Link to comment
Share on other sites

Mods are just data packs. They can change, be disabled and reloaded. If you want to use a data-driven system you have to do it properly.

 

12 minutes ago, Keheck said:

I want to read the data of a FighterEntry while it's being initialized (so during a registry event, in it's constructor), so I can encapsulate the data with no way (except with reflection maybe) to change that data from the outside. I now realize that I don't really need a list of mod domains, since I can just read it's registry name and get the path from there (although maybe I could use the knowledge of getting that list in another I might make)

I have no idea what you are trying to say.

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

I have no idea what you are trying to say.

First of, in analogy to how the registration of Entities are handled, I have two classes: the class io.github.keheck.mobfighters.registry.entries.FighterEntry, which is the equivalent of the EntityEntry class: it is a "pattern" class for individual instanced of a Fighter. Then there is the io.github.keheck.mobfighters.fight.fighters.Fighter class, which is the equivalent of Entity class: It is created via a method inside FighterEntry.

 

The constructor of FighterEntry looks like this:

public FighterEntry(IFighterFactory factory, EntityType<? extends LivingEntity> entityType)
{
    this.factory = factory;
    this.entityType = entityType;
  
    //also, read your fighter-data here.
}

IFighterFactory: This is a functional interface. It is used to create an instance of a new fighter whenever it is needed.

EntityType<...>: This is used so that when a fight is currently going, my mod has information on what the fighter should look like (I want to do a 3D rendered GUI, but that can wait). Why restrict it to instances of LivingEntity? Because only living entities can do stuff, and it made the most sense to me...

 

As for the registry name of the FighterEntry class: I annotated the setRegistryName(ResourceLocation) with @Deprecated, because the getRegistryName method returns the registry name of it's EntityEntry (see constructor).

 

Now to what I am trying to say: I have, in my FighterEntry class, three other fields: two arrays of io.github.keheck.mobfighters.fight.moves.Move instances and one of io.github.keheck.mobfighters.fight.traits.Trait instances. In the constructor (of the FighterEntry class) I want to read a .json file at a specific location, using the registry name of the entityType field. That way, when a FighterEntry gets added to the registry, it automatically retrieves it's information on what moves it can learn and perform.

 

 
 
 
 
Spoiler

In the form of code it would look like this:

 


package io.github.keheck.mobfighters.registry;

//Register the fighter entry
public class Registry
{
  public static void registerFighters(RegistryEvent.Register<FighterEntry> fighterEntryRegister)
  {
      fighterEntryRegister.getRegistry().registerAll
      (new FighterEntry(ExampleFighter::new , EntityEntry.PIG)); //This causes the FighterEntry constructor to be called.
  }
}



package io.github.keheck.mobighters.registry.entries;

//Construct your FighterEntry
public final class FighterEntry implements IForgeRegistryEntry<FighterEntry>
{
  private EntityType<? extends LivingEntity> entityType;  
  private Move[] movePool;
  private Move[] learnPool;
  private Trait[] traits;
  private IFighterFactory factory;
  
  //Remember: entityType == EntityType.Pig
  public FighterEntry(IFighterFactory factory, EntityType<? extends LivingEntity> entityType)
  {
    //assign your fields "factory" and "entityType"
    ResourceLocation data = this.getRegistryName(); //Remember, since the entity type is now assigned we can retreive the FighterEntry's registry name
    
    data = new ResourceLocation
      (
        "minecraft".equals(data.getNamespace()) ? "mobfighters" : data.getNamespace(),  //correct the namespace if it's "minecraft", since that namespace doesn't have the fighter information
        "data/fighters/" + data.getPath() + ".json" //adjust the resource location the the path of the .json file that houses the information (if that's the correct path...)
      );
    
    //magically read data and assign it to movePool, learnPool and traits
  }
}

 

 

Why do I want to do it that way? two reasons:

  1. I want the arrays to be as immutable from the outside as possible. The first step to do that is to make them private (which they are). The second is to make them not change inside any method of the FighterEntry class.
  2. By their nature Moves are very numerous, and Fighters can learn a big number of them (at least, that's what I'm trying to achieve). I don't want modders to waste their time by adding instances of each and every Move they want to add to thier own fighter. Besides that, the code could get *really* long if they add a number of Fighters.

If you want to read the code in it's entierety, here's the github repo.

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



×
×
  • Create New...

Important Information

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