Skip to content

Commit

Permalink
Initial port to 23w35a
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Aug 30, 2023
1 parent 017b9d9 commit bc0c65b
Show file tree
Hide file tree
Showing 34 changed files with 273 additions and 452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static void waitForWorldTicks(long ticks) {

public static void enableDebugHud() {
submitAndWait(client -> {
client.inGameHud.method_53531().method_53539();
client.inGameHud.getDebugHud().toggleDebugHud();
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient ? null : checkType(type, FabricApiLookupTest.CHUTE_BLOCK_ENTITY_TYPE, ChuteBlockEntity::serverTick);
return world.isClient ? null : validateTicker(type, FabricApiLookupTest.CHUTE_BLOCK_ENTITY_TYPE, ChuteBlockEntity::serverTick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.gson.JsonObject;

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

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

generateAdvancement(advancements::add);

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

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

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

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

private Path getOutputPath(Advancement advancement) {
return pathResolver.resolveJson(advancement.getId());
private Path getOutputPath(class_8779 advancement) {
return pathResolver.resolveJson(advancement.comp_1919());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.google.gson.JsonObject;

import net.minecraft.advancement.Advancement;
import net.minecraft.class_8779;
import net.minecraft.class_8790;
import net.minecraft.data.DataProvider;
import net.minecraft.data.DataWriter;
import net.minecraft.data.server.recipe.CraftingRecipeJsonBuilder;
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 @@ -56,40 +59,58 @@ 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(Consumer<RecipeJsonProvider> exporter);
public abstract void generate(class_8790 exporter);

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

@Override
public Advancement.Builder method_53818() {
return exporter.method_53818();
}
};
}

@Override
public CompletableFuture<?> run(DataWriter writer) {
Set<Identifier> generatedRecipes = Sets.newHashSet();
List<CompletableFuture<?>> list = new ArrayList<>();
generate(provider -> {
Identifier identifier = getRecipeIdentifier(provider.getRecipeId());
generate(new class_8790() {
@Override
public void method_53819(RecipeJsonProvider provider) {
Identifier identifier = getRecipeIdentifier(provider.recipeId());

if (!generatedRecipes.add(identifier)) {
throw new IllegalStateException("Duplicate recipe " + identifier);
}
if (!generatedRecipes.add(identifier)) {
throw new IllegalStateException("Duplicate recipe " + identifier);
}

JsonObject recipeJson = provider.toJson();
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(provider);
ConditionJsonProvider.write(recipeJson, conditions);
JsonObject recipeJson = provider.toJson();
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(provider);
ConditionJsonProvider.write(recipeJson, conditions);

list.add(DataProvider.writeToPath(writer, recipeJson, this.recipesPathResolver.resolveJson(identifier)));
JsonObject advancementJson = provider.toAdvancementJson();
list.add(DataProvider.writeToPath(writer, recipeJson, recipesPathResolver.resolveJson(identifier)));

class_8779 advancementBuilder = provider.advancementBuilder();

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

if (advancementJson != null) {
ConditionJsonProvider.write(advancementJson, conditions);
list.add(DataProvider.writeToPath(writer, advancementJson, this.advancementsPathResolver.resolveJson(getRecipeIdentifier(provider.getAdvancementId()))));
@Override
public Advancement.Builder method_53818() {
return Advancement.Builder.createUntelemetered().parent(CraftingRecipeJsonBuilder.ROOT);
}
});
return CompletableFuture.allOf(list.toArray(CompletableFuture[]::new));
Expand Down
Loading

0 comments on commit bc0c65b

Please sign in to comment.