Skip to content

feature: recipe contract model#9

Open
pollend wants to merge 1 commit intodevelopfrom
feature/contract-model
Open

feature: recipe contract model#9
pollend wants to merge 1 commit intodevelopfrom
feature/contract-model

Conversation

@pollend
Copy link
Member

@pollend pollend commented Mar 15, 2021

What I'm thinking about doing is having a ContractSystem and a list of contracts that drive the types of recipes that a contract can fulfill. A contract will have a representative component that defines the type of crafting with some given inputs and outputs that can be used by other systems to plot out crafting relationships or something of the sort. I'm thinking of basing this on an kind of recursive event model where a contract is registered emits an event and other systems can then react and register their own contracts in response or remove a contract. Contracts are grouped by tags and each group with have a incrementing counter when the group has changed.

A crafting station can subscribe to a group change and update any kind of lookup in response. the contracts only serve of facilitate the recipes and a crafting table will fulfill the request and provide the items. Some basic crafting tables should be offered at a minimum. we can rely on other modules to provide the recipe or setup completely separate contracts. other contracts can be configured by other modules for more extravagant recipes not offered by this module. minigame for like smelting would have a different contract from a shape recipe used in a table.

@RegisterSystem(RegisterMode.AUTHORITY)
public class RecepeiStartSystem extends BaseComponentSystem {
@In
ContractSystem contracts; 

 @Override
    public void preBegin() {
      contracts.register("Basic", new ShapeRecipe("module:recp1"));
      contracts.register("Basic", new ShapeRecipe("module:recp2"));
      contracts.register("Basic", new ShapeRecipe("module:recp3"));
      contracts.register("Basic", new ShapeRecipe("module:recp4"));
    }
    @ReceiveEvent
    public void onContractRegistered(EntityRef entity, ContractRegistered event) {
       if(event.name == "Basic" && contract.... //** some search condition**/){
         contracts.remove("Basic","module:recp1")
         contract.add("Advance", new ShapeRecipe("module:recp5"))
       }
    }
}
(ShapeRecipe(2x2), Basic) 
- A 
- B 
- C
(BasicRecipe(2x2), BasicLarge) 
- A 
(ShapeRecipe(3x3), Advance)
- D
- E
- F

events

  • Contract Registered
  • Contract Removed
  • Contract Group Changed

@pollend pollend changed the title feature: recpie contract model feature: recipe contract model Mar 15, 2021
@skaldarnar
Copy link
Contributor

This sounds very similar to the extension models we tried to implement before, e.g., in AlterationEffects. I think we can find a general model of best practices to encourage a specific way of coding things like this.

One thing that becomes apparent here is that the system is limited to a single group, and I'm wondering whether we can just go down this way, or whether we actually want a more free/generic model:

contracts.register(new ShapeRecipe("module:recp1"), Tags.of("Basic", "Magic"));

Second aspect I'd like to point it is that it would help to have a common library of sorts, which defines a (basic) set of known groups or tags, or at least a common practice on how to make these names available to other modules - using plain strings is (a) quite error prone, and (b) hard to extent/change later on. Referencing constant value from some dependency would definitely help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants