fix adv and reg
This commit is contained in:
@@ -18,7 +18,7 @@ loader_version_range=[2,)
|
|||||||
mod_id=l2core
|
mod_id=l2core
|
||||||
mod_name=L2Core
|
mod_name=L2Core
|
||||||
mod_license=LGPL-2.1
|
mod_license=LGPL-2.1
|
||||||
mod_version=3.0.2-pre3
|
mod_version=3.0.2-pre6
|
||||||
mod_group_id=dev.xkmc
|
mod_group_id=dev.xkmc
|
||||||
mod_authors=lcy0x1
|
mod_authors=lcy0x1
|
||||||
mod_description=Core Library mod for all L2 mods
|
mod_description=Core Library mod for all L2 mods
|
||||||
@@ -26,7 +26,7 @@ mod_description=Core Library mod for all L2 mods
|
|||||||
|
|
||||||
jei_minecraft_version = 1.21-neoforge
|
jei_minecraft_version = 1.21-neoforge
|
||||||
jei_version = 19.0.0.7
|
jei_version = 19.0.0.7
|
||||||
registrate_version = MC1.21-1.4.0
|
registrate_version = MC1.21-1.4.1
|
||||||
|
|
||||||
lljij = false
|
lljij = false
|
||||||
rootMod = false
|
rootMod = false
|
||||||
|
|||||||
BIN
libs/Registrate-MC1.21-1.4.1-sources.jar
Normal file
BIN
libs/Registrate-MC1.21-1.4.1-sources.jar
Normal file
Binary file not shown.
Binary file not shown.
@@ -20,8 +20,6 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public final class Reg {
|
public final class Reg {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final String modid;
|
private final String modid;
|
||||||
|
|
||||||
private final Map<Registry<?>, DeferredRegister<?>> map = new LinkedHashMap<>();
|
private final Map<Registry<?>, DeferredRegister<?>> map = new LinkedHashMap<>();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public record SR<T>(DeferredRegister<T> reg) {
|
|||||||
return new SR<>(parent.make(reg));
|
return new SR<>(parent.make(reg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Val<T> reg(String id, Supplier<T> sup) {
|
public <H extends T> Val<H> reg(String id, Supplier<H> sup) {
|
||||||
return new ValImpl<>(reg.register(id, sup));
|
return new ValImpl<>(reg.register(id, sup));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,85 +7,87 @@ import net.minecraft.advancements.AdvancementType;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.neoforged.neoforge.common.conditions.ICondition;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class AdvancementGenerator {
|
public class AdvancementGenerator {
|
||||||
|
|
||||||
private final RegistrateAdvancementProvider pvd;
|
private final RegistrateAdvancementProvider pvd;
|
||||||
private final String modid;
|
private final String modid;
|
||||||
|
|
||||||
public AdvancementGenerator(RegistrateAdvancementProvider pvd, String modid) {
|
public AdvancementGenerator(RegistrateAdvancementProvider pvd, String modid) {
|
||||||
this.pvd = pvd;
|
this.pvd = pvd;
|
||||||
this.modid = modid;
|
this.modid = modid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TabBuilder {
|
public class TabBuilder {
|
||||||
|
|
||||||
private final String tab;
|
private final String tab;
|
||||||
private final ResourceLocation bg;
|
private final ResourceLocation bg;
|
||||||
|
|
||||||
private Entry root;
|
private Entry root;
|
||||||
|
|
||||||
public TabBuilder(String tab) {
|
public TabBuilder(String tab) {
|
||||||
this.tab = tab;
|
this.tab = tab;
|
||||||
this.bg = ResourceLocation.fromNamespaceAndPath(modid, "textures/gui/advancements/backgrounds/" + tab + ".png");
|
this.bg = ResourceLocation.fromNamespaceAndPath(modid, "textures/gui/advancements/backgrounds/" + tab + ".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build() {
|
public void build() {
|
||||||
root.build();
|
root.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry root(String id, Item item, CriterionBuilder builder, String title, String desc) {
|
public Entry root(String id, Item item, CriterionBuilder builder, String title, String desc) {
|
||||||
return root(id, item.getDefaultInstance(), builder, title, desc);
|
return root(id, item.getDefaultInstance(), builder, title, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry root(String id, ItemStack item, CriterionBuilder builder, String title, String desc) {
|
public Entry root(String id, ItemStack item, CriterionBuilder builder, String title, String desc) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = new Entry(new EntryData(id, item, builder, title, desc), null);
|
root = new Entry(new EntryData(id, item, builder, title, desc), null);
|
||||||
}
|
}
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry hidden(String id, CriterionBuilder builder) {
|
public Entry hidden(String id, CriterionBuilder builder) {
|
||||||
return new Entry(new EntryData(id, ItemStack.EMPTY, builder, "", ""), null);
|
return new Entry(new EntryData(id, ItemStack.EMPTY, builder, "", ""), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Entry {
|
public class Entry {
|
||||||
|
|
||||||
private final List<Entry> children = new ArrayList<>();
|
private final List<Entry> children = new ArrayList<>();
|
||||||
private final EntryData data;
|
private final EntryData data;
|
||||||
private final ResourceLocation rl;
|
private final ResourceLocation rl;
|
||||||
private final Entry parent;
|
private final Entry parent;
|
||||||
|
|
||||||
private AdvancementType type = AdvancementType.TASK;
|
private AdvancementType type = AdvancementType.TASK;
|
||||||
private boolean showToast = true, announce = true, hidden = false;
|
private boolean showToast = true, announce = true, hidden = false;
|
||||||
private AdvancementHolder result;
|
private AdvancementHolder result;
|
||||||
|
|
||||||
private Entry(EntryData data, @Nullable Entry parent) {
|
private Entry(EntryData data, @Nullable Entry parent) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
showToast = false;
|
showToast = false;
|
||||||
announce = false;
|
announce = false;
|
||||||
rl = bg;
|
rl = bg;
|
||||||
} else {
|
} else {
|
||||||
rl = null;
|
rl = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry create(String id, Item item, CriterionBuilder builder, String title, String desc) {
|
public Entry create(String id, Item item, CriterionBuilder builder, String title, String desc) {
|
||||||
return create(id, item.getDefaultInstance(), builder, title, desc);
|
return create(id, item.getDefaultInstance(), builder, title, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry create(String id, ItemStack item, CriterionBuilder builder, String title, String desc) {
|
public Entry create(String id, ItemStack item, CriterionBuilder builder, String title, String desc) {
|
||||||
Entry sub = new Entry(new EntryData(id, item, builder, title, desc), this);
|
Entry sub = new Entry(new EntryData(id, item, builder, title, desc), this);
|
||||||
children.add(sub);
|
children.add(sub);
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*TODO
|
/*TODO
|
||||||
public Entry patchouli(L2Registrate reg, CriterionBuilder builder, ResourceLocation book, String title, String desc) {
|
public Entry patchouli(L2Registrate reg, CriterionBuilder builder, ResourceLocation book, String title, String desc) {
|
||||||
@@ -95,69 +97,72 @@ public class AdvancementGenerator {
|
|||||||
.add(new RewardBuilder(reg, 0, book, () -> PatchouliHelper.getBookLoot(book)));
|
.add(new RewardBuilder(reg, 0, book, () -> PatchouliHelper.getBookLoot(book)));
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public Entry root() {
|
public Entry root() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry enter() {
|
public Entry enter() {
|
||||||
return children.getLast();
|
return children.getLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry type(AdvancementType type) {
|
public Entry type(AdvancementType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry type(AdvancementType type, boolean showToast, boolean announce, boolean hidden) {
|
public Entry type(AdvancementType type, boolean showToast, boolean announce, boolean hidden) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.showToast = showToast;
|
this.showToast = showToast;
|
||||||
this.announce = announce;
|
this.announce = announce;
|
||||||
this.hidden = hidden;
|
this.hidden = hidden;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry add(IAdvBuilder builder) {
|
public Entry add(IAdvBuilder builder) {
|
||||||
data.builder.add(builder);
|
data.builder.add(builder);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build() {
|
public void build() {
|
||||||
var builder = Advancement.Builder.advancement();
|
var builder = Advancement.Builder.advancement();
|
||||||
if (!data.item.isEmpty()) {
|
if (!data.item.isEmpty()) {
|
||||||
builder.display(data.item,
|
builder.display(data.item,
|
||||||
pvd.title(modid, "advancements." + tab + "." + data.id, data.title),
|
pvd.title(modid, tab + "." + data.id, data.title),
|
||||||
pvd.desc(modid, "advancements." + tab + "." + data.id, data.desc),
|
pvd.desc(modid, tab + "." + data.id, data.desc),
|
||||||
rl, type, showToast, announce, hidden);
|
rl, type, showToast, announce, hidden
|
||||||
}
|
);
|
||||||
if (parent != null) {
|
}
|
||||||
builder.parent(parent.result);
|
if (parent != null) {
|
||||||
}
|
builder.parent(parent.result);
|
||||||
|
}
|
||||||
|
|
||||||
String uid = modid + ":" + tab + "/" + data.id;
|
String uid = modid + ":" + tab + "/" + data.id;
|
||||||
for (var e : data.builder) {
|
List<ICondition> conditions = new ArrayList<>();
|
||||||
e.modify(uid, builder);
|
for (var e : data.builder) {
|
||||||
e.onBuild();
|
e.onBuild(uid, builder, conditions);
|
||||||
}
|
}
|
||||||
result = builder.save(pvd, uid);
|
Consumer<AdvancementHolder> cons = conditions.isEmpty() ? pvd :
|
||||||
for (Entry e : children) {
|
e -> pvd.withConditions(e, conditions);
|
||||||
e.build();
|
result = builder.save(cons, uid);
|
||||||
}
|
for (Entry e : children) {
|
||||||
}
|
e.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void finish() {
|
public void finish() {
|
||||||
TabBuilder.this.build();
|
TabBuilder.this.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private record EntryData(String id, ItemStack item, List<IAdvBuilder> builder, String title, String desc) {
|
private record EntryData(String id, ItemStack item, List<IAdvBuilder> builder, String title, String desc) {
|
||||||
|
|
||||||
EntryData(String id, ItemStack item, IAdvBuilder builder, String title, String desc) {
|
EntryData(String id, ItemStack item, IAdvBuilder builder, String title, String desc) {
|
||||||
this(id, item, new ArrayList<>(List.of(builder)), title, desc);
|
this(id, item, new ArrayList<>(List.of(builder)), title, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.minecraft.tags.TagKey;
|
|||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.enchantment.Enchantment;
|
import net.minecraft.world.item.enchantment.Enchantment;
|
||||||
import net.minecraft.world.level.ItemLike;
|
import net.minecraft.world.level.ItemLike;
|
||||||
|
import net.neoforged.neoforge.common.conditions.ICondition;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -102,7 +103,7 @@ public class CriterionBuilder implements IAdvBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modify(String id, Advancement.Builder builder) {
|
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
|
||||||
if (list.size() > 1) {
|
if (list.size() > 1) {
|
||||||
var ids = list.stream().map(Pair::getFirst).toList();
|
var ids = list.stream().map(Pair::getFirst).toList();
|
||||||
builder.requirements(req == RequirementsStrategy.AND ?
|
builder.requirements(req == RequirementsStrategy.AND ?
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package dev.xkmc.l2core.serial.advancements;
|
package dev.xkmc.l2core.serial.advancements;
|
||||||
|
|
||||||
import net.minecraft.advancements.Advancement;
|
import net.minecraft.advancements.Advancement;
|
||||||
|
import net.neoforged.neoforge.common.conditions.ICondition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface IAdvBuilder {
|
public interface IAdvBuilder {
|
||||||
|
|
||||||
default void modify(String id, Advancement.Builder builder) {
|
void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
default void onBuild() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package dev.xkmc.l2core.serial.advancements;
|
package dev.xkmc.l2core.serial.advancements;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import net.minecraft.advancements.Advancement;
|
||||||
import com.google.gson.JsonObject;
|
import net.neoforged.neoforge.common.conditions.ICondition;
|
||||||
|
import net.neoforged.neoforge.common.conditions.ModLoadedCondition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public record ModLoadedAdv(String... modid) implements IAdvBuilder {
|
public record ModLoadedAdv(String... modid) implements IAdvBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addConditions(JsonArray conditions) {
|
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
|
||||||
for (String str : modid) {
|
for (var e : modid) {
|
||||||
JsonObject condition = new JsonObject();
|
conditions.add(new ModLoadedCondition(e));
|
||||||
condition.addProperty("type", "forge:mod_loaded");
|
}
|
||||||
condition.addProperty("modid", str);
|
}
|
||||||
conditions.add(condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,17 @@ import net.minecraft.advancements.AdvancementRewards;
|
|||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.world.level.storage.loot.LootTable;
|
import net.minecraft.world.level.storage.loot.LootTable;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||||
|
import net.neoforged.neoforge.common.conditions.ICondition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public record RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot,
|
public record RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot,
|
||||||
Supplier<LootTable.Builder> sup) implements IAdvBuilder {
|
Supplier<LootTable.Builder> sup) implements IAdvBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modify(String id, Advancement.Builder builder) {
|
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
|
||||||
builder.rewards(AdvancementRewards.Builder.loot(loot).addExperience(exp).build());
|
builder.rewards(AdvancementRewards.Builder.loot(loot).addExperience(exp).build());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBuild() {
|
|
||||||
reg.addDataGenerator(ProviderType.LOOT, e -> e.addLootAction(LootContextParamSets.EMPTY,
|
reg.addDataGenerator(ProviderType.LOOT, e -> e.addLootAction(LootContextParamSets.EMPTY,
|
||||||
x -> x.accept(loot, sup.get())));
|
x -> x.accept(loot, sup.get())));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,32 @@ import net.minecraft.data.recipes.RecipeOutput;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.crafting.Recipe;
|
import net.minecraft.world.item.crafting.Recipe;
|
||||||
import net.neoforged.neoforge.common.conditions.ICondition;
|
import net.neoforged.neoforge.common.conditions.ICondition;
|
||||||
|
import net.neoforged.neoforge.common.conditions.ModLoadedCondition;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public record ConditionalRecipeWrapper(RecipeOutput pvd, ICondition... conditions) implements RecipeOutput {
|
public record ConditionalRecipeWrapper(RecipeOutput pvd, ICondition... conditions) implements RecipeOutput {
|
||||||
|
|
||||||
@Override
|
public static RecipeOutput mod(RecipeOutput pvd, String... modid) {
|
||||||
public Advancement.Builder advancement() {
|
ICondition[] ans = new ICondition[modid.length];
|
||||||
return pvd.advancement();
|
for (int i = 0; i < ans.length; ++i) {
|
||||||
}
|
ans[i] = new ModLoadedCondition(modid[i]);
|
||||||
|
}
|
||||||
|
return new ConditionalRecipeWrapper(pvd, ans);
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
|
||||||
pvd.accept(id, recipe, advancement, MathHelper.merge(conditions(), conditions));
|
public static RecipeOutput of(RecipeOutput pvd, ICondition... cond) {
|
||||||
}
|
return new ConditionalRecipeWrapper(pvd, cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Advancement.Builder advancement() {
|
||||||
|
return pvd.advancement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
||||||
|
pvd.accept(id, recipe, advancement, MathHelper.merge(conditions(), conditions));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,20 +13,24 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public record DataRecipeWrapper(RecipeOutput pvd, ItemStack stack) implements RecipeOutput {
|
public record DataRecipeWrapper(RecipeOutput pvd, ItemStack stack) implements RecipeOutput {
|
||||||
|
|
||||||
@Override
|
public static RecipeOutput of(RecipeOutput pvd, ItemStack stack) {
|
||||||
public Advancement.Builder advancement() {
|
return new DataRecipeWrapper(pvd, stack);
|
||||||
return pvd.advancement();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
public Advancement.Builder advancement() {
|
||||||
if (recipe instanceof ShapedRecipe r) {
|
return pvd.advancement();
|
||||||
r.result.applyComponents(stack.getComponents());
|
}
|
||||||
}
|
|
||||||
if (recipe instanceof ShapelessRecipe r) {
|
@Override
|
||||||
r.result.applyComponents(stack.getComponents());
|
public void accept(ResourceLocation id, Recipe<?> recipe, @Nullable AdvancementHolder advancement, ICondition... conditions) {
|
||||||
}
|
if (recipe instanceof ShapedRecipe r) {
|
||||||
pvd.accept(id, recipe, advancement, conditions);
|
r.result.applyComponents(stack.getComponents());
|
||||||
}
|
}
|
||||||
|
if (recipe instanceof ShapelessRecipe r) {
|
||||||
|
r.result.applyComponents(stack.getComponents());
|
||||||
|
}
|
||||||
|
pvd.accept(id, recipe, advancement, conditions);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user