diff --git a/src/main/java/de/dafuqs/spectrum/api/recipe/FusionShrineRecipeWorldEffect.java b/src/main/java/de/dafuqs/spectrum/api/recipe/FusionShrineRecipeWorldEffect.java index 3cec330d7f..f38201841b 100644 --- a/src/main/java/de/dafuqs/spectrum/api/recipe/FusionShrineRecipeWorldEffect.java +++ b/src/main/java/de/dafuqs/spectrum/api/recipe/FusionShrineRecipeWorldEffect.java @@ -2,6 +2,7 @@ import com.google.gson.*; import de.dafuqs.spectrum.*; +import io.wispforest.endec.*; import net.minecraft.server.*; import net.minecraft.server.command.*; import net.minecraft.server.world.*; @@ -16,6 +17,8 @@ public interface FusionShrineRecipeWorldEffect { Map TYPES = new HashMap<>(); + + Endec ENDEC = Endec.STRING.xmap(FusionShrineRecipeWorldEffect::fromString, Objects::toString); FusionShrineRecipeWorldEffect NOTHING = register("nothing", new FusionShrineRecipeWorldEffect.SingleTimeRecipeWorldEffect() { @Override diff --git a/src/main/java/de/dafuqs/spectrum/recipe/GatedSpectrumRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/GatedSpectrumRecipe.java index 72ec5e7b4b..c9256c11e9 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/GatedSpectrumRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/GatedSpectrumRecipe.java @@ -9,7 +9,7 @@ import net.minecraft.util.*; import org.jetbrains.annotations.*; -public class GatedSpectrumRecipe implements GatedRecipe { +public abstract class GatedSpectrumRecipe implements GatedRecipe { public final String group; public final boolean secret; @@ -43,8 +43,10 @@ public Identifier getRequiredAdvancementIdentifier() { } @Override - public abstract Identifier getRecipeTypeUnlockIdentifier(); - + public Identifier getRecipeTypeUnlockIdentifier() { + return null; + } + //TODO: Should this be false when the recipe is unlocked? @Override public boolean isIgnoredInRecipeBook() { diff --git a/src/main/java/de/dafuqs/spectrum/recipe/enchantment_upgrade/EnchantmentUpgradeRecipeSerializer.java b/src/main/java/de/dafuqs/spectrum/recipe/enchantment_upgrade/EnchantmentUpgradeRecipeSerializer.java index ee302912ca..7ef882fb63 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/enchantment_upgrade/EnchantmentUpgradeRecipeSerializer.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/enchantment_upgrade/EnchantmentUpgradeRecipeSerializer.java @@ -5,10 +5,7 @@ import io.wispforest.endec.impl.*; import io.wispforest.owo.serialization.*; import io.wispforest.owo.serialization.endec.*; -import io.wispforest.endec.*; -import io.wispforest.endec.impl.*; -import io.wispforest.owo.serialization.*; -import io.wispforest.owo.serialization.endec.*; +import net.minecraft.enchantment.*; import net.minecraft.item.*; import net.minecraft.registry.*; @@ -16,20 +13,6 @@ public class EnchantmentUpgradeRecipeSerializer extends EndecRecipeSerializer implements GatedRecipeSerializer { -// public static final StructEndec RECIPE_ENDEC = StructEndecBuilder.of( -// Endec.STRING.optionalFieldOf("group", recipe -> recipe.group, ""), -// Endec.BOOLEAN.optionalFieldOf("secret", recipe -> recipe.secret, false), -// MinecraftEndecs.IDENTIFIER.fieldOf("required_advancement", recipe -> recipe.requiredAdvancementIdentifier), -// MinecraftEndecs.IDENTIFIER.fieldOf("enchantment", recipe -> recipe.enchantmentIdentifier), -// Endec.INT.fieldOf("enchantment_destination_level", recipe -> recipe.enchantmentDestinationLevel), -// /// unwrap into these specific fields -// Endec.INT.fieldOf("required_experience", recipe -> recipe.requiredExperience), -// MinecraftEndecs.ofRegistry(Registries.ITEM).fieldOf("required_item",recipe -> recipe.requiredItem), -// Endec.INT.fieldOf("required_item_count", recipe -> recipe.requiredItemCount), -// /// -// EnchantmentUpgradeRecipe::new -// ); - // FIXME - Experimental. Will likely break as I don't believe the recipes are properly being registered // Maybe the recipe injection code (KubeJS compat) is easier? public static final StructEndec ENDEC = StructEndecBuilder.of( diff --git a/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipe.java index 46598f4b5e..f9b1c5484f 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipe.java @@ -53,9 +53,24 @@ public class FusionShrineRecipe extends GatedStackSpectrumRecipe craftingInputs, FluidIngredient fluid, ItemStack output, float experience, int craftingTime, boolean yieldUpgradesDisabled, boolean playCraftingFinishedEffects, boolean copyNbt, - List> spectrumLocationPredicates, @NotNull FusionShrineRecipeWorldEffect startWorldEffect, @NotNull List duringWorldEffects, @NotNull FusionShrineRecipeWorldEffect finishWorldEffect, @Nullable Text description) { + public FusionShrineRecipe( + String group, + boolean secret, + Identifier requiredAdvancementIdentifier, + List craftingInputs, + FluidIngredient fluid, + ItemStack output, + float experience, + int craftingTime, + boolean yieldUpgradesDisabled, + boolean playCraftingFinishedEffects, + boolean copyNbt, + List> spectrumLocationPredicates, + @NotNull FusionShrineRecipeWorldEffect startWorldEffect, + @NotNull List duringWorldEffects, + @NotNull FusionShrineRecipeWorldEffect finishWorldEffect, + @Nullable Text description + ) { super(group, secret, requiredAdvancementIdentifier); this.craftingInputs = craftingInputs; diff --git a/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipeSerializer.java b/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipeSerializer.java index 8cd1fc06aa..84cfc78acd 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipeSerializer.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/fusion_shrine/FusionShrineRecipeSerializer.java @@ -1,23 +1,22 @@ package de.dafuqs.spectrum.recipe.fusion_shrine; -import com.google.gson.*; -import de.dafuqs.spectrum.*; -import de.dafuqs.spectrum.api.predicate.*; +import com.mojang.serialization.*; +import de.dafuqs.spectrum.api.predicate.location.*; import de.dafuqs.spectrum.api.recipe.*; import de.dafuqs.spectrum.recipe.*; import io.wispforest.endec.*; import io.wispforest.endec.impl.*; +import io.wispforest.owo.serialization.*; import io.wispforest.owo.serialization.endec.*; -import net.minecraft.item.*; import net.minecraft.network.*; +import net.minecraft.network.codec.*; import net.minecraft.text.*; -import net.minecraft.util.*; import java.util.*; public class FusionShrineRecipeSerializer implements GatedRecipeSerializer { - public static final StructEndec ENDEC = StructEndecBuilder.of( + public static final StructEndec ENDEC = StructEndecBuilder.of( Endec.STRING.optionalFieldOf("group", recipe -> recipe.group, ""), Endec.BOOLEAN.optionalFieldOf("secret", recipe -> recipe.secret, false), MinecraftEndecs.IDENTIFIER.fieldOf("required_advancement", recipe -> recipe.requiredAdvancementIdentifier), @@ -29,132 +28,143 @@ public class FusionShrineRecipeSerializer implements GatedRecipeSerializer recipe.yieldUpgradesDisabled, false), Endec.BOOLEAN.optionalFieldOf("play_crafting_finished_effects", recipe -> recipe.playCraftingFinishedEffects, true), Endec.BOOLEAN.optionalFieldOf("copy_components", recipe -> recipe.copyNbt, false), - // TODO - List of WorldConditionPredicates - // TODO - FusionShrineRecipeWorldEffect when starting - // TODO - List of FusionShrineRecipeWorldEffect during the craft - // TODO - FusionShrineRecipeWorldEffect when craft is finished - MinecraftEndecs.TEXT.optionalFieldOf("description", recipe -> recipe.description, Text.EMPTY) + CodecUtils.toEndec(SpectrumLocationPredicate.CODEC).listOf().optionalFieldOf("world_conditions",recipe -> recipe.spectrumLocationPredicates, List.of()), + FusionShrineRecipeWorldEffect.ENDEC.fieldOf("start_crafting_effect", recipe -> recipe.startWorldEffect), + FusionShrineRecipeWorldEffect.ENDEC.listOf().fieldOf("during_crafting_effects", recipe -> recipe.duringWorldEffects), + FusionShrineRecipeWorldEffect.ENDEC.fieldOf("finish_crafting_effect", recipe -> recipe.finishWorldEffect), + MinecraftEndecs.TEXT.optionalFieldOf("description", recipe -> recipe.description, Text.empty()), + FusionShrineRecipe::new ); @Override - public FusionShrineRecipe read(Identifier identifier, JsonObject jsonObject) { - String group = readGroup(jsonObject); - boolean secret = readSecret(jsonObject); - Identifier requiredAdvancementIdentifier = readRequiredAdvancementIdentifier(jsonObject); - - JsonArray ingredientArray = JsonHelper.getArray(jsonObject, "ingredients"); - List craftingInputs = RecipeParser.ingredientStacksFromJson(ingredientArray, ingredientArray.size()); - if (craftingInputs.size() > 7) { - throw new JsonParseException("Recipe cannot have more than 7 ingredients. Has " + craftingInputs.size()); - } - - FluidIngredient fluid = FluidIngredient.EMPTY; - if (JsonHelper.hasJsonObject(jsonObject, "fluid")) { - JsonObject fluidObject = JsonHelper.getObject(jsonObject, "fluid"); - FluidIngredient.JsonParseResult result = FluidIngredient.fromJson(fluidObject); - fluid = result.result(); - if (result.malformed()) { - // Currently handling malformed input leniently. May throw an error in the future. - SpectrumCommon.logError("Fusion Recipe " + identifier + "contains a malformed fluid input tag! This recipe will not be craftable."); - } else if (result.result() == FluidIngredient.EMPTY && !result.isTag()) { // tags get populated after recipes are - SpectrumCommon.logError("Fusion Recipe " + identifier + " specifies fluid " + result.id() + " that does not exist! This recipe will not be craftable."); - } - } - - ItemStack output; - if (JsonHelper.hasJsonObject(jsonObject, "result")) { - output = RecipeUtils.itemStackWithNbtFromJson(JsonHelper.getObject(jsonObject, "result")); - } else { - output = ItemStack.EMPTY; - } - float experience = JsonHelper.getFloat(jsonObject, "experience", 0); - int craftingTime = JsonHelper.getInt(jsonObject, "time", 200); - boolean yieldUpgradesDisabled = JsonHelper.getBoolean(jsonObject, "disable_yield_upgrades", false); - boolean playCraftingFinishedEffects = JsonHelper.getBoolean(jsonObject, "play_crafting_finished_effects", true); - - List> worldConditions = new ArrayList<>(); - if (JsonHelper.hasArray(jsonObject, "world_conditions")) { - for (JsonElement element : JsonHelper.getArray(jsonObject, "world_conditions")) { - worldConditions.add(SpectrumLocationPredicateType.fromJson(element)); - } - } - - FusionShrineRecipeWorldEffect startWorldEffect = FusionShrineRecipeWorldEffect.fromString(JsonHelper.getString(jsonObject, "start_crafting_effect", null)); - List duringWorldEffects = new ArrayList<>(); - if (JsonHelper.hasArray(jsonObject, "during_crafting_effects")) { - JsonArray worldEffectsArray = JsonHelper.getArray(jsonObject, "during_crafting_effects"); - for (int i = 0; i < worldEffectsArray.size(); i++) { - duringWorldEffects.add(FusionShrineRecipeWorldEffect.fromString(worldEffectsArray.get(i).getAsString())); - } - } - FusionShrineRecipeWorldEffect finishWorldEffect = FusionShrineRecipeWorldEffect.fromString(JsonHelper.getString(jsonObject, "finish_crafting_effect", null)); - - Text description; - if (JsonHelper.hasString(jsonObject, "description")) { - description = Text.translatable(JsonHelper.getString(jsonObject, "description")); - } else { - description = null; - } - boolean copyNbt = JsonHelper.getBoolean(jsonObject, "copy_nbt", false); - if (copyNbt && output.isEmpty()) { - throw new JsonParseException("Recipe does have copy_nbt set, but has no output!"); - } - - return this.recipeFactory.create(identifier, group, secret, requiredAdvancementIdentifier, - craftingInputs, fluid, output, experience, craftingTime, yieldUpgradesDisabled, playCraftingFinishedEffects, copyNbt, - worldConditions, startWorldEffect, duringWorldEffects, finishWorldEffect, description); + public MapCodec codec() { + return CodecUtils.toMapCodec(ENDEC); } - @Override - public void write(PacketByteBuf packetByteBuf, FusionShrineRecipe recipe) { - packetByteBuf.writeString(recipe.group); - packetByteBuf.writeBoolean(recipe.secret); - writeNullableIdentifier(packetByteBuf, recipe.requiredAdvancementIdentifier); - - packetByteBuf.writeShort(recipe.craftingInputs.size()); - for (IngredientStack ingredientStack : recipe.craftingInputs) { - ingredientStack.write(packetByteBuf); - } - - writeFluidIngredient(packetByteBuf, recipe.fluid); - packetByteBuf.writeItemStack(recipe.output); - packetByteBuf.writeFloat(recipe.experience); - packetByteBuf.writeInt(recipe.craftingTime); - packetByteBuf.writeBoolean(recipe.yieldUpgradesDisabled); - packetByteBuf.writeBoolean(recipe.playCraftingFinishedEffects); - - if (recipe.getDescription().isEmpty()) { - packetByteBuf.writeText(Text.literal("")); - } else { - packetByteBuf.writeText(recipe.getDescription().get()); - } - packetByteBuf.writeBoolean(recipe.copyNbt); + public PacketCodec packetCodec() { + return CodecUtils.toPacketCodec(ENDEC); } - - - @Override - public FusionShrineRecipe read(Identifier identifier, PacketByteBuf packetByteBuf) { - String group = packetByteBuf.readString(); - boolean secret = packetByteBuf.readBoolean(); - Identifier requiredAdvancementIdentifier = readNullableIdentifier(packetByteBuf); - - short craftingInputCount = packetByteBuf.readShort(); - List ingredients = IngredientStack.decodeByteBuf(packetByteBuf, craftingInputCount); - - FluidIngredient fluid = readFluidIngredient(packetByteBuf); - ItemStack output = packetByteBuf.readItemStack(); - float experience = packetByteBuf.readFloat(); - int craftingTime = packetByteBuf.readInt(); - boolean yieldUpgradesDisabled = packetByteBuf.readBoolean(); - boolean playCraftingFinishedEffects = packetByteBuf.readBoolean(); - Text description = packetByteBuf.readText(); - boolean copyNbt = packetByteBuf.readBoolean(); - - return this.recipeFactory.create(identifier, group, secret, requiredAdvancementIdentifier, - ingredients, fluid, output, experience, craftingTime, yieldUpgradesDisabled, playCraftingFinishedEffects, copyNbt, - List.of(), FusionShrineRecipeWorldEffect.NOTHING, List.of(), FusionShrineRecipeWorldEffect.NOTHING, description); - } +// @Override +// public FusionShrineRecipe read(Identifier identifier, JsonObject jsonObject) { +// String group = readGroup(jsonObject); +// boolean secret = readSecret(jsonObject); +// Identifier requiredAdvancementIdentifier = readRequiredAdvancementIdentifier(jsonObject); +// +// JsonArray ingredientArray = JsonHelper.getArray(jsonObject, "ingredients"); +// List craftingInputs = RecipeParser.ingredientStacksFromJson(ingredientArray, ingredientArray.size()); +// if (craftingInputs.size() > 7) { +// throw new JsonParseException("Recipe cannot have more than 7 ingredients. Has " + craftingInputs.size()); +// } +// +// FluidIngredient fluid = FluidIngredient.EMPTY; +// if (JsonHelper.hasJsonObject(jsonObject, "fluid")) { +// JsonObject fluidObject = JsonHelper.getObject(jsonObject, "fluid"); +// FluidIngredient.JsonParseResult result = FluidIngredient.fromJson(fluidObject); +// fluid = result.result(); +// if (result.malformed()) { +// // Currently handling malformed input leniently. May throw an error in the future. +// SpectrumCommon.logError("Fusion Recipe " + identifier + "contains a malformed fluid input tag! This recipe will not be craftable."); +// } else if (result.result() == FluidIngredient.EMPTY && !result.isTag()) { // tags get populated after recipes are +// SpectrumCommon.logError("Fusion Recipe " + identifier + " specifies fluid " + result.id() + " that does not exist! This recipe will not be craftable."); +// } +// } +// +// ItemStack output; +// if (JsonHelper.hasJsonObject(jsonObject, "result")) { +// output = RecipeUtils.itemStackWithNbtFromJson(JsonHelper.getObject(jsonObject, "result")); +// } else { +// output = ItemStack.EMPTY; +// } +// float experience = JsonHelper.getFloat(jsonObject, "experience", 0); +// int craftingTime = JsonHelper.getInt(jsonObject, "time", 200); +// boolean yieldUpgradesDisabled = JsonHelper.getBoolean(jsonObject, "disable_yield_upgrades", false); +// boolean playCraftingFinishedEffects = JsonHelper.getBoolean(jsonObject, "play_crafting_finished_effects", true); +// +// List> worldConditions = new ArrayList<>(); +// if (JsonHelper.hasArray(jsonObject, "world_conditions")) { +// for (JsonElement element : JsonHelper.getArray(jsonObject, "world_conditions")) { +// worldConditions.add(SpectrumLocationPredicateType.fromJson(element)); +// } +// } +// +// FusionShrineRecipeWorldEffect startWorldEffect = FusionShrineRecipeWorldEffect.fromString(JsonHelper.getString(jsonObject, "start_crafting_effect", null)); +// List duringWorldEffects = new ArrayList<>(); +// if (JsonHelper.hasArray(jsonObject, "during_crafting_effects")) { +// JsonArray worldEffectsArray = JsonHelper.getArray(jsonObject, "during_crafting_effects"); +// for (int i = 0; i < worldEffectsArray.size(); i++) { +// duringWorldEffects.add(FusionShrineRecipeWorldEffect.fromString(worldEffectsArray.get(i).getAsString())); +// } +// } +// FusionShrineRecipeWorldEffect finishWorldEffect = FusionShrineRecipeWorldEffect.fromString(JsonHelper.getString(jsonObject, "finish_crafting_effect", null)); +// +// Text description; +// if (JsonHelper.hasString(jsonObject, "description")) { +// description = Text.translatable(JsonHelper.getString(jsonObject, "description")); +// } else { +// description = null; +// } +// boolean copyNbt = JsonHelper.getBoolean(jsonObject, "copy_nbt", false); +// if (copyNbt && output.isEmpty()) { +// throw new JsonParseException("Recipe does have copy_nbt set, but has no output!"); +// } +// +// return this.recipeFactory.create(identifier, group, secret, requiredAdvancementIdentifier, +// craftingInputs, fluid, output, experience, craftingTime, yieldUpgradesDisabled, playCraftingFinishedEffects, copyNbt, +// worldConditions, startWorldEffect, duringWorldEffects, finishWorldEffect, description); +// } +// +// +// @Override +// public void write(PacketByteBuf packetByteBuf, FusionShrineRecipe recipe) { +// packetByteBuf.writeString(recipe.group); +// packetByteBuf.writeBoolean(recipe.secret); +// writeNullableIdentifier(packetByteBuf, recipe.requiredAdvancementIdentifier); +// +// packetByteBuf.writeShort(recipe.craftingInputs.size()); +// for (IngredientStack ingredientStack : recipe.craftingInputs) { +// ingredientStack.write(packetByteBuf); +// } +// +// writeFluidIngredient(packetByteBuf, recipe.fluid); +// packetByteBuf.writeItemStack(recipe.output); +// packetByteBuf.writeFloat(recipe.experience); +// packetByteBuf.writeInt(recipe.craftingTime); +// packetByteBuf.writeBoolean(recipe.yieldUpgradesDisabled); +// packetByteBuf.writeBoolean(recipe.playCraftingFinishedEffects); +// +// if (recipe.getDescription().isEmpty()) { +// packetByteBuf.writeText(Text.literal("")); +// } else { +// packetByteBuf.writeText(recipe.getDescription().get()); +// } +// packetByteBuf.writeBoolean(recipe.copyNbt); +// } +// +// +// @Override +// public FusionShrineRecipe read(Identifier identifier, PacketByteBuf packetByteBuf) { +// String group = packetByteBuf.readString(); +// boolean secret = packetByteBuf.readBoolean(); +// Identifier requiredAdvancementIdentifier = readNullableIdentifier(packetByteBuf); +// +// short craftingInputCount = packetByteBuf.readShort(); +// List ingredients = IngredientStack.decodeByteBuf(packetByteBuf, craftingInputCount); +// +// FluidIngredient fluid = readFluidIngredient(packetByteBuf); +// ItemStack output = packetByteBuf.readItemStack(); +// float experience = packetByteBuf.readFloat(); +// int craftingTime = packetByteBuf.readInt(); +// boolean yieldUpgradesDisabled = packetByteBuf.readBoolean(); +// boolean playCraftingFinishedEffects = packetByteBuf.readBoolean(); +// +// Text description = packetByteBuf.readText(); +// boolean copyNbt = packetByteBuf.readBoolean(); +// +// return this.recipeFactory.create(identifier, group, secret, requiredAdvancementIdentifier, +// ingredients, fluid, output, experience, craftingTime, yieldUpgradesDisabled, playCraftingFinishedEffects, copyNbt, +// List.of(), FusionShrineRecipeWorldEffect.NOTHING, List.of(), FusionShrineRecipeWorldEffect.NOTHING, description); +// } } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/EnchantedBookUnsoulingRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/EnchantedBookUnsoulingRecipe.java index 1602933e50..4554142c85 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/EnchantedBookUnsoulingRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/EnchantedBookUnsoulingRecipe.java @@ -4,37 +4,40 @@ import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.recipe.primordial_fire_burning.*; import net.minecraft.enchantment.*; -import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.recipe.*; +import net.minecraft.recipe.input.*; import net.minecraft.registry.*; -import net.minecraft.util.*; +import net.minecraft.registry.entry.*; import net.minecraft.world.*; public class EnchantedBookUnsoulingRecipe extends PrimordialFireBurningRecipe { public static final RecipeSerializer SERIALIZER = new EmptyRecipeSerializer<>(EnchantedBookUnsoulingRecipe::new); - public EnchantedBookUnsoulingRecipe(Identifier identifier) { + public EnchantedBookUnsoulingRecipe() { + // FIXME - What to do about enchantments here? super("", false, UNLOCK_IDENTIFIER, Ingredient.ofStacks(SpectrumEnchantmentHelper.addOrUpgradeEnchantment(Items.ENCHANTED_BOOK.getDefaultStack(), Enchantments.SOUL_SPEED, 1, false, false).getRight()), SpectrumEnchantmentHelper.addOrUpgradeEnchantment(Items.ENCHANTED_BOOK.getDefaultStack(), Enchantments.SWIFT_SNEAK, 1, false, false).getRight()); } @Override - public boolean matches(Inventory inv, World world) { - ItemStack stack = inv.getStack(0); - return EnchantmentHelper.get(stack).containsKey(Enchantments.SOUL_SPEED); + public boolean matches(RecipeInput inv, World world) { + ItemStack stack = inv.getStackInSlot(0); + RegistryEntry.Reference soulSpeed = world.getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(Enchantments.SOUL_SPEED).orElseThrow(); + return stack.getEnchantments().getEnchantments().contains(soulSpeed); } @Override public ItemStack craft(RecipeInput inv, RegistryWrapper.WrapperLookup drm) { - ItemStack stack = inv.getStack(0); + ItemStack stack = inv.getStackInSlot(0); - int level = EnchantmentHelper.get(stack).getOrDefault(Enchantments.SOUL_SPEED, 0); + RegistryEntry.Reference soulSpeed = drm.createRegistryLookup().getOptionalEntry(RegistryKeys.ENCHANTMENT, Enchantments.SOUL_SPEED).orElseThrow(); + int level = stack.getEnchantments().getLevel(soulSpeed); if(level > 0) { - stack = SpectrumEnchantmentHelper.removeEnchantments(stack, Enchantments.SOUL_SPEED).getLeft(); - stack = SpectrumEnchantmentHelper.addOrUpgradeEnchantment(stack, Enchantments.SWIFT_SNEAK, level, false, false).getRight(); + stack = SpectrumEnchantmentHelper.removeEnchantments(drm, stack, Enchantments.SOUL_SPEED).getLeft(); + stack = SpectrumEnchantmentHelper.addOrUpgradeEnchantment(drm, stack, Enchantments.SWIFT_SNEAK, level, false, false).getRight(); } return stack; } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/MemoryDementiaRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/MemoryDementiaRecipe.java index dc7a6173c7..d918d70462 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/MemoryDementiaRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/primordial_fire_burning/dynamic/MemoryDementiaRecipe.java @@ -5,32 +5,32 @@ import de.dafuqs.spectrum.recipe.primordial_fire_burning.*; import de.dafuqs.spectrum.registries.*; import net.minecraft.entity.*; -import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.recipe.*; +import net.minecraft.recipe.input.*; import net.minecraft.registry.*; -import net.minecraft.util.*; import net.minecraft.world.*; public class MemoryDementiaRecipe extends PrimordialFireBurningRecipe { public static final RecipeSerializer SERIALIZER = new EmptyRecipeSerializer<>(MemoryDementiaRecipe::new); - public MemoryDementiaRecipe(Identifier identifier) { + public MemoryDementiaRecipe() { super("", false, UNLOCK_IDENTIFIER, Ingredient.ofStacks(MemoryItem.getForEntityType(EntityType.BEE, 1), MemoryItem.getForEntityType(EntityType.FOX, 10), MemoryItem.getForEntityType(EntityType.SKELETON, 5), MemoryItem.getForEntityType(EntityType.HUSK, 50), MemoryItem.getForEntityType(EntityType.BLAZE, -1)), SpectrumBlocks.MEMORY.asItem().getDefaultStack()); } @Override - public boolean matches(Inventory inv, World world) { - return MemoryItem.getEntityType(inv.getStack(0).getNbt()).isPresent(); + public boolean matches(RecipeInput inv, World world) { + // FIXME - Component + return MemoryItem.getEntityType(inv.getStackInSlot(0).contains()); } @Override public ItemStack craft(RecipeInput inv, RegistryWrapper.WrapperLookup drm) { - ItemStack stack = inv.getStack(0); - stack.setNbt(null); + ItemStack stack = inv.getStackInSlot(0); + // FIXME - Set Component return stack; } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/SpiritInstillerRecipeSerializer.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/SpiritInstillerRecipeSerializer.java index 3173a2cf77..70be8e38a4 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/SpiritInstillerRecipeSerializer.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/SpiritInstillerRecipeSerializer.java @@ -1,78 +1,38 @@ package de.dafuqs.spectrum.recipe.spirit_instiller; -import com.google.gson.*; - +import com.mojang.serialization.*; import de.dafuqs.spectrum.api.recipe.*; import de.dafuqs.spectrum.recipe.*; -import net.minecraft.item.*; +import io.wispforest.endec.*; +import io.wispforest.endec.impl.*; +import io.wispforest.owo.serialization.*; +import io.wispforest.owo.serialization.endec.*; import net.minecraft.network.*; -import net.minecraft.util.*; +import net.minecraft.network.codec.*; public class SpiritInstillerRecipeSerializer implements GatedRecipeSerializer { - public final SpiritInstillerRecipeSerializer.RecipeFactory recipeFactory; - - public SpiritInstillerRecipeSerializer(SpiritInstillerRecipeSerializer.RecipeFactory recipeFactory) { - this.recipeFactory = recipeFactory; - } - - public interface RecipeFactory { - SpiritInstillerRecipe create(Identifier id, String group, boolean secret, Identifier requiredAdvancementIdentifier, IngredientStack centerIngredient, IngredientStack bowlIngredient1, IngredientStack bowlIngredient2, ItemStack outputItemStack, - int craftingTime, float experience, boolean noBenefitsFromYieldAndEfficiencyUpgrades); - } + public static final StructEndec ENDEC = StructEndecBuilder.of( + Endec.STRING.optionalFieldOf("group", recipe -> recipe.group, ""), + Endec.BOOLEAN.optionalFieldOf("secret", recipe -> recipe.secret, false), + MinecraftEndecs.IDENTIFIER.fieldOf("required_advancement", recipe -> recipe.requiredAdvancementIdentifier), + IngredientStack.Serializer.ENDEC.fieldOf("center_ingredient", recipe -> recipe.centerIngredient), + IngredientStack.Serializer.ENDEC.fieldOf("ingredient1", recipe -> recipe.bowlIngredient1), + IngredientStack.Serializer.ENDEC.fieldOf("ingredient2", recipe -> recipe.bowlIngredient2), + MinecraftEndecs.ITEM_STACK.fieldOf("result", recipe -> recipe.output), + Endec.INT.optionalFieldOf("time", recipe -> recipe.craftingTime, 200), + Endec.FLOAT.optionalFieldOf("experience", recipe -> recipe.experience, 1.0f), + Endec.BOOLEAN.optionalFieldOf("disable_yield_and_efficiency_upgrades", recipe -> recipe.noBenefitsFromYieldAndEfficiencyUpgrades, false), + SpiritInstillerRecipe::new + ); @Override - public SpiritInstillerRecipe read(Identifier identifier, JsonObject jsonObject) { - String group = readGroup(jsonObject); - boolean secret = readSecret(jsonObject); - Identifier requiredAdvancementIdentifier = readRequiredAdvancementIdentifier(jsonObject); - - IngredientStack centerIngredient = RecipeParser.ingredientStackFromJson(JsonHelper.getObject(jsonObject, "center_ingredient")); - IngredientStack bowlIngredient1 = RecipeParser.ingredientStackFromJson(JsonHelper.getObject(jsonObject, "ingredient1")); - IngredientStack bowlIngredient2 = RecipeParser.ingredientStackFromJson(JsonHelper.getObject(jsonObject, "ingredient2")); - ItemStack outputItemStack = RecipeUtils.itemStackWithNbtFromJson(JsonHelper.getObject(jsonObject, "result")); - - int craftingTime = JsonHelper.getInt(jsonObject, "time", 200); - float experience = JsonHelper.getFloat(jsonObject, "experience", 1.0F); - - boolean noBenefitsFromYieldAndEfficiencyUpgrades = false; - if (JsonHelper.hasPrimitive(jsonObject, "disable_yield_and_efficiency_upgrades")) { - noBenefitsFromYieldAndEfficiencyUpgrades = JsonHelper.getBoolean(jsonObject, "disable_yield_and_efficiency_upgrades", false); - } - - return this.recipeFactory.create(identifier, group, secret, requiredAdvancementIdentifier, centerIngredient, bowlIngredient1, bowlIngredient2, outputItemStack, craftingTime, experience, noBenefitsFromYieldAndEfficiencyUpgrades); + public MapCodec codec() { + return CodecUtils.toMapCodec(ENDEC); } @Override - public void write(PacketByteBuf packetByteBuf, SpiritInstillerRecipe recipe) { - packetByteBuf.writeString(recipe.group); - packetByteBuf.writeBoolean(recipe.secret); - writeNullableIdentifier(packetByteBuf, recipe.requiredAdvancementIdentifier); - - recipe.centerIngredient.write(packetByteBuf); - recipe.bowlIngredient1.write(packetByteBuf); - recipe.bowlIngredient2.write(packetByteBuf); - packetByteBuf.writeItemStack(recipe.output); - packetByteBuf.writeInt(recipe.craftingTime); - packetByteBuf.writeFloat(recipe.experience); - packetByteBuf.writeBoolean(recipe.noBenefitsFromYieldAndEfficiencyUpgrades); + public PacketCodec packetCodec() { + return CodecUtils.toPacketCodec(ENDEC); } - - @Override - public SpiritInstillerRecipe read(Identifier identifier, PacketByteBuf packetByteBuf) { - String group = packetByteBuf.readString(); - boolean secret = packetByteBuf.readBoolean(); - Identifier requiredAdvancementIdentifier = readNullableIdentifier(packetByteBuf); - - IngredientStack centerIngredient = IngredientStack.fromByteBuf(packetByteBuf); - IngredientStack bowlIngredient1 = IngredientStack.fromByteBuf(packetByteBuf); - IngredientStack bowlIngredient2 = IngredientStack.fromByteBuf(packetByteBuf); - ItemStack outputItemStack = packetByteBuf.readItemStack(); - int craftingTime = packetByteBuf.readInt(); - float experience = packetByteBuf.readFloat(); - boolean noBenefitsFromYieldAndEfficiencyUpgrades = packetByteBuf.readBoolean(); - - return this.recipeFactory.create(identifier, group, secret, requiredAdvancementIdentifier, centerIngredient, bowlIngredient1, bowlIngredient2, outputItemStack, craftingTime, experience, noBenefitsFromYieldAndEfficiencyUpgrades); - } - } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/MemoryToHeadRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/MemoryToHeadRecipe.java index f45b08860f..c01a229be7 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/MemoryToHeadRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/MemoryToHeadRecipe.java @@ -8,8 +8,9 @@ import de.dafuqs.spectrum.recipe.spirit_instiller.*; import de.dafuqs.spectrum.registries.*; import net.minecraft.block.*; +import net.minecraft.component.*; +import net.minecraft.component.type.*; import net.minecraft.entity.*; -import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.loot.*; import net.minecraft.loot.context.*; @@ -17,7 +18,6 @@ import net.minecraft.recipe.input.*; import net.minecraft.registry.*; import net.minecraft.server.world.*; -import net.minecraft.util.*; import net.minecraft.util.math.*; import java.util.*; @@ -39,7 +39,7 @@ public ItemStack craft(RecipeInput inv, RegistryWrapper.WrapperLookup drm) { ServerWorld world = (ServerWorld) spiritInstillerBlockEntity.getWorld(); BlockPos pos = spiritInstillerBlockEntity.getPos(); - /** + /* * This is moderately cursed * we spawn the entity from the memory, process its loot table with a custom damage type that guarantees a head drop, * search for a head drop in that loot and then discard that entity. @@ -89,13 +89,9 @@ private static Optional getSkullTypeForMemory(ItemStack in return Optional.empty(); } - // FIXME - Migrate to component - Optional> optionalMemoryEntity = MemoryItem.getEntityType(instillerStack.getNbt()); - if (optionalMemoryEntity.isEmpty()) { - return Optional.empty(); - } + Optional> optionalMemoryEntity = MemoryItem.getEntityType(instillerStack.getOrDefault(DataComponentTypes.ENTITY_DATA, NbtComponent.DEFAULT).copyNbt()); + return optionalMemoryEntity.flatMap(SpectrumSkullBlock::getSkullType); - return SpectrumSkullBlock.getSkullType(optionalMemoryEntity.get()); } } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerChangeRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerChangeRecipe.java index 3d243090c3..fa5ab1a023 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerChangeRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerChangeRecipe.java @@ -1,13 +1,13 @@ package de.dafuqs.spectrum.recipe.spirit_instiller.dynamic.spawner_manipulation; - import de.dafuqs.spectrum.blocks.item_bowl.*; import de.dafuqs.spectrum.blocks.spirit_instiller.*; import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.recipe.spirit_instiller.*; import de.dafuqs.spectrum.registries.*; import net.minecraft.block.entity.*; -import net.minecraft.inventory.*; +import net.minecraft.component.*; +import net.minecraft.component.type.*; import net.minecraft.item.*; import net.minecraft.nbt.*; import net.minecraft.recipe.*; @@ -47,10 +47,12 @@ public ItemStack craft(RecipeInput inv, RegistryWrapper.WrapperLookup drm) { ItemStack secondBowlStack = rightBowl.getStack(0); ItemStack spawnerStack = spiritInstillerBlockEntity.getStack(0); - NbtCompound spawnerNbt = spawnerStack.getOrCreateNbt(); + // TODO - Review + NbtComponent spawnerNbt = spawnerStack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT); + NbtCompound blockEntityTag; if (spawnerNbt.contains("BlockEntityTag")) { - blockEntityTag = spawnerNbt.getCompound("BlockEntityTag").copy(); + blockEntityTag = spawnerNbt.copyNbt().getCompound("BlockEntityTag"); } else { blockEntityTag = new NbtCompound(); } @@ -59,7 +61,8 @@ public ItemStack craft(RecipeInput inv, RegistryWrapper.WrapperLookup drm) { resultStack = spawnerStack.copy(); resultStack.setCount(1); - resultStack.setSubNbt("BlockEntityTag", blockEntityTag); + + resultStack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(blockEntityTag)); spawnXPAndGrantAdvancements(resultStack, spiritInstillerBlockEntity, spiritInstillerBlockEntity.getUpgradeHolder(), world, pos); } @@ -70,18 +73,18 @@ public ItemStack craft(RecipeInput inv, RegistryWrapper.WrapperLookup drm) { @Override public boolean canCraftWithStacks(RecipeInput inventory) { - NbtCompound blockEntityTag = inventory.getStackInSlot(0).getSubNbt("BlockEntityTag"); - if (blockEntityTag == null) { + NbtComponent blockEntityComponent = inventory.getStackInSlot(0).getOrDefault(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.DEFAULT); + if (blockEntityComponent == null) { return true; } - return canCraftWithBlockEntityTag(blockEntityTag, inventory.getStackInSlot(1), inventory.getStackInSlot(2)); + return canCraftWithBlockEntityTag(blockEntityComponent, inventory.getStackInSlot(1), inventory.getStackInSlot(2)); } // Overwrite these @Override public abstract RecipeSerializer getSerializer(); - public abstract boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack); + public abstract boolean canCraftWithBlockEntityTag(NbtComponent spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack); public abstract NbtCompound getSpawnerResultNbt(NbtCompound spawnerBlockEntityNbt, ItemStack secondBowlStack, ItemStack centerStack); diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerCreatureChangeRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerCreatureChangeRecipe.java index 87d88e507d..0db9ba9ad3 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerCreatureChangeRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerCreatureChangeRecipe.java @@ -1,9 +1,9 @@ package de.dafuqs.spectrum.recipe.spirit_instiller.dynamic.spawner_manipulation; - import de.dafuqs.spectrum.blocks.mob_head.*; import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.registries.*; +import net.minecraft.component.type.*; import net.minecraft.entity.*; import net.minecraft.item.*; import net.minecraft.nbt.*; @@ -18,12 +18,12 @@ public class SpawnerCreatureChangeRecipe extends SpawnerChangeRecipe { public static final RecipeSerializer SERIALIZER = new EmptyRecipeSerializer<>(SpawnerCreatureChangeRecipe::new); - public SpawnerCreatureChangeRecipe(Identifier identifier) { - super(IngredientStack.of(Ingredient.fromTag(SpectrumItemTags.SKULLS)), IngredientStack.ofItems(4, SpectrumItems.DOWNSTONE_FRAGMENTS), SpectrumAdvancements.SPAWNER_CREATURE_CHANGE); + public SpawnerCreatureChangeRecipe() { + super(IngredientStack.ofTag(SpectrumItemTags.SKULLS, 1), IngredientStack.ofItems(4, SpectrumItems.DOWNSTONE_FRAGMENTS), SpectrumAdvancements.SPAWNER_CREATURE_CHANGE); } @Override - public boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, ItemStack firstBowlStack, ItemStack secondBowlStack) { + public boolean canCraftWithBlockEntityTag(NbtComponent spawnerBlockEntityNbt, ItemStack firstBowlStack, ItemStack secondBowlStack) { Optional> entityType = SpectrumSkullBlock.getEntityTypeOfSkullStack(firstBowlStack); entityType = entityType.isEmpty() ? SpectrumSkullBlock.getEntityTypeOfSkullStack(secondBowlStack) : entityType; @@ -35,7 +35,7 @@ public boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, Ite } if (spawnerBlockEntityNbt.contains("SpawnData")) { - NbtCompound spawnData = spawnerBlockEntityNbt.getCompound("SpawnData"); + NbtCompound spawnData = spawnerBlockEntityNbt.copyNbt().getCompound("SpawnData"); if (spawnData.contains("entity")) { NbtCompound entity = spawnData.getCompound("entity"); if (entity.contains("id")) { diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerMaxNearbyEntitiesChangeRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerMaxNearbyEntitiesChangeRecipe.java index d4c8d7bf58..fe604d5bea 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerMaxNearbyEntitiesChangeRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerMaxNearbyEntitiesChangeRecipe.java @@ -3,25 +3,26 @@ import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.registries.*; +import net.minecraft.component.type.*; import net.minecraft.item.*; import net.minecraft.nbt.*; import net.minecraft.recipe.*; import net.minecraft.text.*; -import net.minecraft.util.*; public class SpawnerMaxNearbyEntitiesChangeRecipe extends SpawnerChangeRecipe { public static final RecipeSerializer SERIALIZER = new EmptyRecipeSerializer<>(SpawnerMaxNearbyEntitiesChangeRecipe::new); protected static final int DEFAULT_MAX_ENTITIES = 6; protected static final int MAX_MAX_ENTITIES = 40; - public SpawnerMaxNearbyEntitiesChangeRecipe(Identifier identifier) { + + public SpawnerMaxNearbyEntitiesChangeRecipe() { super(IngredientStack.ofItems(4, SpectrumItems.MERMAIDS_GEM)); } @Override - public boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { + public boolean canCraftWithBlockEntityTag(NbtComponent spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { if (spawnerBlockEntityNbt.contains("MaxNearbyEntities")) { - return spawnerBlockEntityNbt.getShort("MaxNearbyEntities") < MAX_MAX_ENTITIES; + return spawnerBlockEntityNbt.copyNbt().getShort("MaxNearbyEntities") < MAX_MAX_ENTITIES; } return true; } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerRequiredPlayerRangeChangeRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerRequiredPlayerRangeChangeRecipe.java index d0b85537c0..7e5a20f514 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerRequiredPlayerRangeChangeRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerRequiredPlayerRangeChangeRecipe.java @@ -3,25 +3,26 @@ import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.registries.*; +import net.minecraft.component.type.*; import net.minecraft.item.*; import net.minecraft.nbt.*; import net.minecraft.recipe.*; import net.minecraft.text.*; -import net.minecraft.util.*; public class SpawnerRequiredPlayerRangeChangeRecipe extends SpawnerChangeRecipe { public static final RecipeSerializer SERIALIZER = new EmptyRecipeSerializer<>(SpawnerRequiredPlayerRangeChangeRecipe::new); protected static final int DEFAULT_DETECTION_RANGE = 16; protected static final int MAX_DETECTION_RANGE = 64; - public SpawnerRequiredPlayerRangeChangeRecipe(Identifier identifier) { + + public SpawnerRequiredPlayerRangeChangeRecipe() { super(IngredientStack.ofItems(4, SpectrumItems.STRATINE_GEM)); } @Override - public boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { + public boolean canCraftWithBlockEntityTag(NbtComponent spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { if (spawnerBlockEntityNbt.contains("RequiredPlayerRange")) { - return spawnerBlockEntityNbt.getShort("RequiredPlayerRange") < MAX_DETECTION_RANGE; + return spawnerBlockEntityNbt.copyNbt().getShort("RequiredPlayerRange") < MAX_DETECTION_RANGE; } return true; } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnCountChangeRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnCountChangeRecipe.java index 45f31f9f8d..521c6a8aa9 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnCountChangeRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnCountChangeRecipe.java @@ -3,25 +3,25 @@ import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.registries.*; +import net.minecraft.component.type.*; import net.minecraft.item.*; import net.minecraft.nbt.*; import net.minecraft.recipe.*; import net.minecraft.text.*; -import net.minecraft.util.*; public class SpawnerSpawnCountChangeRecipe extends SpawnerChangeRecipe { public static final RecipeSerializer SERIALIZER = new EmptyRecipeSerializer<>(SpawnerSpawnCountChangeRecipe::new); protected static final int DEFAULT_SPAWN_COUNT = 4; protected static final int MAX_SPAWN_COUNT = 16; - public SpawnerSpawnCountChangeRecipe(Identifier identifier) { + public SpawnerSpawnCountChangeRecipe() { super(IngredientStack.ofItems(4, SpectrumItems.NEOLITH)); } @Override - public boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { + public boolean canCraftWithBlockEntityTag(NbtComponent spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { if (spawnerBlockEntityNbt.contains("SpawnCount")) { - return spawnerBlockEntityNbt.getShort("SpawnCount") < MAX_SPAWN_COUNT; + return spawnerBlockEntityNbt.copyNbt().getShort("SpawnCount") < MAX_SPAWN_COUNT; } return true; } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnDelayChangeRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnDelayChangeRecipe.java index 035d75a7ae..73537ac7d6 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnDelayChangeRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/spirit_instiller/dynamic/spawner_manipulation/SpawnerSpawnDelayChangeRecipe.java @@ -1,13 +1,12 @@ package de.dafuqs.spectrum.recipe.spirit_instiller.dynamic.spawner_manipulation; - import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.registries.*; +import net.minecraft.component.type.*; import net.minecraft.item.*; import net.minecraft.nbt.*; import net.minecraft.recipe.*; import net.minecraft.text.*; -import net.minecraft.util.*; public class SpawnerSpawnDelayChangeRecipe extends SpawnerChangeRecipe { @@ -15,15 +14,15 @@ public class SpawnerSpawnDelayChangeRecipe extends SpawnerChangeRecipe { protected static final int DEFAULT_MIN_DELAY = 200; protected static final int DEFAULT_MAX_DELAY = 800; protected static final int MIN_DELAY = 20; - public SpawnerSpawnDelayChangeRecipe(Identifier identifier) { + public SpawnerSpawnDelayChangeRecipe() { super(IngredientStack.ofItems(4, SpectrumItems.MIDNIGHT_CHIP)); } @Override - public boolean canCraftWithBlockEntityTag(NbtCompound spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { + public boolean canCraftWithBlockEntityTag(NbtComponent spawnerBlockEntityNbt, ItemStack leftBowlStack, ItemStack rightBowlStack) { if (spawnerBlockEntityNbt.contains("MinSpawnDelay") && spawnerBlockEntityNbt.contains("MaxSpawnDelay")) { - return spawnerBlockEntityNbt.getShort("MinSpawnDelay") > MIN_DELAY - && spawnerBlockEntityNbt.getShort("MaxSpawnDelay") > MIN_DELAY; + return spawnerBlockEntityNbt.copyNbt().getShort("MinSpawnDelay") > MIN_DELAY + && spawnerBlockEntityNbt.copyNbt().getShort("MaxSpawnDelay") > MIN_DELAY; } return true; } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationData.java b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationData.java index 9f7c8de74d..29bbb2e9eb 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationData.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationData.java @@ -1,18 +1,32 @@ package de.dafuqs.spectrum.recipe.titration_barrel; import com.google.gson.*; +import io.wispforest.endec.*; +import io.wispforest.endec.impl.*; import net.minecraft.network.*; import net.minecraft.util.*; import java.util.*; -public record FermentationData(float fermentationSpeedMod, float angelsSharePercentPerMcDay, - List statusEffectEntries) { +public record FermentationData( + float fermentationSpeedMod, + float angelsSharePercentPerMcDay, + List statusEffectEntries +) { private static final String FERMENTATION_SPEED_MOD_STRING = "fermentation_speed_mod"; private static final String ANGELS_SHARE_STRING = "angels_share_percent_per_mc_day"; private static final String EFFECTS_STRING = "effects"; + public static final StructEndec ENDEC = StructEndecBuilder.of( + Endec.FLOAT.fieldOf(FERMENTATION_SPEED_MOD_STRING, FermentationData::fermentationSpeedMod), + Endec.FLOAT.fieldOf(ANGELS_SHARE_STRING, FermentationData::angelsSharePercentPerMcDay), + FermentationStatusEffectEntry.FERMENTATION_ENTRY_ENDEC.listOf().fieldOf(EFFECTS_STRING, FermentationData::statusEffectEntries), + FermentationData::new + ); + + // TODO - Once the loot functions that use this, E.G. FermentRandomlyLootFunction + // TODO - then all of these, including the nested data structures, should fall away public static FermentationData fromJson(JsonObject jsonObject) { float fermentationSpeedMod = JsonHelper.getFloat(jsonObject, FERMENTATION_SPEED_MOD_STRING, 1.0F); float angelsSharePerMcDay = JsonHelper.getFloat(jsonObject, ANGELS_SHARE_STRING, 0.01F); diff --git a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationStatusEffectEntry.java b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationStatusEffectEntry.java index 2a4aad66c2..5fadef1831 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationStatusEffectEntry.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/FermentationStatusEffectEntry.java @@ -2,6 +2,9 @@ import com.google.gson.*; import de.dafuqs.spectrum.*; +import io.wispforest.endec.*; +import io.wispforest.endec.impl.*; +import io.wispforest.owo.serialization.endec.*; import net.minecraft.entity.effect.*; import net.minecraft.network.*; import net.minecraft.registry.*; @@ -9,8 +12,17 @@ import java.util.*; -public record FermentationStatusEffectEntry(StatusEffect statusEffect, int baseDuration, - List potencyEntries) { +public record FermentationStatusEffectEntry( + StatusEffect statusEffect, + int baseDuration, + List potencyEntries) { + + public static final StructEndec FERMENTATION_ENTRY_ENDEC = StructEndecBuilder.of( + MinecraftEndecs.ofRegistry(Registries.STATUS_EFFECT).fieldOf("status_effect", FermentationStatusEffectEntry::statusEffect), + Endec.INT.fieldOf("base_duration", FermentationStatusEffectEntry::baseDuration), + StatusEffectPotencyEntry.POTENCY_ENDEC.listOf().fieldOf("potency_entries", FermentationStatusEffectEntry::potencyEntries), + FermentationStatusEffectEntry::new + ); public record StatusEffectPotencyEntry(int minAlcPercent, int minThickness, int potency) { @@ -18,6 +30,13 @@ public record StatusEffectPotencyEntry(int minAlcPercent, int minThickness, int private static final String MIN_THICKNESS_STRING = "min_thickness"; private static final String MIN_POTENCY_STRING = "potency"; + public static final StructEndec POTENCY_ENDEC = StructEndecBuilder.of( + Endec.INT.fieldOf(MIN_ALC_STRING, StatusEffectPotencyEntry::minAlcPercent), + Endec.INT.fieldOf(MIN_THICKNESS_STRING, StatusEffectPotencyEntry::minThickness), + Endec.INT.fieldOf(MIN_POTENCY_STRING, StatusEffectPotencyEntry::potency), + StatusEffectPotencyEntry::new + ); + public static StatusEffectPotencyEntry fromJson(JsonObject jsonObject) { int minAlcPercent = JsonHelper.getInt(jsonObject, MIN_ALC_STRING, 0); int minThickness = JsonHelper.getInt(jsonObject, MIN_THICKNESS_STRING, 0); @@ -53,7 +72,7 @@ public static FermentationStatusEffectEntry fromJson(JsonObject jsonObject) { StatusEffect statusEffect = Registries.STATUS_EFFECT.get(statusEffectIdentifier); if (statusEffect == null) { SpectrumCommon.logError("Status effect " + statusEffectIdentifier + " does not exist in the status effect registry. Falling back to WEAKNESS"); - statusEffect = StatusEffects.WEAKNESS; + statusEffect = StatusEffects.WEAKNESS.value(); } int baseDuration = JsonHelper.getInt(jsonObject, BASE_DURATION_STRING, 1200); diff --git a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/TitrationBarrelRecipeSerializer.java b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/TitrationBarrelRecipeSerializer.java index b64438d4ff..8c92fa83d3 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/TitrationBarrelRecipeSerializer.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/TitrationBarrelRecipeSerializer.java @@ -1,31 +1,29 @@ package de.dafuqs.spectrum.recipe.titration_barrel; -import com.google.gson.*; -import de.dafuqs.spectrum.*; import de.dafuqs.spectrum.api.recipe.*; import de.dafuqs.spectrum.recipe.*; import io.wispforest.endec.*; import io.wispforest.endec.impl.*; import io.wispforest.owo.serialization.*; -import net.minecraft.item.*; -import net.minecraft.network.*; -import net.minecraft.recipe.*; +import io.wispforest.owo.serialization.endec.*; import net.minecraft.registry.*; -import net.minecraft.util.*; - -import java.util.*; public class TitrationBarrelRecipeSerializer extends EndecRecipeSerializer implements GatedRecipeSerializer { - public static final StructEndec ENDEC = StructEndecBuilder.of( - CodecUtils.toEndec(Ingredient.ALLOW_EMPTY_CODEC).fieldOf("ingredients", s -> s.ingredients), - // FIXME + public static final StructEndec ENDEC = StructEndecBuilder.of( + Endec.STRING.optionalFieldOf("group", recipe -> recipe.group, ""), + Endec.BOOLEAN.optionalFieldOf("secret", recipe -> recipe.secret, false), + MinecraftEndecs.IDENTIFIER.fieldOf("required_advancement", recipe -> recipe.requiredAdvancementIdentifier), + IngredientStack.Serializer.ENDEC.listOf().fieldOf("ingredients", recipe -> recipe.inputStacks), + FluidIngredient.ENDEC.fieldOf("fluid", recipe -> recipe.fluid), + MinecraftEndecs.ITEM_STACK.fieldOf("result", recipe -> recipe.outputItemStack), + MinecraftEndecs.ofRegistry(Registries.ITEM).fieldOf("tapping_item", recipe -> recipe.tappingItem), + Endec.INT.fieldOf("min_fermentation_time_hours", recipe -> recipe.minFermentationTimeHours), + FermentationData.ENDEC.fieldOf("fermentation_data", recipe -> recipe.fermentationData), TitrationBarrelRecipe::new ); public TitrationBarrelRecipeSerializer() { super(ENDEC); } - - } diff --git a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/dynamic/CheongRecipe.java b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/dynamic/CheongRecipe.java index 5dd093a09c..223bd3b07a 100644 --- a/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/dynamic/CheongRecipe.java +++ b/src/main/java/de/dafuqs/spectrum/recipe/titration_barrel/dynamic/CheongRecipe.java @@ -1,6 +1,5 @@ package de.dafuqs.spectrum.recipe.titration_barrel.dynamic; -import de.dafuqs.matchbooks.recipe.matchbook.*; import de.dafuqs.spectrum.api.recipe.*; import de.dafuqs.spectrum.recipe.*; import de.dafuqs.spectrum.recipe.IngredientStack; @@ -10,7 +9,6 @@ import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.recipe.*; -import net.minecraft.util.*; import java.util.*; diff --git a/src/main/java/de/dafuqs/spectrum/registries/SpectrumRecipeTypes.java b/src/main/java/de/dafuqs/spectrum/registries/SpectrumRecipeTypes.java index 9febbde1a4..de35305683 100644 --- a/src/main/java/de/dafuqs/spectrum/registries/SpectrumRecipeTypes.java +++ b/src/main/java/de/dafuqs/spectrum/registries/SpectrumRecipeTypes.java @@ -114,7 +114,7 @@ public static void registerSerializer() { ANVIL_CRUSHING_RECIPE_SERIALIZER = registerSerializer(ANVIL_CRUSHING_ID, new AnvilCrushingRecipeSerializer()); ANVIL_CRUSHING = registerRecipeType(ANVIL_CRUSHING_ID); - FUSION_SHRINE_RECIPE_SERIALIZER = registerSerializer(FUSION_SHRINE_ID, new FusionShrineRecipeSerializer(FusionShrineRecipe::new)); + FUSION_SHRINE_RECIPE_SERIALIZER = registerSerializer(FUSION_SHRINE_ID, new FusionShrineRecipeSerializer()); FUSION_SHRINE = registerRecipeType(FUSION_SHRINE_ID); ENCHANTER_RECIPE_SERIALIZER = registerSerializer(ENCHANTER_ID, new EnchanterRecipeSerializer()); @@ -144,7 +144,7 @@ public static void registerSerializer() { DRAGONROT_CONVERTING_SERIALIZER = registerSerializer(DRAGONROT_CONVERTING_ID, new FluidConvertingRecipeSerializer()); DRAGONROT_CONVERTING = registerRecipeType(DRAGONROT_CONVERTING_ID); - SPIRIT_INSTILLING_SERIALIZER = registerSerializer(SPIRIT_INSTILLING_ID, new SpiritInstillerRecipeSerializer((id, group, secret, requiredAdvancementIdentifier, centerIngredient, bowlIngredient1, bowlIngredient2, output, craftingTime, experience, noBenefitsFromYieldAndEfficiencyUpgrades) -> new SpiritInstillerRecipe(group, secret, requiredAdvancementIdentifier, centerIngredient, bowlIngredient1, bowlIngredient2, output, craftingTime, experience, noBenefitsFromYieldAndEfficiencyUpgrades))); + SPIRIT_INSTILLING_SERIALIZER = registerSerializer(SPIRIT_INSTILLING_ID, new SpiritInstillerRecipeSerializer()); SPIRIT_INSTILLING = registerRecipeType(SPIRIT_INSTILLING_ID); INK_CONVERTING_RECIPE_SERIALIZER = registerSerializer(INK_CONVERTING_ID, new InkConvertingRecipeSerializer());