Start on recipe serde rewrite
This commit is contained in:
parent
5eab27bead
commit
47eea962a0
17 changed files with 411 additions and 229 deletions
|
@ -30,51 +30,51 @@ import net.minecraft.item.ItemConvertible
|
|||
import net.minecraft.item.Items
|
||||
import net.minecraft.recipe.CookingRecipeSerializer
|
||||
import net.minecraft.recipe.RecipeSerializer
|
||||
import techreborn.datagen.tags.CommonTagsTrait
|
||||
import techreborn.datagen.tags.CommonTags
|
||||
import techreborn.init.TRContent
|
||||
|
||||
class SmeltingRecipesProvider extends TechRebornRecipesProvider implements CommonTagsTrait {
|
||||
class SmeltingRecipesProvider extends TechRebornRecipesProvider {
|
||||
SmeltingRecipesProvider(FabricDataGenerator dataGenerator) {
|
||||
super(dataGenerator)
|
||||
}
|
||||
|
||||
@Override
|
||||
void generateRecipes() {
|
||||
// Add smelting and blasting recipes.
|
||||
[
|
||||
(TRContent.Ingots.MIXED_METAL): TRContent.Ingots.ADVANCED_ALLOY,
|
||||
(cItem("brass_dusts")): TRContent.Ingots.BRASS,
|
||||
(TRContent.Dusts.BRONZE): TRContent.Ingots.BRONZE,
|
||||
(cItem("electrum_dusts")): TRContent.Ingots.ELECTRUM,
|
||||
(TRContent.Dusts.INVAR): TRContent.Ingots.INVAR,
|
||||
(cItem("lead_ores")): TRContent.Ingots.LEAD,
|
||||
(cItem("raw_lead_ores")): TRContent.Ingots.LEAD,
|
||||
(TRContent.Dusts.NICKEL): TRContent.Ingots.NICKEL,
|
||||
(cItem("sheldonite_ores")): TRContent.Ingots.PLATINUM,
|
||||
(cItem("platinum_dusts")): TRContent.Ingots.PLATINUM,
|
||||
(Items.IRON_INGOT): TRContent.Ingots.REFINED_IRON,
|
||||
(cItem("silver_ores")): TRContent.Ingots.SILVER,
|
||||
(cItem("raw_silver_ores")): TRContent.Ingots.SILVER,
|
||||
(cItem("tin_ores")): TRContent.Ingots.TIN,
|
||||
(cItem("raw_tin_ores")): TRContent.Ingots.TIN,
|
||||
(cItem("zinc_dusts")): TRContent.Ingots.ZINC
|
||||
].each {input, output ->
|
||||
offerSmelting(input, output)
|
||||
offerBlasting(input, output)
|
||||
}
|
||||
// Add smelting and blasting recipes.
|
||||
[
|
||||
(TRContent.Ingots.MIXED_METAL) : TRContent.Ingots.ADVANCED_ALLOY,
|
||||
(CommonTags.Items.brassDusts) : TRContent.Ingots.BRASS,
|
||||
(TRContent.Dusts.BRONZE) : TRContent.Ingots.BRONZE,
|
||||
(CommonTags.Items.electrumDusts): TRContent.Ingots.ELECTRUM,
|
||||
(TRContent.Dusts.INVAR) : TRContent.Ingots.INVAR,
|
||||
(CommonTags.Items.leadOres) : TRContent.Ingots.LEAD,
|
||||
(CommonTags.Items.rawLeadOres) : TRContent.Ingots.LEAD,
|
||||
(TRContent.Dusts.NICKEL) : TRContent.Ingots.NICKEL,
|
||||
(CommonTags.Items.sheldoniteOres) : TRContent.Ingots.PLATINUM,
|
||||
(CommonTags.Items.platinumDusts) : TRContent.Ingots.PLATINUM,
|
||||
(Items.IRON_INGOT) : TRContent.Ingots.REFINED_IRON,
|
||||
(CommonTags.Items.silverOres) : TRContent.Ingots.SILVER,
|
||||
(CommonTags.Items.rawSilverOres) : TRContent.Ingots.SILVER,
|
||||
(CommonTags.Items.tinOres) : TRContent.Ingots.TIN,
|
||||
(CommonTags.Items.rawTinOres) : TRContent.Ingots.TIN,
|
||||
(CommonTags.Items.zincDusts) : TRContent.Ingots.ZINC
|
||||
].each { input, output ->
|
||||
offerSmelting(input, output)
|
||||
offerBlasting(input, output)
|
||||
}
|
||||
}
|
||||
|
||||
def offerSmelting(def input, ItemConvertible output, float experience = 0.5f, int cookingTime = 200) {
|
||||
offerCookingRecipe(input, output, experience, cookingTime, RecipeSerializer.SMELTING, "smelting/")
|
||||
}
|
||||
def offerSmelting(def input, ItemConvertible output, float experience = 0.5f, int cookingTime = 200) {
|
||||
offerCookingRecipe(input, output, experience, cookingTime, RecipeSerializer.SMELTING, "smelting/")
|
||||
}
|
||||
|
||||
def offerBlasting(def input, ItemConvertible output, float experience = 0.5f, int cookingTime = 200) {
|
||||
offerCookingRecipe(input, output, experience, cookingTime, RecipeSerializer.BLASTING, "blasting/")
|
||||
}
|
||||
def offerBlasting(def input, ItemConvertible output, float experience = 0.5f, int cookingTime = 200) {
|
||||
offerCookingRecipe(input, output, experience, cookingTime, RecipeSerializer.BLASTING, "blasting/")
|
||||
}
|
||||
|
||||
def offerCookingRecipe(def input, ItemConvertible output, float experience, int cookingTime, CookingRecipeSerializer<?> serializer, String prefix = "") {
|
||||
CookingRecipeJsonFactory.create(createIngredient(input), output, experience, cookingTime, serializer)
|
||||
.criterion(getCriterionName(input), getCriterionConditions(input))
|
||||
.offerTo(this.exporter, prefix + getInputPath(output) + "_from_" + getInputPath(input))
|
||||
def offerCookingRecipe(def input, ItemConvertible output, float experience, int cookingTime, CookingRecipeSerializer<?> serializer, String prefix = "") {
|
||||
CookingRecipeJsonFactory.create(createIngredient(input), output, experience, cookingTime, serializer)
|
||||
.criterion(getCriterionName(input), getCriterionConditions(input))
|
||||
.offerTo(this.exporter, prefix + getInputPath(output) + "_from_" + getInputPath(input))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,28 @@
|
|||
package techreborn.datagen.tags
|
||||
|
||||
import net.fabricmc.fabric.api.tag.TagFactory
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.tag.Tag
|
||||
import net.minecraft.util.Identifier
|
||||
|
||||
trait CommonTagsTrait {
|
||||
static Tag.Identified<Item> cItem(String path) {
|
||||
return TagFactory.ITEM.create(new Identifier("c", path))
|
||||
}
|
||||
class CommonTags {
|
||||
static class Items {
|
||||
public static zincIngots = create("zinc_ingots")
|
||||
|
||||
public static brassDusts = create("brass_dusts")
|
||||
public static electrumDusts = create("electrum_dusts")
|
||||
public static platinumDusts = create("platinum_dusts")
|
||||
public static zincDusts = create("zinc_dusts")
|
||||
|
||||
public static leadOres = create("lead_ores")
|
||||
public static sheldoniteOres = create("sheldonite_ores")
|
||||
public static silverOres = create("silver_ores")
|
||||
public static tinOres = create("tin_ores")
|
||||
|
||||
public static rawLeadOres = create("raw_lead_ores")
|
||||
public static rawSilverOres = create("raw_silver_ores")
|
||||
public static rawTinOres = create("raw_tin_ores")
|
||||
|
||||
private static def create(String path) {
|
||||
return TagFactory.ITEM.create(new Identifier("c", path))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,47 +38,25 @@ import net.minecraft.util.collection.DefaultedList;
|
|||
import net.minecraft.world.World;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.DummyIngredient;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RollingMachineRecipe extends RebornRecipe {
|
||||
|
||||
private ShapedRecipe shapedRecipe;
|
||||
private final ShapedRecipe shapedRecipe;
|
||||
private final JsonObject shapedRecipeJson;
|
||||
|
||||
public RollingMachineRecipe(RebornRecipeType<?> type, Identifier name) {
|
||||
super(type, name);
|
||||
this(type, name, List.of(new DummyIngredient()), Collections.emptyList(), Integer.MAX_VALUE, Integer.MAX_VALUE, null, null);
|
||||
this.dummy = true;
|
||||
}
|
||||
|
||||
public RollingMachineRecipe(RebornRecipeType<?> type, Identifier name, ShapedRecipe recipe) {
|
||||
super(type, name);
|
||||
this.shapedRecipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(JsonObject jsonObject) {
|
||||
if (jsonObject.has("shaped")) {
|
||||
JsonObject json = JsonHelper.getObject(jsonObject, "shaped");
|
||||
shapedRecipe = RecipeSerializer.SHAPED.read(getId(), json);
|
||||
} else {
|
||||
//This will be handled by the PacketByteBuf deserialize
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PacketByteBuf byteBuf) {
|
||||
String s = shapedRecipe.getId().toString();
|
||||
byteBuf.writeInt(s.length());
|
||||
byteBuf.writeString(s);
|
||||
RecipeSerializer.SHAPED.write(byteBuf, shapedRecipe);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(PacketByteBuf byteBuf) {
|
||||
Identifier identifier = new Identifier(byteBuf.readString(byteBuf.readInt()));
|
||||
shapedRecipe = RecipeSerializer.SHAPED.read(identifier, byteBuf);
|
||||
public RollingMachineRecipe(RebornRecipeType<?> type, Identifier name, List<RebornIngredient> ingredients, List<ItemStack> outputs, int power, int time, ShapedRecipe shapedRecipe, JsonObject shapedRecipeJson) {
|
||||
super(type, name, ingredients, outputs, power, time);
|
||||
this.shapedRecipe = shapedRecipe;
|
||||
this.shapedRecipeJson = shapedRecipeJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,4 +97,8 @@ public class RollingMachineRecipe extends RebornRecipe {
|
|||
public ShapedRecipe getShapedRecipe() {
|
||||
return shapedRecipe;
|
||||
}
|
||||
|
||||
public JsonObject getShapedRecipeJson() {
|
||||
return shapedRecipeJson;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package techreborn.api.recipe.recipes;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.crafting.serde.RebornRecipeSerde;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RollingMachineRecipeSerde extends RebornRecipeSerde<RollingMachineRecipe> {
|
||||
@Override
|
||||
protected RollingMachineRecipe fromJson(JsonObject jsonObject, RebornRecipeType<RollingMachineRecipe> type, Identifier name, List<RebornIngredient> ingredients, List<ItemStack> outputs, int power, int time) {
|
||||
final JsonObject json = JsonHelper.getObject(jsonObject, "shaped");
|
||||
final ShapedRecipe shapedRecipe = RecipeSerializer.SHAPED.read(name, json);
|
||||
return new RollingMachineRecipe(type, name, ingredients, outputs, power, time, shapedRecipe, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(RollingMachineRecipe recipe, JsonObject jsonObject) {
|
||||
super.toJson(recipe, jsonObject);
|
||||
|
||||
if (recipe.getShapedRecipeJson() != null) {
|
||||
jsonObject.add("shaped", recipe.getShapedRecipeJson());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RollingMachineRecipe createDummy(RebornRecipeType<RollingMachineRecipe> type, Identifier name) {
|
||||
return new RollingMachineRecipe(type, name);
|
||||
}
|
||||
}
|
|
@ -33,27 +33,27 @@ import techreborn.api.recipe.recipes.*;
|
|||
|
||||
public class ModRecipes {
|
||||
|
||||
public static final RebornRecipeType<RebornRecipe> ALLOY_SMELTER = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:alloy_smelter"));
|
||||
public static final RebornRecipeType<RebornRecipe> ASSEMBLING_MACHINE = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:assembling_machine"));
|
||||
public static final RebornRecipeType<BlastFurnaceRecipe> BLAST_FURNACE = RecipeManager.newRecipeType(BlastFurnaceRecipe::new, new Identifier("techreborn:blast_furnace"));
|
||||
public static final RebornRecipeType<RebornRecipe> CENTRIFUGE = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:centrifuge"));
|
||||
public static final RebornRecipeType<RebornRecipe> CHEMICAL_REACTOR = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:chemical_reactor"));
|
||||
public static final RebornRecipeType<RebornRecipe> COMPRESSOR = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:compressor"));
|
||||
public static final RebornRecipeType<RebornRecipe> DISTILLATION_TOWER = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:distillation_tower"));
|
||||
public static final RebornRecipeType<RebornRecipe> EXTRACTOR = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:extractor"));
|
||||
public static final RebornRecipeType<RebornRecipe> GRINDER = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:grinder"));
|
||||
public static final RebornRecipeType<RebornRecipe> IMPLOSION_COMPRESSOR = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:implosion_compressor"));
|
||||
public static final RebornRecipeType<RebornRecipe> INDUSTRIAL_ELECTROLYZER = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:industrial_electrolyzer"));
|
||||
public static final RebornRecipeType<IndustrialGrinderRecipe> INDUSTRIAL_GRINDER = RecipeManager.newRecipeType(IndustrialGrinderRecipe::new, new Identifier("techreborn:industrial_grinder"));
|
||||
public static final RebornRecipeType<IndustrialSawmillRecipe> INDUSTRIAL_SAWMILL = RecipeManager.newRecipeType(IndustrialSawmillRecipe::new, new Identifier("techreborn:industrial_sawmill"));
|
||||
public static final RebornRecipeType<RebornRecipe> RECYCLER = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:recycler"));
|
||||
public static final RebornRecipeType<RebornRecipe> SCRAPBOX = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:scrapbox"));
|
||||
public static final RebornRecipeType<RebornRecipe> VACUUM_FREEZER = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:vacuum_freezer"));
|
||||
public static final RebornRecipeType<FluidReplicatorRecipe> FLUID_REPLICATOR = RecipeManager.newRecipeType(FluidReplicatorRecipe::new, new Identifier("techreborn:fluid_replicator"));
|
||||
public static final RebornRecipeType<FusionReactorRecipe> FUSION_REACTOR = RecipeManager.newRecipeType(FusionReactorRecipe::new, new Identifier("techreborn:fusion_reactor"));
|
||||
public static final RebornRecipeType<RollingMachineRecipe> ROLLING_MACHINE = RecipeManager.newRecipeType(RollingMachineRecipe::new, new Identifier("techreborn:rolling_machine"));
|
||||
public static final RebornRecipeType<RebornRecipe> SOLID_CANNING_MACHINE = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:solid_canning_machine"));
|
||||
public static final RebornRecipeType<RebornRecipe> WIRE_MILL = RecipeManager.newRecipeType(RebornRecipe::new, new Identifier("techreborn:wire_mill"));
|
||||
public static final RebornRecipeType<RebornRecipe> ALLOY_SMELTER = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:alloy_smelter"));
|
||||
public static final RebornRecipeType<RebornRecipe> ASSEMBLING_MACHINE = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:assembling_machine"));
|
||||
public static final RebornRecipeType<BlastFurnaceRecipe> BLAST_FURNACE = RecipeManager.newRecipeType(BlastFurnaceRecipe::deserialize, new Identifier("techreborn:blast_furnace"));
|
||||
public static final RebornRecipeType<RebornRecipe> CENTRIFUGE = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:centrifuge"));
|
||||
public static final RebornRecipeType<RebornRecipe> CHEMICAL_REACTOR = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:chemical_reactor"));
|
||||
public static final RebornRecipeType<RebornRecipe> COMPRESSOR = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:compressor"));
|
||||
public static final RebornRecipeType<RebornRecipe> DISTILLATION_TOWER = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:distillation_tower"));
|
||||
public static final RebornRecipeType<RebornRecipe> EXTRACTOR = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:extractor"));
|
||||
public static final RebornRecipeType<RebornRecipe> GRINDER = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:grinder"));
|
||||
public static final RebornRecipeType<RebornRecipe> IMPLOSION_COMPRESSOR = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:implosion_compressor"));
|
||||
public static final RebornRecipeType<RebornRecipe> INDUSTRIAL_ELECTROLYZER = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:industrial_electrolyzer"));
|
||||
public static final RebornRecipeType<IndustrialGrinderRecipe> INDUSTRIAL_GRINDER = RecipeManager.newRecipeType(IndustrialGrinderRecipe::deserialize, new Identifier("techreborn:industrial_grinder"));
|
||||
public static final RebornRecipeType<IndustrialSawmillRecipe> INDUSTRIAL_SAWMILL = RecipeManager.newRecipeType(IndustrialSawmillRecipe::deserialize, new Identifier("techreborn:industrial_sawmill"));
|
||||
public static final RebornRecipeType<RebornRecipe> RECYCLER = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:recycler"));
|
||||
public static final RebornRecipeType<RebornRecipe> SCRAPBOX = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:scrapbox"));
|
||||
public static final RebornRecipeType<RebornRecipe> VACUUM_FREEZER = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:vacuum_freezer"));
|
||||
public static final RebornRecipeType<FluidReplicatorRecipe> FLUID_REPLICATOR = RecipeManager.newRecipeType(FluidReplicatorRecipe::deserialize, new Identifier("techreborn:fluid_replicator"));
|
||||
public static final RebornRecipeType<FusionReactorRecipe> FUSION_REACTOR = RecipeManager.newRecipeType(FusionReactorRecipe::deserialize, new Identifier("techreborn:fusion_reactor"));
|
||||
public static final RebornRecipeType<RollingMachineRecipe> ROLLING_MACHINE = RecipeManager.newRecipeType(RollingMachineRecipe::deserialize, new Identifier("techreborn:rolling_machine"));
|
||||
public static final RebornRecipeType<RebornRecipe> SOLID_CANNING_MACHINE = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:solid_canning_machine"));
|
||||
public static final RebornRecipeType<RebornRecipe> WIRE_MILL = RecipeManager.newRecipeType(RebornRecipe::deserialize, new Identifier("techreborn:wire_mill"));
|
||||
|
||||
public static RebornRecipeType<?> byName(Identifier identifier) {
|
||||
return (RebornRecipeType<?>) Registry.RECIPE_SERIALIZER.get(identifier);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue