[Changes] Migrated Advancement Manager to DataGen
This commit is contained in:
parent
251925ac08
commit
3f2963d8bf
4 changed files with 36 additions and 39 deletions
|
@ -26,27 +26,46 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class AdvancementManager {
|
||||
private static final Map<ResourceLocation, Advancement.Builder> ADVANCEMENTS = new HashMap<>();
|
||||
private static final Map<ResourceLocation, Advancement.Builder> ADVANCEMENTS = new LinkedHashMap<>();
|
||||
|
||||
public static void register(ResourceLocation id, Advancement.Builder builder) {
|
||||
ADVANCEMENTS.put(id, builder);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void addAdvancements(Map<ResourceLocation, Advancement.Builder> map) {
|
||||
public static void registerAllDataGen(List<String> namespaces, Consumer<Advancement> consumer) {
|
||||
final Advancement ROOT_RECIPE = Advancement.Builder.advancement()
|
||||
.addCriterion(
|
||||
"impossible",
|
||||
new ImpossibleTrigger.TriggerInstance()
|
||||
)
|
||||
.build(RecipeBuilder.ROOT_RECIPE_ADVANCEMENT);
|
||||
final Map<ResourceLocation, Advancement> BUILT = new HashMap<>();
|
||||
|
||||
for (var entry : ADVANCEMENTS.entrySet()) {
|
||||
if (!map.containsKey(entry.getKey())) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
final ResourceLocation loc = entry.getKey();
|
||||
if (namespaces == null || namespaces.contains(loc.getNamespace())) {
|
||||
final Advancement.Builder builder = entry.getValue();
|
||||
if (builder.canBuild(locToAdd -> {
|
||||
if (locToAdd.equals(RecipeBuilder.ROOT_RECIPE_ADVANCEMENT)) return ROOT_RECIPE;
|
||||
return BUILT.get(locToAdd);
|
||||
})) {
|
||||
final Advancement adv = builder.build(loc);
|
||||
BUILT.put(loc, adv);
|
||||
consumer.accept(adv);
|
||||
} else {
|
||||
BCLib.LOGGER.error("Unable to build Advancement " + loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class RewardsBuilder {
|
||||
private final Builder calle;
|
||||
private final AdvancementRewards.Builder builder = new AdvancementRewards.Builder();
|
||||
|
@ -147,7 +166,11 @@ public class AdvancementManager {
|
|||
return create(new ItemStack(icon), type, displayAdapter);
|
||||
}
|
||||
|
||||
public static Builder create(ItemStack icon, AdvancementType type, Consumer<DisplayBuilder> displayAdapter) {
|
||||
public static Builder create(
|
||||
ItemStack icon,
|
||||
AdvancementType type,
|
||||
Consumer<DisplayBuilder> displayAdapter
|
||||
) {
|
||||
var id = BuiltInRegistries.ITEM.getKey(icon.getItem());
|
||||
boolean canBuild = true;
|
||||
if (id == null || icon.is(Items.AIR)) {
|
||||
|
@ -168,7 +191,10 @@ public class AdvancementManager {
|
|||
return b;
|
||||
}
|
||||
|
||||
public static <C extends Container, T extends Recipe<C>> Builder createRecipe(T recipe, AdvancementType type) {
|
||||
public static <C extends Container, T extends Recipe<C>> Builder createRecipe(
|
||||
T recipe,
|
||||
AdvancementType type
|
||||
) {
|
||||
Item item = recipe.getResultItem().getItem();
|
||||
return create(item, type, displayBuilder -> displayBuilder.hideToast().hideFromChat())
|
||||
//.awardRecipe(item)
|
||||
|
@ -365,15 +391,10 @@ public class AdvancementManager {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ResourceLocation buildAndRegister() {
|
||||
public ResourceLocation build() {
|
||||
AdvancementManager.register(id, this.builder);
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public ResourceLocation buildAndRegister(Map<ResourceLocation, Advancement.Builder> map) {
|
||||
map.put(id, this.builder);
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DisplayBuilder {
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import org.betterx.bclib.api.v2.advancement.AdvancementManager;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.ServerAdvancementManager;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(ServerAdvancementManager.class)
|
||||
public class ServerAdvancementManagerMixin {
|
||||
@ModifyArg(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementList;add(Ljava/util/Map;)V"))
|
||||
public Map<ResourceLocation, Advancement.Builder> bcl_interceptApply(Map<ResourceLocation, Advancement.Builder> map) {
|
||||
AdvancementManager.addAdvancements(map);
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -214,7 +214,7 @@ public class AbstractAdvancementRecipe {
|
|||
.endReward()
|
||||
.requirements(RequirementsStrategy.OR);
|
||||
|
||||
advancement.buildAndRegister();
|
||||
advancement.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
"RecipeManagerMixin",
|
||||
"RecipeMixin",
|
||||
"RegistryDataLoaderMixin",
|
||||
"ServerAdvancementManagerMixin",
|
||||
"ServerLevelMixin",
|
||||
"ShovelItemAccessor",
|
||||
"SurfaceRulesContextAccessor",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue