mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Experimental: Move elven trade recipes to vanilla json system
This commit is contained in:
1 parent
df3f177180
commit
188cf3f5a0
23 files changed
+484
-56
No files matched your search
@@ -10,16 +10,30 @@ package vazkii.botania.api.recipe;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RecipeElvenTrade {
|
||||
public class RecipeElvenTrade implements IRecipe<IInventory> {
|
||||
private final ResourceLocation id;
|
||||
private final ImmutableList<ItemStack> outputs;
|
||||
private final ImmutableList<Ingredient> inputs;
|
||||
@@ -86,10 +100,46 @@ public class RecipeElvenTrade {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nonnull IInventory inv, @Nonnull World world) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(@Nonnull IInventory inv) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeTypes.ELVEN_TRADE_SERIALIZER;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return ModRecipeTypes.ELVEN_TRADE_TYPE;
|
||||
}
|
||||
|
||||
public List<Ingredient> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
@@ -102,28 +152,57 @@ public class RecipeElvenTrade {
|
||||
return getOutputs();
|
||||
}
|
||||
|
||||
public void write(PacketBuffer buf) {
|
||||
buf.writeResourceLocation(id);
|
||||
buf.writeVarInt(inputs.size());
|
||||
for (Ingredient input : inputs) {
|
||||
input.write(buf);
|
||||
}
|
||||
buf.writeVarInt(outputs.size());
|
||||
for (ItemStack output : outputs) {
|
||||
buf.writeItemStack(output, false);
|
||||
}
|
||||
}
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeElvenTrade> {
|
||||
|
||||
public static RecipeElvenTrade read(PacketBuffer buf) {
|
||||
ResourceLocation id = buf.readResourceLocation();
|
||||
Ingredient[] inputs = new Ingredient[buf.readVarInt()];
|
||||
for (int i = 0; i < inputs.length; i++) {
|
||||
inputs[i] = Ingredient.read(buf);
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeElvenTrade read(@Nonnull ResourceLocation id, @Nonnull JsonObject json) {
|
||||
JsonElement output = json.get("output");
|
||||
List<ItemStack> outputStacks = new ArrayList<>();
|
||||
if (output.isJsonArray()) {
|
||||
for (JsonElement e : output.getAsJsonArray()) {
|
||||
JsonObject o = JSONUtils.getJsonObject(e, "output stack");
|
||||
outputStacks.add(CraftingHelper.getItemStack(o, true));
|
||||
}
|
||||
} else {
|
||||
JsonObject o = JSONUtils.getJsonObject(output, "output stack");
|
||||
outputStacks.add(CraftingHelper.getItemStack(o, true));
|
||||
}
|
||||
|
||||
List<Ingredient> inputs = new ArrayList<>();
|
||||
for (JsonElement e : JSONUtils.getJsonArray(json, "ingredients")) {
|
||||
Ingredient ing = Ingredient.deserialize(e);
|
||||
if (!ing.hasNoMatchingItems()) {
|
||||
inputs.add(ing);
|
||||
}
|
||||
}
|
||||
|
||||
return new RecipeElvenTrade(id, outputStacks.toArray(new ItemStack[0]), inputs.toArray(new Ingredient[0]));
|
||||
}
|
||||
ItemStack[] outputs = new ItemStack[buf.readVarInt()];
|
||||
for (int i = 0; i < outputs.length; i++) {
|
||||
outputs[i] = buf.readItemStack();
|
||||
|
||||
@Override
|
||||
public RecipeElvenTrade read(@Nonnull ResourceLocation id, PacketBuffer buf) {
|
||||
Ingredient[] inputs = new Ingredient[buf.readVarInt()];
|
||||
for (int i = 0; i < inputs.length; i++) {
|
||||
inputs[i] = Ingredient.read(buf);
|
||||
}
|
||||
ItemStack[] outputs = new ItemStack[buf.readVarInt()];
|
||||
for (int i = 0; i < outputs.length; i++) {
|
||||
outputs[i] = buf.readItemStack();
|
||||
}
|
||||
return new RecipeElvenTrade(id, outputs, inputs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buf, RecipeElvenTrade recipe) {
|
||||
buf.writeVarInt(recipe.getInputs().size());
|
||||
for (Ingredient input : recipe.getInputs()) {
|
||||
input.write(buf);
|
||||
}
|
||||
buf.writeVarInt(recipe.getOutputs().size());
|
||||
for (ItemStack output : recipe.getOutputs()) {
|
||||
buf.writeItemStack(output, false);
|
||||
}
|
||||
}
|
||||
return new RecipeElvenTrade(id, outputs, inputs);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import vazkii.botania.client.integration.jei.puredaisy.PureDaisyRecipeCategory;
|
||||
import vazkii.botania.client.integration.jei.runicaltar.RunicAltarRecipeCategory;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.ModSubtiles;
|
||||
import vazkii.botania.common.block.tile.TileAlfPortal;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.crafting.recipe.AncientWillRecipe;
|
||||
import vazkii.botania.common.crafting.recipe.CompositeLensRecipe;
|
||||
@@ -120,7 +121,7 @@ public class JEIBotaniaPlugin implements IModPlugin {
|
||||
registry.addRecipes(BotaniaAPI.brewRecipes.values(), BreweryRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.pureDaisyRecipes.values(), PureDaisyRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.petalRecipes.values(), PetalApothecaryRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.elvenTradeRecipes.values(), ElvenTradeRecipeCategory.UID);
|
||||
registry.addRecipes(TileAlfPortal.elvenTradeRecipes(Minecraft.getInstance().world.getRecipeManager()), ElvenTradeRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.runeAltarRecipes.values(), RunicAltarRecipeCategory.UID);
|
||||
registry.addRecipes(BotaniaAPI.manaInfusionRecipes.values(), ManaPoolRecipeCategory.UID);
|
||||
|
||||
|
||||
@@ -10,13 +10,16 @@ package vazkii.botania.client.patchouli.processor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.client.patchouli.PatchouliUtils;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.patchouli.api.IComponentProcessor;
|
||||
import vazkii.patchouli.api.IVariableProvider;
|
||||
import vazkii.patchouli.api.PatchouliAPI;
|
||||
@@ -32,9 +35,9 @@ public class ElvenTradeProcessor implements IComponentProcessor {
|
||||
public void setup(IVariableProvider<String> variables) {
|
||||
ImmutableList.Builder<RecipeElvenTrade> builder = ImmutableList.builder();
|
||||
for (String s : variables.get("recipes").split(";")) {
|
||||
RecipeElvenTrade recipeElvenTrade = BotaniaAPI.elvenTradeRecipes.get(new ResourceLocation(s));
|
||||
if (recipeElvenTrade != null) {
|
||||
builder.add(recipeElvenTrade);
|
||||
IRecipe<?> recipe = Minecraft.getInstance().world.getRecipeManager().getRecipes(ModRecipeTypes.ELVEN_TRADE_TYPE).get(new ResourceLocation(s));
|
||||
if (recipe instanceof RecipeElvenTrade) {
|
||||
builder.add((RecipeElvenTrade) recipe);
|
||||
}
|
||||
}
|
||||
recipes = builder.build();
|
||||
|
||||
@@ -14,6 +14,8 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.RecipeManager;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -33,11 +35,13 @@ import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.state.enums.AlfPortalState;
|
||||
import vazkii.botania.client.fx.WispParticleData;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.advancements.AlfPortalBreadTrigger;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.mana.BlockPool;
|
||||
import vazkii.botania.common.block.tile.mana.TilePool;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.botania.common.item.ItemLexicon;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
@@ -52,6 +56,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
|
||||
@@ -174,7 +179,7 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
|
||||
private boolean validateItemUsage(ItemEntity entity) {
|
||||
ItemStack inputStack = entity.getItem();
|
||||
for (RecipeElvenTrade recipe : BotaniaAPI.elvenTradeRecipes.values()) {
|
||||
for (RecipeElvenTrade recipe : elvenTradeRecipes(world.getRecipeManager())) {
|
||||
if (recipe.containsItem(inputStack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -269,9 +274,16 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<RecipeElvenTrade> elvenTradeRecipes(RecipeManager rm) {
|
||||
return rm.getRecipes(ModRecipeTypes.ELVEN_TRADE_TYPE).values().stream()
|
||||
.filter(r -> r instanceof RecipeElvenTrade)
|
||||
.map(r -> (RecipeElvenTrade) r)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void resolveRecipes() {
|
||||
List<BlockPos> pylons = locatePylons();
|
||||
for (RecipeElvenTrade recipe : BotaniaAPI.elvenTradeRecipes.values()) {
|
||||
for (RecipeElvenTrade recipe : elvenTradeRecipes(world.getRecipeManager())) {
|
||||
Optional<List<ItemStack>> match = recipe.match(stacksIn);
|
||||
if (match.isPresent()) {
|
||||
if (consumeMana(pylons, 500, false)) {
|
||||
|
||||
@@ -8,10 +8,14 @@
|
||||
*/
|
||||
package vazkii.botania.common.core.helper;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.Dynamic;
|
||||
import com.mojang.datafixers.types.JsonOps;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.NBTDynamicOps;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -146,6 +150,20 @@ public final class ItemNBTHelper {
|
||||
return verifyExistance(stack, tag) ? stack.getOrCreateTag().getList(tag, objtype) : nullifyOnFail ? null : new ListNBT();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the given stack such that {@link net.minecraftforge.common.crafting.CraftingHelper#getItemStack}
|
||||
* would be able to read the result back
|
||||
*/
|
||||
public static JsonObject serializeStack(ItemStack stack) {
|
||||
CompoundNBT nbt = stack.write(new CompoundNBT());
|
||||
nbt.put("count", nbt.get("Count"));
|
||||
nbt.remove("Count");
|
||||
nbt.put("item", nbt.get("id"));
|
||||
nbt.remove("id");
|
||||
Dynamic<INBT> dyn = new Dynamic<>(NBTDynamicOps.INSTANCE, nbt);
|
||||
return dyn.convert(JsonOps.INSTANCE).getValue().getAsJsonObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the `target` tag contains all of the tags and values present in the `template` tag. Recurses into
|
||||
* compound tags and matches all template keys and values; recurses into list tags and matches the template against
|
||||
|
||||
@@ -36,27 +36,6 @@ public class ModElvenTradeRecipes {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegisterRecipesEvent evt) {
|
||||
Ingredient livingwood = Ingredient.fromTag(ModTags.Items.LIVINGWOOD);
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("dreamwood"), new ItemStack(ModBlocks.dreamwood), livingwood));
|
||||
|
||||
Ingredient manaDiamond = Ingredient.fromTag(ModTags.Items.GEMS_MANA_DIAMOND);
|
||||
Ingredient manaSteel = Ingredient.fromTag(ModTags.Items.INGOTS_MANASTEEL);
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("elementium"), new ItemStack(ModItems.elementium), manaSteel, manaSteel));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("elementium_block"), new ItemStack(ModBlocks.elementiumBlock), Ingredient.fromItems(ModBlocks.manasteelBlock), Ingredient.fromItems(ModBlocks.manasteelBlock)));
|
||||
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("pixie_dust"), new ItemStack(ModItems.pixieDust), Ingredient.fromItems(ModItems.manaPearl)));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("dragonstone"), new ItemStack(ModItems.dragonstone), manaDiamond));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("dragonstone_block"), new ItemStack(ModBlocks.dragonstoneBlock), Ingredient.fromItems(ModBlocks.manaDiamondBlock)));
|
||||
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("elf_quartz"), new ItemStack(ModItems.elfQuartz), Ingredient.fromItems(Items.QUARTZ)));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("elf_glass"), new ItemStack(ModBlocks.elfGlass), Ingredient.fromItems(ModBlocks.manaGlass)));
|
||||
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("iron_return"), new ItemStack(Items.IRON_INGOT), Ingredient.fromItems(Items.IRON_INGOT)));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("iron_block_return"), new ItemStack(Blocks.IRON_BLOCK), Ingredient.fromItems(Blocks.IRON_BLOCK)));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("ender_pearl_return"), new ItemStack(Items.ENDER_PEARL), Ingredient.fromItems(Items.ENDER_PEARL)));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("diamond_return"), new ItemStack(Items.DIAMOND), Ingredient.fromItems(Items.DIAMOND)));
|
||||
evt.elvenTrade().accept(new RecipeElvenTrade(prefix("diamond_block_return"), new ItemStack(Blocks.DIAMOND_BLOCK), Ingredient.fromItems(Blocks.DIAMOND_BLOCK)));
|
||||
|
||||
ItemStack elvenLexicon = new ItemStack(ModItems.lexicon);
|
||||
elvenLexicon.getOrCreateTag().putBoolean(ItemLexicon.TAG_ELVEN_UNLOCK, true);
|
||||
evt.elvenTrade().accept(new RecipeLexicon(prefix("elven_lexicon"), elvenLexicon, Ingredient.fromStacks(new ItemStack(ModItems.lexicon))));
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.common.block.ModSubtiles;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class ModRecipeTypes {
|
||||
public static final IRecipeType<RecipeElvenTrade> ELVEN_TRADE_TYPE = new RecipeType<>();
|
||||
public static final IRecipeSerializer<RecipeElvenTrade> ELVEN_TRADE_SERIALIZER = new RecipeElvenTrade.Serializer();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<IRecipeSerializer<?>> evt) {
|
||||
ResourceLocation id = prefix("elven_trade");
|
||||
Registry.register(Registry.RECIPE_TYPE, id, ELVEN_TRADE_TYPE);
|
||||
evt.getRegistry().register(ELVEN_TRADE_SERIALIZER.setRegistryName(id));
|
||||
}
|
||||
|
||||
private static class RecipeType<T extends IRecipe<?>> implements IRecipeType<T> {
|
||||
@Override
|
||||
public String toString() {
|
||||
return Registry.RECIPE_TYPE.getKey(this).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipePureDaisy;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -48,10 +49,6 @@ public class PacketSyncRecipes {
|
||||
for (RecipeBrew recipe : brew.values()) {
|
||||
recipe.write(buf);
|
||||
}
|
||||
buf.writeVarInt(elven.size());
|
||||
for (RecipeElvenTrade recipe : elven.values()) {
|
||||
recipe.write(buf);
|
||||
}
|
||||
buf.writeVarInt(manaInfusion.size());
|
||||
for (RecipeManaInfusion recipe : manaInfusion.values()) {
|
||||
recipe.write(buf);
|
||||
@@ -75,10 +72,7 @@ public class PacketSyncRecipes {
|
||||
Map<ResourceLocation, RecipeBrew> brew = Stream.generate(() -> RecipeBrew.read(buf))
|
||||
.limit(brewCount)
|
||||
.collect(Collectors.toMap(RecipeBrew::getId, r -> r));
|
||||
int elvenCount = buf.readVarInt();
|
||||
Map<ResourceLocation, RecipeElvenTrade> elven = Stream.generate(() -> RecipeElvenTrade.read(buf))
|
||||
.limit(elvenCount)
|
||||
.collect(Collectors.toMap(RecipeElvenTrade::getId, r -> r));
|
||||
Map<ResourceLocation, RecipeElvenTrade> elven = Collections.emptyMap();
|
||||
int manaInfusionCount = buf.readVarInt();
|
||||
Map<ResourceLocation, RecipeManaInfusion> manaInfusion = Stream.generate(() -> RecipeManaInfusion.read(buf))
|
||||
.limit(manaInfusionCount)
|
||||
|
||||
@@ -28,6 +28,7 @@ public class DataGenerators {
|
||||
evt.getGenerator().addProvider(new FloatingFlowerModelProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new ItemModelProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new BlockstateProvider(evt.getGenerator(), evt.getExistingFileHelper()));
|
||||
evt.getGenerator().addProvider(new ElvenTradeProvider(evt.getGenerator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package vazkii.botania.data;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.data.RecipeProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.crafting.ModRecipeTypes;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.ModTags;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;
|
||||
|
||||
public class ElvenTradeProvider extends RecipeProvider {
|
||||
public ElvenTradeProvider(DataGenerator gen) {
|
||||
super(gen);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
Ingredient livingwood = Ingredient.fromTag(ModTags.Items.LIVINGWOOD);
|
||||
consumer.accept(new FinishedRecipe(id("dreamwood"), new ItemStack(ModBlocks.dreamwood), livingwood));
|
||||
|
||||
Ingredient manaDiamond = Ingredient.fromTag(ModTags.Items.GEMS_MANA_DIAMOND);
|
||||
Ingredient manaSteel = Ingredient.fromTag(ModTags.Items.INGOTS_MANASTEEL);
|
||||
consumer.accept(new FinishedRecipe(id("elementium"), new ItemStack(ModItems.elementium), manaSteel, manaSteel));
|
||||
consumer.accept(new FinishedRecipe(id("elementium_block"), new ItemStack(ModBlocks.elementiumBlock), Ingredient.fromItems(ModBlocks.manasteelBlock), Ingredient.fromItems(ModBlocks.manasteelBlock)));
|
||||
|
||||
consumer.accept(new FinishedRecipe(id("pixie_dust"), new ItemStack(ModItems.pixieDust), Ingredient.fromItems(ModItems.manaPearl)));
|
||||
consumer.accept(new FinishedRecipe(id("dragonstone"), new ItemStack(ModItems.dragonstone), manaDiamond));
|
||||
consumer.accept(new FinishedRecipe(id("dragonstone_block"), new ItemStack(ModBlocks.dragonstoneBlock), Ingredient.fromItems(ModBlocks.manaDiamondBlock)));
|
||||
|
||||
consumer.accept(new FinishedRecipe(id("elf_quartz"), new ItemStack(ModItems.elfQuartz), Ingredient.fromItems(Items.QUARTZ)));
|
||||
consumer.accept(new FinishedRecipe(id("elf_glass"), new ItemStack(ModBlocks.elfGlass), Ingredient.fromItems(ModBlocks.manaGlass)));
|
||||
|
||||
consumer.accept(new FinishedRecipe(id("iron_return"), new ItemStack(Items.IRON_INGOT), Ingredient.fromItems(Items.IRON_INGOT)));
|
||||
consumer.accept(new FinishedRecipe(id("iron_block_return"), new ItemStack(Blocks.IRON_BLOCK), Ingredient.fromItems(Blocks.IRON_BLOCK)));
|
||||
consumer.accept(new FinishedRecipe(id("ender_pearl_return"), new ItemStack(Items.ENDER_PEARL), Ingredient.fromItems(Items.ENDER_PEARL)));
|
||||
consumer.accept(new FinishedRecipe(id("diamond_return"), new ItemStack(Items.DIAMOND), Ingredient.fromItems(Items.DIAMOND)));
|
||||
consumer.accept(new FinishedRecipe(id("diamond_block_return"), new ItemStack(Blocks.DIAMOND_BLOCK), Ingredient.fromItems(Blocks.DIAMOND_BLOCK)));
|
||||
}
|
||||
|
||||
private static ResourceLocation id(String path) {
|
||||
return prefix("elven_trade/" + path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Botania elven trade recipes";
|
||||
}
|
||||
|
||||
private static class FinishedRecipe implements IFinishedRecipe {
|
||||
private final ResourceLocation id;
|
||||
private final List<Ingredient> inputs;
|
||||
private final List<ItemStack> outputs;
|
||||
|
||||
public FinishedRecipe(ResourceLocation id, ItemStack output, Ingredient... inputs) {
|
||||
this(id, Arrays.asList(inputs), Collections.singletonList(output));
|
||||
}
|
||||
private FinishedRecipe(ResourceLocation id, List<Ingredient> inputs, List<ItemStack> outputs) {
|
||||
this.id = id;
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonObject json) {
|
||||
JsonArray in = new JsonArray();
|
||||
for (Ingredient ingr : inputs) {
|
||||
in.add(ingr.serialize());
|
||||
}
|
||||
|
||||
JsonArray out = new JsonArray();
|
||||
for (ItemStack s : outputs) {
|
||||
out.add(ItemNBTHelper.serializeStack(s));
|
||||
}
|
||||
|
||||
json.add("ingredients", in);
|
||||
json.add("output", out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override public IRecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeTypes.ELVEN_TRADE_SERIALIZER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override public JsonObject getAdvancementJson() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override public ResourceLocation getAdvancementID() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user