mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-25 00:18:34 +01:00
Compare commits
No commits in common. "26343b77c16f22f2f9fd8d98184b5246a4864569" and "0b61cc082da7a4ad3fcb1ccccd0d5b2510889777" have entirely different histories.
26343b77c1
...
0b61cc082d
10 changed files with 56 additions and 492 deletions
|
@ -29,8 +29,6 @@ public class ActuallyAdditionsData {
|
|||
generator.addProvider(new ItemRecipeGenerator(generator));
|
||||
generator.addProvider(generatorBlockTags);
|
||||
generator.addProvider(new ItemTagsGenerator(generator, generatorBlockTags, helper));
|
||||
|
||||
generator.addProvider(new LaserRecipeGenerator(generator));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,6 +185,7 @@ public class BlockRecipeGenerator extends RecipeProvider {
|
|||
@Override
|
||||
protected void saveAdvancement(DirectoryCache p_208310_1_, JsonObject p_208310_2_, Path p_208310_3_) {
|
||||
//Nope... maybe later...
|
||||
|
||||
}
|
||||
|
||||
public static class Recipe {
|
||||
|
|
|
@ -2,9 +2,6 @@ package de.ellpeck.actuallyadditions.data;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.TargetNBTIngredient;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.WrappedRecipe;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheFoods;
|
||||
import net.minecraft.data.*;
|
||||
|
@ -334,56 +331,16 @@ public class ItemRecipeGenerator extends RecipeProvider {
|
|||
.define('C', ActuallyItems.COIL.get())
|
||||
.define('G', Items.GOLD_NUGGET).save(consumer);
|
||||
|
||||
//Battery
|
||||
Recipe.shaped(ActuallyItems.BATTERY.get())
|
||||
.pattern(" R ")
|
||||
.pattern("ICI")
|
||||
.pattern("III")
|
||||
.define('R', ActuallyItems.RESTONIA_CRYSTAL.get())
|
||||
.define('I', ActuallyItems.ENORI_CRYSTAL.get())
|
||||
.define('C', ActuallyItems.COIL_ADVANCED.get())
|
||||
.save(consumer);
|
||||
|
||||
//Double Battery
|
||||
Recipe.shaped(ActuallyItems.BATTERY_DOUBLE.get())
|
||||
.pattern(" R ")
|
||||
.pattern("ICI")
|
||||
.pattern("III")
|
||||
.define('R', TargetNBTIngredient.of(ActuallyItems.BATTERY.get()))
|
||||
.define('I', ActuallyItems.ENORI_CRYSTAL.get())
|
||||
.define('C', ActuallyItems.COIL_ADVANCED.get())
|
||||
.save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get()));
|
||||
|
||||
//Triple Battery
|
||||
Recipe.shaped(ActuallyItems.BATTERY_TRIPLE.get())
|
||||
.pattern(" R ")
|
||||
.pattern("ICI")
|
||||
.pattern("III")
|
||||
.define('R', TargetNBTIngredient.of(ActuallyItems.BATTERY_DOUBLE.get()))
|
||||
.define('I', ActuallyItems.ENORI_EMPOWERED_CRYSTAL.get())
|
||||
.define('C', ActuallyItems.COIL_ADVANCED.get())
|
||||
.save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get()));
|
||||
|
||||
//Quad Battery
|
||||
Recipe.shaped(ActuallyItems.BATTERY_QUADRUPLE.get())
|
||||
.pattern(" R ")
|
||||
.pattern("ICI")
|
||||
.pattern("III")
|
||||
.define('R', TargetNBTIngredient.of(ActuallyItems.BATTERY_TRIPLE.get()))
|
||||
.define('I', ActuallyItems.ENORI_EMPOWERED_CRYSTAL.get())
|
||||
.define('C', ActuallyItems.COIL_ADVANCED.get())
|
||||
.save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get()));
|
||||
|
||||
//Quintuple Battery
|
||||
Recipe.shaped(ActuallyItems.BATTERY_QUINTUPLE.get())
|
||||
.pattern(" R ")
|
||||
.pattern("ICI")
|
||||
.pattern("III")
|
||||
.define('R', TargetNBTIngredient.of(ActuallyItems.BATTERY_QUADRUPLE.get()))
|
||||
.define('I', ActuallyItems.DIAMATINE_EMPOWERED_CRYSTAL.get())
|
||||
.define('C', ActuallyItems.COIL_ADVANCED.get())
|
||||
.save(WrappedRecipe.Inject(consumer, ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get()));
|
||||
|
||||
// //Battery
|
||||
// RecipeHandler.addOreDictRecipe(new ItemStack(InitItems.itemBattery), " R ", "ICI", "III", 'R', new ItemStack(InitItems.itemCrystal, 1, TheCrystals.REDSTONE.ordinal()), 'I', new ItemStack(InitItems.itemCrystal, 1, TheCrystals.IRON.ordinal()), 'C', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.COIL_ADVANCED.ordinal()));
|
||||
// recipeBattery = RecipeUtil.lastIRecipe();
|
||||
//
|
||||
// //Double Battery
|
||||
// new RecipeKeepDataShaped(new ResourceLocation(ActuallyAdditions.MODID, "double_battery"), new ItemStack(InitItems.itemBatteryDouble), new ItemStack(InitItems.itemBattery), " R ", "ICI", "III", 'R', new ItemStack(InitItems.itemBattery), 'I', new ItemStack(InitItems.itemCrystal, 1, TheCrystals.IRON.ordinal()), 'C', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.COIL_ADVANCED.ordinal()));
|
||||
// recipeBatteryDouble = RecipeUtil.lastIRecipe();
|
||||
//
|
||||
// //Magnet Ring
|
||||
// RecipeHandler.addOreDictRecipe(new ItemStack(InitItems.itemMagnetRing), "RIB", "IOI", "BIR", 'R', new ItemStack(InitItems.itemCrystal, 1, TheCrystals.REDSTONE.ordinal()), 'I', new ItemStack(InitItems.itemCrystal, 1, TheCrystals.IRON.ordinal()), 'B', new ItemStack(Items.DYE, 1, 4), 'O', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.RING.ordinal()));
|
||||
|
@ -397,6 +354,17 @@ public class ItemRecipeGenerator extends RecipeProvider {
|
|||
// RecipeHandler.addOreDictRecipe(new ItemStack(InitItems.itemWaterRemovalRing), "BIB", "IOI", "BIB", 'B', new ItemStack(Items.WATER_BUCKET), 'I', new ItemStack(InitItems.itemCrystalEmpowered, 1, TheCrystals.DIAMOND.ordinal()), 'O', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.RING.ordinal()));
|
||||
// recipeWaterRing = RecipeUtil.lastIRecipe();
|
||||
//
|
||||
// //Triple Battery
|
||||
// new RecipeKeepDataShaped(new ResourceLocation(ActuallyAdditions.MODID, "triple_battery"), new ItemStack(InitItems.itemBatteryTriple), new ItemStack(InitItems.itemBatteryDouble), " R ", "ICI", "III", 'R', new ItemStack(InitItems.itemBatteryDouble), 'I', new ItemStack(InitItems.itemCrystalEmpowered, 1, TheCrystals.IRON.ordinal()), 'C', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.COIL_ADVANCED.ordinal()));
|
||||
// recipeBatteryTriple = RecipeUtil.lastIRecipe();
|
||||
//
|
||||
// //Quadruple Battery
|
||||
// new RecipeKeepDataShaped(new ResourceLocation(ActuallyAdditions.MODID, "quadruple_battery"), new ItemStack(InitItems.itemBatteryQuadruple), new ItemStack(InitItems.itemBatteryTriple), " R ", "ICI", "III", 'R', new ItemStack(InitItems.itemBatteryTriple), 'I', new ItemStack(InitItems.itemCrystalEmpowered, 1, TheCrystals.IRON.ordinal()), 'C', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.COIL_ADVANCED.ordinal()));
|
||||
// recipeBatteryQuadruple = RecipeUtil.lastIRecipe();
|
||||
//
|
||||
// //Quintuple Battery
|
||||
// new RecipeKeepDataShaped(new ResourceLocation(ActuallyAdditions.MODID, "quintuple_battery"), new ItemStack(InitItems.itemBatteryQuintuple), new ItemStack(InitItems.itemBatteryQuadruple), " R ", "ICI", "III", 'R', new ItemStack(InitItems.itemBatteryQuadruple), 'I', new ItemStack(InitItems.itemCrystalEmpowered, 1, TheCrystals.DIAMOND.ordinal()), 'C', new ItemStack(InitItems.itemMisc, 1, TheMiscItems.COIL_ADVANCED.ordinal()));
|
||||
// recipeBatteryQuintuple = RecipeUtil.lastIRecipe();
|
||||
//
|
||||
// //Cup
|
||||
// RecipeHandler.addOreDictRecipe(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CUP.ordinal()), "S S", "SCS", "SSS", 'S', "stone", 'C', "cropCoffee");
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package de.ellpeck.actuallyadditions.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.data.RecipeProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LaserRecipeGenerator extends RecipeProvider {
|
||||
public LaserRecipeGenerator(DataGenerator p_i48262_1_) {
|
||||
super(p_i48262_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(DirectoryCache pCache, JsonObject pAdvancementJson, Path pPath) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
|
||||
|
||||
consumer.accept(new LaserRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "laser_restonia_block"),
|
||||
Ingredient.of(Tags.Items.STORAGE_BLOCKS_REDSTONE), 400, new ItemStack(ActuallyBlocks.RESTONIA_CRYSTAL.getItem())));
|
||||
}
|
||||
}
|
|
@ -13,9 +13,7 @@ package de.ellpeck.actuallyadditions.mod;
|
|||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.InitBooklet;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.TargetNBTIngredient;
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.entity.InitEntities;
|
||||
import de.ellpeck.actuallyadditions.mod.event.CommonEvents;
|
||||
|
@ -37,7 +35,6 @@ import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
|
|||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
@ -84,7 +81,6 @@ public class ActuallyAdditions {
|
|||
|
||||
ActuallyBlocks.BLOCKS.register(eventBus);
|
||||
ActuallyBlocks.TILES.register(eventBus);
|
||||
ActuallyRecipes.init(eventBus);
|
||||
ActuallyContainers.CONTAINERS.register(eventBus);
|
||||
|
||||
MinecraftForge.EVENT_BUS.addListener(this::serverStarted);
|
||||
|
@ -103,7 +99,6 @@ public class ActuallyAdditions {
|
|||
ActuallyAdditionsAPI.connectionHandler = new LaserRelayConnectionHandler();
|
||||
Lenses.init();
|
||||
// CompatUtil.registerCraftingTweaks();
|
||||
event.enqueueWork(() -> CraftingHelper.register(TargetNBTIngredient.Serializer.NAME, TargetNBTIngredient.SERIALIZER));
|
||||
|
||||
commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities");
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class ActuallyRecipes {
|
||||
public static final DeferredRegister<IRecipeSerializer<?>> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ActuallyAdditions.MODID);
|
||||
|
||||
public static void init(IEventBus bus) {
|
||||
SERIALIZERS.register(bus);
|
||||
}
|
||||
|
||||
public static final RegistryObject<IRecipeSerializer<?>> KEEP_DATA_SHAPED_RECIPE = SERIALIZERS.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new);
|
||||
public static final RegistryObject<IRecipeSerializer<?>> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new);
|
||||
|
||||
|
||||
|
||||
public static class Types {
|
||||
public static final IRecipeType<LaserRecipe> LASER = IRecipeType.register(ActuallyAdditions.MODID + ":laser");
|
||||
public static final IRecipeType<LaserRecipe> EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower");
|
||||
public static final IRecipeType<LaserRecipe> CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crush");
|
||||
public static final IRecipeType<LaserRecipe> COALGEN = IRecipeType.register(ActuallyAdditions.MODID + ":coal_power");
|
||||
public static final IRecipeType<LaserRecipe> OILGEN = IRecipeType.register(ActuallyAdditions.MODID + ":oil_power");
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.*;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class LaserRecipe implements IRecipe<IInventory> {
|
||||
public static String NAME = "laser";
|
||||
private ItemStack result;
|
||||
private Ingredient itemIngredient;
|
||||
private int energy;
|
||||
private ResourceLocation id;
|
||||
|
||||
public LaserRecipe(ResourceLocation id, ItemStack result, Ingredient itemIngredient, int energy) {
|
||||
this.result = result;
|
||||
this.itemIngredient = itemIngredient;
|
||||
this.energy = energy;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack itemStack, int energyIn) {
|
||||
|
||||
return itemIngredient.test(itemStack) && (energyIn >= energy);
|
||||
}
|
||||
|
||||
//nah
|
||||
@Override
|
||||
public boolean matches(IInventory pInv, World pLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(IInventory pInv) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ActuallyRecipes.LASER_RECIPE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return ActuallyRecipes.Types.LASER;
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<LaserRecipe> {
|
||||
|
||||
@Override
|
||||
public LaserRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
|
||||
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
|
||||
int energy = JSONUtils.getAsInt(pJson, "energy");
|
||||
ItemStack result = new ItemStack(JSONUtils.getAsItem(pJson, "result"));
|
||||
|
||||
return new LaserRecipe(pRecipeId, result, ingredient, energy);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public LaserRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) {
|
||||
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
|
||||
int energy = pBuffer.readInt();
|
||||
ItemStack result = pBuffer.readItem();
|
||||
return new LaserRecipe(pRecipeId, result, ingredient, energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(PacketBuffer pBuffer, LaserRecipe pRecipe) {
|
||||
pRecipe.itemIngredient.toNetwork(pBuffer);
|
||||
pBuffer.writeInt(pRecipe.energy);
|
||||
pBuffer.writeItem(pRecipe.result);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FinishedRecipe implements IFinishedRecipe {
|
||||
private ResourceLocation id;
|
||||
private Ingredient itemIngredient;
|
||||
private int energy;
|
||||
private ItemStack output;
|
||||
|
||||
public FinishedRecipe(ResourceLocation id, Ingredient itemIngredient, int energy, ItemStack output) {
|
||||
this.id = id;
|
||||
this.itemIngredient = itemIngredient;
|
||||
this.energy = energy;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeRecipeData(JsonObject pJson) {
|
||||
pJson.add("input", itemIngredient.toJson());
|
||||
pJson.addProperty("energy", energy);
|
||||
pJson.addProperty("output", Registry.ITEM.getKey(output.getItem()).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getType() {
|
||||
return ActuallyRecipes.LASER_RECIPE.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject serializeAdvancement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementId() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,92 +1,41 @@
|
|||
/*
|
||||
* This file ("RecipeKeepDataShaped.java") is part of the Actually Additions mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://ellpeck.de/actaddlicense
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015-2017 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
// TODO: [port] MOVE TO DATA_GENERATOR
|
||||
@Deprecated
|
||||
public class RecipeKeepDataShaped { //extends ShapedOreRecipe {
|
||||
//
|
||||
// private final ItemStack nbtCopyStack;
|
||||
//
|
||||
// public RecipeKeepDataShaped(ResourceLocation group, ItemStack result, ItemStack nbtCopyStack, Object... recipe) {
|
||||
// super(group, result, recipe);
|
||||
// this.nbtCopyStack = nbtCopyStack;
|
||||
//
|
||||
// RecipeHelper.addRecipe(group.getPath(), this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
// ItemStack stack = super.getCraftingResult(inventory);
|
||||
// if (StackUtil.isValid(stack)) {
|
||||
// for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
// ItemStack input = inventory.getStackInSlot(i);
|
||||
// if (ItemUtil.areItemsEqual(this.nbtCopyStack, input, true)) {
|
||||
// stack.setTagCompound(input.getTagCompound());
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return stack;
|
||||
// }
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RecipeKeepDataShaped extends ShapedRecipe {
|
||||
public static String NAME = "copy_nbt";
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public RecipeKeepDataShaped(ResourceLocation idIn, String groupIn, int recipeWidthIn, int recipeHeightIn, NonNullList<Ingredient> recipeItemsIn, ItemStack recipeOutputIn) {
|
||||
super(idIn, groupIn, recipeWidthIn, recipeHeightIn, recipeItemsIn, recipeOutputIn);
|
||||
}
|
||||
|
||||
public RecipeKeepDataShaped(ShapedRecipe shapedRecipe) {
|
||||
super(shapedRecipe.getId(), shapedRecipe.getGroup(), shapedRecipe.getRecipeWidth(), shapedRecipe.getRecipeHeight(), shapedRecipe.getIngredients(), shapedRecipe.getResultItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(CraftingInventory inv) {
|
||||
final ItemStack craftingResult = super.assemble(inv);
|
||||
TargetNBTIngredient donorIngredient = null;
|
||||
ItemStack datasource = ItemStack.EMPTY;
|
||||
NonNullList<Ingredient> ingredients = getIngredients();
|
||||
for (Ingredient ingredient : ingredients) {
|
||||
if (ingredient instanceof TargetNBTIngredient) {
|
||||
donorIngredient = (TargetNBTIngredient) ingredient;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (donorIngredient != null && !inv.isEmpty()) {
|
||||
for (int i = 0; i < inv.getContainerSize(); i++) {
|
||||
final ItemStack item = inv.getItem(i);
|
||||
if (!item.isEmpty() && donorIngredient.test(item)) {
|
||||
datasource = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!datasource.isEmpty() && datasource.hasTag())
|
||||
craftingResult.setTag(datasource.getTag().copy());
|
||||
|
||||
return craftingResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get();
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeKeepDataShaped> {
|
||||
@Nullable
|
||||
@Override
|
||||
public RecipeKeepDataShaped fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) {
|
||||
return new RecipeKeepDataShaped(IRecipeSerializer.SHAPED_RECIPE.fromNetwork(recipeId, buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeKeepDataShaped fromJson(ResourceLocation recipeId, JsonObject json) {
|
||||
try {
|
||||
return new RecipeKeepDataShaped(IRecipeSerializer.SHAPED_RECIPE.fromJson(recipeId, json));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
LOGGER.info("Error reading "+ NAME +" Recipe from packet: ", exception);
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(PacketBuffer buffer, RecipeKeepDataShaped recipe) {
|
||||
try {
|
||||
IRecipeSerializer.SHAPED_RECIPE.toNetwork(buffer, recipe);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
LOGGER.info("Error writing "+ NAME +" Recipe to packet: ", exception);
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.IIngredientSerializer;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TargetNBTIngredient extends Ingredient {
|
||||
public TargetNBTIngredient(Stream<? extends IItemList> itemLists) {
|
||||
super(itemLists);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredientSerializer<? extends Ingredient> getSerializer() {
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
public static TargetNBTIngredient of(IItemProvider itemProvider) {
|
||||
return new TargetNBTIngredient(Stream.of(new SingleItemList(new ItemStack(itemProvider))));
|
||||
}
|
||||
public static TargetNBTIngredient of(ItemStack itemStack) {
|
||||
return new TargetNBTIngredient(Stream.of(new SingleItemList(itemStack)));
|
||||
}
|
||||
public static TargetNBTIngredient of(ITag tag) {
|
||||
return new TargetNBTIngredient(Stream.of(new TagList(tag)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public JsonElement toJson() {
|
||||
JsonObject tmp = super.toJson().getAsJsonObject();
|
||||
tmp.addProperty("type", Serializer.NAME.toString());
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
public static Serializer SERIALIZER = new Serializer();
|
||||
public static class Serializer implements IIngredientSerializer<TargetNBTIngredient> {
|
||||
public static ResourceLocation NAME = new ResourceLocation(ActuallyAdditions.MODID, "nbt_target");
|
||||
|
||||
@Override
|
||||
public TargetNBTIngredient parse(PacketBuffer buffer) {
|
||||
return new TargetNBTIngredient(Stream.generate(() -> new SingleItemList(buffer.readItem())).limit(buffer.readVarInt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetNBTIngredient parse(JsonObject json) {
|
||||
return new TargetNBTIngredient(Stream.of(Ingredient.valueFromJson(json)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer, TargetNBTIngredient ingredient) {
|
||||
ItemStack[] items = ingredient.getItems();
|
||||
buffer.writeVarInt(items.length);
|
||||
|
||||
for (ItemStack stack : items)
|
||||
buffer.writeItem(stack);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class WrappedRecipe implements IFinishedRecipe {
|
||||
IFinishedRecipe inner;
|
||||
IRecipeSerializer<?> serializerOverride;
|
||||
|
||||
public WrappedRecipe(IFinishedRecipe innerIn) {
|
||||
inner = innerIn;
|
||||
}
|
||||
|
||||
public WrappedRecipe(IFinishedRecipe innerIn, IRecipeSerializer<?> serializerOverrideIn) {
|
||||
inner = innerIn;
|
||||
serializerOverride = serializerOverrideIn;
|
||||
}
|
||||
|
||||
public static Consumer<IFinishedRecipe> Inject(Consumer<IFinishedRecipe> consumer, IRecipeSerializer<?> serializer) {
|
||||
return iFinishedRecipe -> consumer.accept(new WrappedRecipe(iFinishedRecipe, serializer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeRecipeData(JsonObject json) {
|
||||
inner.serializeRecipeData(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject serializeRecipe() {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
if (serializerOverride != null)
|
||||
jsonObject.addProperty("type", serializerOverride.getRegistryName().toString());
|
||||
else
|
||||
jsonObject.addProperty("type", inner.getType().getRegistryName().toString());
|
||||
serializeRecipeData(jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return inner.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getType () {
|
||||
return serializerOverride != null? serializerOverride:inner.getType();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject serializeAdvancement() {
|
||||
return inner.serializeAdvancement();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementId() {
|
||||
return inner.getAdvancementId();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue