Skip to content

Commit

Permalink
1.20.2-pre1
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Sep 5, 2023
1 parent 462ea84 commit 4351121
Show file tree
Hide file tree
Showing 23 changed files with 134 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.google.gson.JsonObject;

import net.minecraft.advancement.Advancement;
import net.minecraft.class_8779;
import net.minecraft.advancement.AdvancementEntry;
import net.minecraft.data.DataOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.DataWriter;
Expand Down Expand Up @@ -58,12 +58,12 @@ protected FabricAdvancementProvider(FabricDataOutput output) {
*
* <p>Use {@link Advancement.Builder#build(Consumer, String)} to help build advancements.
*/
public abstract void generateAdvancement(Consumer<class_8779> consumer);
public abstract void generateAdvancement(Consumer<AdvancementEntry> consumer);

/**
* Return a new exporter that applies the specified conditions to any advancement it receives.
*/
protected Consumer<class_8779> withConditions(Consumer<class_8779> exporter, ConditionJsonProvider... conditions) {
protected Consumer<AdvancementEntry> withConditions(Consumer<AdvancementEntry> exporter, ConditionJsonProvider... conditions) {
Preconditions.checkArgument(conditions.length > 0, "Must add at least one condition.");
return advancement -> {
FabricDataGenHelper.addConditions(advancement, conditions);
Expand All @@ -74,18 +74,18 @@ protected Consumer<class_8779> withConditions(Consumer<class_8779> exporter, Con
@Override
public CompletableFuture<?> run(DataWriter writer) {
final Set<Identifier> identifiers = Sets.newHashSet();
final Set<class_8779> advancements = Sets.newHashSet();
final Set<AdvancementEntry> advancements = Sets.newHashSet();

generateAdvancement(advancements::add);

final List<CompletableFuture<?>> futures = new ArrayList<>();

for (class_8779 advancement : advancements) {
if (!identifiers.add(advancement.comp_1919())) {
throw new IllegalStateException("Duplicate advancement " + advancement.comp_1919());
for (AdvancementEntry advancement : advancements) {
if (!identifiers.add(advancement.id())) {
throw new IllegalStateException("Duplicate advancement " + advancement.id());
}

JsonObject advancementJson = advancement.comp_1920().method_53621();
JsonObject advancementJson = advancement.value().toJson();
ConditionJsonProvider.write(advancementJson, FabricDataGenHelper.consumeConditions(advancement));

futures.add(DataProvider.writeToPath(writer, advancementJson, getOutputPath(advancement)));
Expand All @@ -94,8 +94,8 @@ public CompletableFuture<?> run(DataWriter writer) {
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
}

private Path getOutputPath(class_8779 advancement) {
return pathResolver.resolveJson(advancement.comp_1919());
private Path getOutputPath(AdvancementEntry advancement) {
return pathResolver.resolveJson(advancement.id());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import com.google.gson.JsonObject;

import net.minecraft.advancement.Advancement;
import net.minecraft.class_8779;
import net.minecraft.class_8790;
import net.minecraft.advancement.AdvancementEntry;
import net.minecraft.data.DataProvider;
import net.minecraft.data.DataWriter;
import net.minecraft.data.server.recipe.CraftingRecipeJsonBuilder;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.data.server.recipe.RecipeProvider;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
Expand Down Expand Up @@ -59,23 +59,23 @@ public FabricRecipeProvider(FabricDataOutput output) {
* Implement this method and then use the range of methods in {@link RecipeProvider} or from one of the recipe json factories such as {@link ShapedRecipeJsonBuilder} or {@link ShapelessRecipeJsonBuilder}.
*/
@Override
public abstract void generate(class_8790 exporter);
public abstract void generate(RecipeExporter exporter);

/**
* Return a new exporter that applies the specified conditions to any recipe json provider it receives.
*/
protected class_8790 withConditions(class_8790 exporter, ConditionJsonProvider... conditions) {
protected RecipeExporter withConditions(RecipeExporter exporter, ConditionJsonProvider... conditions) {
Preconditions.checkArgument(conditions.length > 0, "Must add at least one condition.");
return new class_8790() {
return new RecipeExporter() {
@Override
public void method_53819(RecipeJsonProvider provider) {
public void accept(RecipeJsonProvider provider) {
FabricDataGenHelper.addConditions(provider, conditions);
exporter.method_53819(provider);
exporter.accept(provider);
}

@Override
public Advancement.Builder method_53818() {
return exporter.method_53818();
public Advancement.Builder getAdvancementBuilder() {
return exporter.getAdvancementBuilder();
}
};
}
Expand All @@ -84,10 +84,10 @@ public Advancement.Builder method_53818() {
public CompletableFuture<?> run(DataWriter writer) {
Set<Identifier> generatedRecipes = Sets.newHashSet();
List<CompletableFuture<?>> list = new ArrayList<>();
generate(new class_8790() {
generate(new RecipeExporter() {
@Override
public void method_53819(RecipeJsonProvider provider) {
Identifier identifier = getRecipeIdentifier(provider.recipeId());
public void accept(RecipeJsonProvider provider) {
Identifier identifier = getRecipeIdentifier(provider.id());

if (!generatedRecipes.add(identifier)) {
throw new IllegalStateException("Duplicate recipe " + identifier);
Expand All @@ -99,17 +99,17 @@ public void method_53819(RecipeJsonProvider provider) {

list.add(DataProvider.writeToPath(writer, recipeJson, recipesPathResolver.resolveJson(identifier)));

class_8779 advancementBuilder = provider.advancementBuilder();
AdvancementEntry advancement = provider.advancement();

if (advancementBuilder != null) {
JsonObject advancementJson = advancementBuilder.comp_1920().method_53621();
if (advancement != null) {
JsonObject advancementJson = advancement.value().toJson();
ConditionJsonProvider.write(advancementJson, conditions);
list.add(DataProvider.writeToPath(writer, advancementJson, advancementsPathResolver.resolveJson(getRecipeIdentifier(advancementBuilder.comp_1919()))));
list.add(DataProvider.writeToPath(writer, advancementJson, advancementsPathResolver.resolveJson(getRecipeIdentifier(advancement.id()))));
}
}

@Override
public Advancement.Builder method_53818() {
public Advancement.Builder getAdvancementBuilder() {
return Advancement.Builder.createUntelemetered().parent(CraftingRecipeJsonBuilder.ROOT);
}
});
Expand Down
Loading

0 comments on commit 4351121

Please sign in to comment.