Skip to content

Commit

Permalink
Restore single type entity ingredient syntax
Browse files Browse the repository at this point in the history
Same deal as fluid ingredient, help other mods that relied on teh old syntax, though in this case no need to deprecate it. Might want a more general way to do a list or value type field in the future
  • Loading branch information
KnightMiner committed Apr 8, 2024
1 parent a5337b5 commit 0358e1d
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ public abstract class EntityIngredient implements Predicate<EntityType<?>>, IAmL

/** Creates a builder with set and tag */
private static EitherLoadable.TypedBuilder<EntityIngredient> loadableBuilder() {
return EitherLoadable.<EntityIngredient>typed().key("types", SET_MATCH).key("tag", TAG_MATCH);
return EitherLoadable.<EntityIngredient>typed().key("types", SET_MATCH).key("type", ENTRY_MATCH).key("tag", TAG_MATCH);
}
/** Loadable for a single value, notably not used for networking (though that probably would still work fine due to how EitherLoadable works) */
private static final RecordLoadable<EntityIngredient> ENTRY_MATCH = RecordLoadable.create(Loadables.ENTITY_TYPE.requiredField("type", i -> {
Set<EntityType<?>> types = i.getTypes();
if (types.size() == 1) {
return types.iterator().next();
}
throw new IllegalStateException("Cannot use entry match to serialize more than 1 entity");
}), EntityIngredient::of);
/** Loadable for a set match */
private static final RecordLoadable<EntityIngredient> SET_MATCH = RecordLoadable.create(Loadables.ENTITY_TYPE.set().requiredField("types", EntityIngredient::getTypes), EntityIngredient::of);
/** Loadable for a tag match */
Expand Down Expand Up @@ -122,7 +130,7 @@ private static class SetMatch extends EntityIngredient {

@Override
public Loadable<?> loadable() {
return SET_MATCH;
return types.size() == 1 ? ENTRY_MATCH : SET_MATCH;
}

@Override
Expand Down

0 comments on commit 0358e1d

Please sign in to comment.