Skip to content

Commit

Permalink
Compiles. Sorta.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Nov 2, 2023
1 parent 1c58d46 commit 04249e7
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 158 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ runs {
data {
with commonRunProperties
programArguments = [
'--mod', 'ae2', '--all', '--output', file('src/generated/resources/'), "--existing", file("src/main/resources")
'--mod', 'ae2',
'--all',
'--output', file('src/generated/resources/').absolutePath,
'--existing', file('src/main/resources').absolutePath
]
}
guideexport {
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/appeng/datagen/providers/recipes/EntropyRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,59 +46,59 @@ public void buildRecipes(RecipeOutput consumer) {

private void buildCoolRecipes(RecipeOutput consumer) {

EntropyRecipeBuilder.cool(AppEng.makeId("entropy/cool/flowing_water_snowball"))
EntropyRecipeBuilder.cool()
.setInputFluid(Fluids.FLOWING_WATER)
.setDrops(new ItemStack(Items.SNOWBALL))
.save(consumer);
.save(consumer, AppEng.makeId("entropy/cool/flowing_water_snowball"));

EntropyRecipeBuilder.cool(AppEng.makeId("entropy/cool/grass_block_dirt"))
EntropyRecipeBuilder.cool()
.setInputBlock(Blocks.GRASS_BLOCK)
.setOutputBlock(Blocks.DIRT)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/cool/grass_block_dirt"));

EntropyRecipeBuilder.cool(AppEng.makeId("entropy/cool/lava_obsidian"))
EntropyRecipeBuilder.cool()
.setInputFluid(Fluids.LAVA)
.setOutputBlock(Blocks.OBSIDIAN)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/cool/lava_obsidian"));

EntropyRecipeBuilder.cool(AppEng.makeId("entropy/cool/stone_bricks_cracked_stone_bricks"))
EntropyRecipeBuilder.cool()
.setInputBlock(Blocks.STONE_BRICKS)
.setOutputBlock(Blocks.CRACKED_STONE_BRICKS)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/cool/stone_bricks_cracked_stone_bricks"));

EntropyRecipeBuilder.cool(AppEng.makeId("entropy/cool/stone_cobblestone"))
EntropyRecipeBuilder.cool()
.setInputBlock(Blocks.STONE)
.setOutputBlock(Blocks.COBBLESTONE)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/cool/stone_cobblestone"));

EntropyRecipeBuilder.cool(AppEng.makeId("entropy/cool/water_ice"))
EntropyRecipeBuilder.cool()
.setInputFluid(Fluids.WATER)
.setOutputBlock(Blocks.ICE)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/cool/water_ice"));

}

private void buildHeatRecipes(RecipeOutput consumer) {

EntropyRecipeBuilder.heat(AppEng.makeId("entropy/heat/cobblestone_stone"))
EntropyRecipeBuilder.heat()
.setInputBlock(Blocks.COBBLESTONE)
.setOutputBlock(Blocks.STONE)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/heat/cobblestone_stone"));

EntropyRecipeBuilder.heat(AppEng.makeId("entropy/heat/ice_water"))
EntropyRecipeBuilder.heat()
.setInputBlock(Blocks.ICE)
.setOutputFluid(Fluids.WATER)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/heat/ice_water"));

EntropyRecipeBuilder.heat(AppEng.makeId("entropy/heat/snow_water"))
EntropyRecipeBuilder.heat()
.setInputBlock(Blocks.SNOW)
.setOutputFluid(Fluids.FLOWING_WATER)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/heat/snow_water"));

EntropyRecipeBuilder.heat(AppEng.makeId("entropy/heat/water_air"))
EntropyRecipeBuilder.heat()
.setInputFluid(Fluids.WATER)
.setOutputBlock(Blocks.AIR)
.save(consumer);
.save(consumer, AppEng.makeId("entropy/heat/water_air"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public <T, V> List<T> getRecipes(IRecipeCategory<T> recipeCategory, IFocus<V> fo
}

private ShapedRecipe make(ItemStack textureItem, ItemStack cableAnchor, ItemStack result) {
// This id should only be used within JEI and not really matter
var itemId = BuiltInRegistries.ITEM.getKey(textureItem.getItem());
ResourceLocation id = new ResourceLocation(AppEng.MOD_ID,
"facade/" + itemId.getNamespace() + "/" + itemId.getPath());

NonNullList<Ingredient> ingredients = NonNullList.withSize(9, Ingredient.EMPTY);
ingredients.set(1, Ingredient.of(cableAnchor));
ingredients.set(3, Ingredient.of(cableAnchor));
Expand All @@ -104,7 +99,7 @@ private ShapedRecipe make(ItemStack textureItem, ItemStack cableAnchor, ItemStac
var output = result.copy();
output.setCount(4);

return new ShapedRecipe(id, "", CraftingBookCategory.MISC, 3, 3, ingredients, output);
return new ShapedRecipe("", CraftingBookCategory.MISC, 3, 3, ingredients, output);
}

@Override
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/appeng/recipes/entropy/EntropyRecipeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.google.common.base.Preconditions;
import com.google.gson.JsonObject;

import com.mojang.serialization.JsonOps;
import net.minecraft.Util;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.data.recipes.RecipeOutput;
import org.jetbrains.annotations.Nullable;
Expand All @@ -39,7 +41,6 @@
import net.minecraft.world.level.material.Fluid;

public class EntropyRecipeBuilder {
private ResourceLocation id;
private EntropyMode mode;

private Block inputBlock;
Expand All @@ -56,18 +57,12 @@ public class EntropyRecipeBuilder {
private boolean outputFluidKeep;
private List<ItemStack> drops = Collections.emptyList();

public static EntropyRecipeBuilder cool(ResourceLocation id) {
return new EntropyRecipeBuilder().setId(id).setMode(EntropyMode.COOL);
public static EntropyRecipeBuilder cool() {
return new EntropyRecipeBuilder().setMode(EntropyMode.COOL);
}

public static EntropyRecipeBuilder heat(ResourceLocation id) {
return new EntropyRecipeBuilder().setId(id).setMode(EntropyMode.HEAT);
}

public EntropyRecipeBuilder setId(ResourceLocation id) {
Preconditions.checkArgument(id != null);
this.id = id;
return this;
public static EntropyRecipeBuilder heat() {
return new EntropyRecipeBuilder().setMode(EntropyMode.HEAT);
}

public EntropyRecipeBuilder setMode(EntropyMode mode) {
Expand Down Expand Up @@ -169,7 +164,6 @@ public EntropyRecipeBuilder addFluidStateAppliers(StateApplier<?> applier) {
}

public EntropyRecipe build() {
Preconditions.checkState(id != null);
Preconditions.checkState(mode != null);
Preconditions.checkState(inputBlock != null || inputFluid != null,
"Either inputBlock or inputFluid needs to be not null");
Expand All @@ -179,14 +173,21 @@ public EntropyRecipe build() {
drops);
}

public void save(RecipeOutput consumer) {
consumer.accept(new Result());
public void save(RecipeOutput consumer, ResourceLocation id) {
consumer.accept(new Result(id));
}

private class Result implements FinishedRecipe {
private final ResourceLocation id;

public Result(ResourceLocation id) {
this.id = id;
}

@Override
public void serializeRecipeData(JsonObject json) {
EntropyRecipeSerializer.INSTANCE.toJson(build(), json);
Util.getOrThrow(EntropyRecipeSerializer.INSTANCE.codec()
.encode(build(), JsonOps.INSTANCE, json), IllegalStateException::new);
}

@Override
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/appeng/recipes/entropy/EntropyRecipeSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.ExtraCodecs;
import org.jetbrains.annotations.Nullable;

import net.minecraft.core.Registry;
Expand All @@ -46,15 +49,24 @@ public class EntropyRecipeSerializer implements RecipeSerializer<EntropyRecipe>

public static final EntropyRecipeSerializer INSTANCE = new EntropyRecipeSerializer();

private static final Codec<EntropyRecipe> CODEC = ExtraCodecs.adaptJsonSerializer(
EntropyRecipeSerializer::fromJson,
EntropyRecipeSerializer::toJson
);

private EntropyRecipeSerializer() {
}

@Override
public EntropyRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
public Codec<EntropyRecipe> codec() {
return CODEC;
}

private static EntropyRecipe fromJson(JsonElement jsonEl) {
var json = jsonEl.getAsJsonObject();
EntropyRecipeBuilder builder = new EntropyRecipeBuilder();

// Set id and mode
builder.setId(recipeId);
builder.setMode(EntropyMode.valueOf(GsonHelper.getAsString(json, "mode").toUpperCase(Locale.ROOT)));

//// Parse inputs
Expand Down Expand Up @@ -136,10 +148,9 @@ private static <T> T getRequiredEntry(Registry<T> registry, String id) {

@Nullable
@Override
public EntropyRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
public EntropyRecipe fromNetwork(FriendlyByteBuf buffer) {
EntropyRecipeBuilder builder = new EntropyRecipeBuilder();

builder.setId(recipeId);
builder.setMode(buffer.readEnum(EntropyMode.class));

if (buffer.readBoolean()) {
Expand Down Expand Up @@ -295,13 +306,15 @@ private static void parseStateAppliers(StateDefinition<?, ?> stateDefinition, Js
});
}

public void toJson(EntropyRecipe recipe, JsonObject json) {
private static JsonElement toJson(EntropyRecipe recipe) {
JsonObject json = new JsonObject();
json.addProperty("mode", recipe.getMode().name().toLowerCase(Locale.ROOT));
json.add("input", serializeInput(recipe));
json.add("output", serializeOutput(recipe));
return json;
}

private JsonObject serializeInput(EntropyRecipe recipe) {
private static JsonObject serializeInput(EntropyRecipe recipe) {
var input = new JsonObject();
if (recipe.getInputBlock() != null) {
var jsonBlock = new JsonObject();
Expand All @@ -319,7 +332,7 @@ private JsonObject serializeInput(EntropyRecipe recipe) {
return input;
}

private JsonElement serializeOutput(EntropyRecipe recipe) {
private static JsonElement serializeOutput(EntropyRecipe recipe) {
var output = new JsonObject();
if (recipe.getOutputBlock() != null) {
var jsonBlock = new JsonObject();
Expand Down Expand Up @@ -358,7 +371,7 @@ private JsonElement serializeOutput(EntropyRecipe recipe) {
return output;
}

private void serializeStateMatchers(List<StateMatcher> matchers, JsonObject json) {
private static void serializeStateMatchers(List<StateMatcher> matchers, JsonObject json) {
if (matchers.isEmpty()) {
return;
}
Expand Down Expand Up @@ -389,7 +402,7 @@ private void serializeStateMatchers(List<StateMatcher> matchers, JsonObject json
json.add("properties", properties);
}

private void serializeStateAppliers(List<StateApplier<?>> appliers, JsonObject json) {
private static void serializeStateAppliers(List<StateApplier<?>> appliers, JsonObject json) {
if (appliers.isEmpty()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/recipes/game/FacadeRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public RecipeSerializer<FacadeRecipe> getSerializer() {

public static RecipeSerializer<FacadeRecipe> getSerializer(FacadeItem facade) {
if (SERIALIZER == null) {
SERIALIZER = new SimpleCraftingRecipeSerializer<>((id, category) -> new FacadeRecipe(category, facade));
SERIALIZER = new SimpleCraftingRecipeSerializer<>((category) -> new FacadeRecipe(category, facade));
}
return SERIALIZER;
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/appeng/recipes/handlers/ChargerRecipe.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package appeng.recipes.handlers;

import appeng.core.AppEng;
import appeng.init.InitRecipeTypes;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
Expand All @@ -12,9 +17,6 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;

import appeng.core.AppEng;
import appeng.init.InitRecipeTypes;

public class ChargerRecipe implements Recipe<Container> {
public static final ResourceLocation TYPE_ID = AppEng.makeId("charger");

Expand All @@ -24,6 +26,13 @@ public class ChargerRecipe implements Recipe<Container> {
public final NonNullList<Ingredient> ingredients;
public final Item result;

public static final Codec<ChargerRecipe> CODEC = RecordCodecBuilder.create(builder -> {
return builder.group(
Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(ChargerRecipe::getIngredient),
BuiltInRegistries.ITEM.byNameCodec().fieldOf("result").forGetter(cr -> cr.result)
).apply(builder, ChargerRecipe::new);
});

public ChargerRecipe(Ingredient ingredient, Item result) {
this.ingredient = ingredient;
this.result = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.gson.JsonObject;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
Expand All @@ -16,16 +19,12 @@ public class ChargerRecipeSerializer implements RecipeSerializer<ChargerRecipe>
public static final ChargerRecipeSerializer INSTANCE = new ChargerRecipeSerializer();

@Override
public ChargerRecipe fromJson(ResourceLocation recipeId, JsonObject serializedRecipe) {

Ingredient ingredient = Ingredient.fromJson(serializedRecipe.get("ingredient"));
Item result = ShapedRecipe.itemFromJson(GsonHelper.getAsJsonObject(serializedRecipe, "result"));

return new ChargerRecipe(ingredient, result);
public Codec<ChargerRecipe> codec() {
return ChargerRecipe.CODEC;
}

@Override
public ChargerRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
public ChargerRecipe fromNetwork(FriendlyByteBuf buffer) {
Ingredient ingredient = Ingredient.fromNetwork(buffer);
ItemStack result = buffer.readItem();

Expand Down
Loading

0 comments on commit 04249e7

Please sign in to comment.