fix bug and add avaritiaddons support

This commit is contained in:
vfyjxf committed 2021-08-24 12:51:04 +08:00
1 parent d6c7499c2b
commit 3980fa2350
10 files changed
+634 -101

No files matched your search

@@ -1,30 +1,34 @@
package com.github.vfyjxf.nee;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Configuration;
import java.io.File;
/**
* @author vfyjxf
*/
@Config(modid = "neenergistics", name = "NotEnoughEnergistics", category = "transfer")
public class NEEConfig {
@Comment("Automatic switch Pattern Terminal's Mode when click [+].Default:true")
public static boolean allowAutomaticSwitchPatternTerminalMode = true;
@Comment("If true, print current recipe type in log.Default:false")
public static boolean allowPrintRecipeType = false;
public static String[] transformBlacklist = new String[0];
public static String[] transformPriorityList = new String[0];
public static String[] transformPriorityModList = new String[0];
@Comment("If oredict has this mod's item, use it first.")
public static String[] modPriorityList = new String[0];
public static void loadConfig(File configFile) {
Configuration config = new Configuration(configFile);
config.load();
@Comment("If item in the blacklist, it will not be transferred.\n" +
"example:{\"itemName\":\"gregtech:meta_item_2\",\"meta\":\"32492\"}")
public static String[] itemBlacklist = new String[0];
transformBlacklist = config.get("client", "transformItemBlacklist", new String[0],
"If item in the blacklist, it will not be transferred.\n" +
"the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n"+
"example: \"{\"modid\":\"minecraft\",\"name\":\"iron_ingot\",\"recipeProcessor\":\"EnderIO\",\"identifier\":\"EnderIOAlloySmelter\"}\"").getStringList();
transformPriorityList = config.get("client", "transformItemPriorityList", new String[0],
"If item in tne priority list, it will be transferred first.").getStringList();
@Comment("If item in tne priority list, it will be transferred first.\n" +
"example:{\"itemName\":\"gregtech:meta_item_2\",\"meta\":\"32492\"}")
public static String[] itemPriorityList = new String[0];
transformPriorityModList = config.get("client","transformPriorityModList",new String[0],
"if oredict has this mod's item, use it first").getStringList();
if (config.hasChanged()) config.save();
}
}
@@ -0,0 +1,100 @@
package com.github.vfyjxf.nee;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.client.gui.implementations.GuiPatternTermEx;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
import com.github.vfyjxf.nee.processor.RecipeProcessor;
import cpw.mods.fml.common.Loader;
import thaumicenergistics.client.gui.GuiKnowledgeInscriber;
import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter;
import java.util.*;
public class NEINeeConfig implements IConfigureNEI {
@Override
public void loadConfig() {
RecipeProcessor.init();
Set<String> defaultIdentifiers = new HashSet<>(
Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null)
);
Set<String> identifiers = new HashSet<>(defaultIdentifiers);
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
identifiers.addAll(processor.getAllOverlayIdentifier());
}
for (String ident : identifiers) {
API.registerGuiOverlay(GuiPatternTerm.class, ident);
API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident);
}
installPatternTerminalExSupport(identifiers);
installThaumicEnergisticsSupport();
installAvaritiaddonsSupport();
}
@Override
public String getName() {
return NotEnoughEnergistics.NAME;
}
@Override
public String getVersion() {
return NotEnoughEnergistics.VERSION;
}
private void installThaumicEnergisticsSupport() {
try {
Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
} catch (ClassNotFoundException e) {
return;
}
if (Loader.isModLoaded("thaumcraftneiplugin")) {
NotEnoughEnergistics.logger.info("Install ThaumicEnergistics support");
API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapedrecipes");
API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapelessrecipes");
API.registerGuiOverlayHandler(GuiKnowledgeInscriber.class, new NEECraftingHandler(), "arcaneshapedrecipes");
API.registerGuiOverlayHandler(GuiKnowledgeInscriber.class, new NEECraftingHandler(), "arcaneshapelessrecipes");
}
}
private void installPatternTerminalExSupport(Set<String> identifiers) {
try {
Class.forName("appeng.client.gui.implementations.GuiPatternTermEx");
} catch (ClassNotFoundException e) {
return;
}
identifiers.remove("crafting");
identifiers.remove("crafting2x2");
//PatternTermEx Support
for (String ident : identifiers) {
API.registerGuiOverlay(GuiPatternTermEx.class, ident);
API.registerGuiOverlayHandler(GuiPatternTermEx.class, new NEECraftingHandler(), ident);
}
}
private void installAvaritiaddonsSupport() {
try {
Class.forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter");
} catch (ClassNotFoundException e) {
return;
}
if (Loader.isModLoaded("avaritiaddons")) {
NotEnoughEnergistics.logger.info("Install Avaritiaddons support");
API.registerGuiOverlay(GuiExtremeAutoCrafter.class, "extreme");
API.registerGuiOverlayHandler(GuiExtremeAutoCrafter.class, new NEECraftingHandler(), "extreme");
}
}
}
@@ -0,0 +1,261 @@
package com.github.vfyjxf.nee.nei;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.client.gui.implementations.GuiPatternTermEx;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import appeng.util.Platform;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
import com.github.vfyjxf.nee.processor.RecipeProcessor;
import com.github.vfyjxf.nee.utils.ItemUtils;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.ArrayList;
import java.util.List;
/**
* @author vfyjxf
*/
public class NEECraftingHandler implements IOverlayHandler {
public static final String OUTPUT_KEY = "Outputs";
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
if (firstGui instanceof GuiPatternTerm || (hasPatternTermExClz() && firstGui instanceof GuiPatternTermEx)) {
NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex));
} else {
knowledgeInscriberHandler(firstGui, recipe, recipeIndex);
extremeAutoCrafterHandler(firstGui, recipe, recipeIndex);
}
}
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) {
if (isCraftingTableRecipe(recipe)) {
return packCraftingTableRecipe(recipe, recipeIndex);
} else {
return packProcessRecipe(recipe, recipeIndex);
}
}
private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex) {
final NBTTagCompound recipeInputs = new NBTTagCompound();
NBTTagCompound recipeOutputs = new NBTTagCompound();
String identifier = ((TemplateRecipeHandler) recipe).getOverlayIdentifier();
int inputIndex = 0;
int outputIndex = 0;
//get all recipe inputs and other stacks,use first item
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
List<PositionedStack> inputs = processor.getRecipeInput(recipe, recipeIndex, identifier);
List<PositionedStack> outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier);
String recipeProcessorId = processor.getRecipeProcessorId();
List<PositionedStack> tInputs = new ArrayList<>();
if (inputs != null && outputs != null) {
for (PositionedStack positionedStack : inputs) {
ItemStack currentStack = positionedStack.items[0];
boolean find = false;
for (PositionedStack storedStack : tInputs) {
ItemStack StoredStack = storedStack.items[0];
if (StoredStack.isItemEqual(currentStack) && (StoredStack.stackSize + currentStack.stackSize) <= StoredStack.getMaxStackSize()) {
find = true;
storedStack.items[0].stackSize = StoredStack.stackSize + currentStack.stackSize;
}
}
if (!find) {
tInputs.add(positionedStack);
}
}
for (PositionedStack positionedStack : tInputs) {
ItemStack currentStack = positionedStack.items[0];
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
if (preferModItem != null) {
currentStack = preferModItem;
currentStack.stackSize = positionedStack.items[0].stackSize;
}
for (ItemStack stack : positionedStack.items) {
if (Platform.isRecipePrioritized(stack) || ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
currentStack = stack.copy();
currentStack.stackSize = positionedStack.items[0].stackSize;
break;
}
}
if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) {
continue;
}
recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
inputIndex++;
}
for (PositionedStack positionedStack : outputs) {
if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) {
continue;
}
recipeOutputs.setTag(OUTPUT_KEY + outputIndex, positionedStack.item.writeToNBT(new NBTTagCompound()));
outputIndex++;
}
}
}
return new PacketNEIPatternRecipe(recipeInputs, recipeOutputs);
}
private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, int recipeIndex) {
final NBTTagCompound recipeInputs = new NBTTagCompound();
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
for (final PositionedStack positionedStack : ingredients) {
final int col = (positionedStack.relx - 25) / 18;
final int row = (positionedStack.rely - 6) / 18;
int slotIndex = col + row * 3;
if (positionedStack.items != null && positionedStack.items.length > 0) {
final ItemStack[] currentStackList = positionedStack.items;
ItemStack stack = positionedStack.items[0];
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
if (preferModItem != null) {
stack = preferModItem;
}
for (ItemStack currentStack : currentStackList) {
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
stack = currentStack.copy();
}
}
recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound()));
}
}
return new PacketNEIPatternRecipe(recipeInputs, null);
}
private void knowledgeInscriberHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
Class<?> knowledgeInscriberClz;
try {
knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
} catch (ClassNotFoundException e) {
return;
}
if (knowledgeInscriberClz.isInstance(firstGui)) {
NEENetworkHandler.getInstance().sendToServer(packetArcaneRecipe(recipe, recipeIndex));
}
}
private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeIndex) {
final Class<?> itemAspectClz;
Class<?> iA = null;
try {
iA = Class.forName("com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
itemAspectClz = iA;
final NBTTagCompound recipeInputs = new NBTTagCompound();
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
if (itemAspectClz != null) {
ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem()));
}
for (PositionedStack positionedStack : ingredients) {
if (positionedStack.items != null && positionedStack.items.length > 0) {
int slotIndex = getSlotIndex(positionedStack.relx * 100 + positionedStack.rely);
final ItemStack[] currentStackList = positionedStack.items;
ItemStack stack = positionedStack.item;
for (ItemStack currentStack : currentStackList) {
if (Platform.isRecipePrioritized(currentStack)) {
stack = currentStack.copy();
}
}
recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound()));
}
}
return new PacketArcaneRecipe(recipeInputs);
}
private void extremeAutoCrafterHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
final Class<?> guiExtremeAutoCrafterClz;
try {
guiExtremeAutoCrafterClz = Class.forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter");
} catch (ClassNotFoundException e) {
return;
}
if (guiExtremeAutoCrafterClz.isInstance(firstGui)) {
NEENetworkHandler.getInstance().sendToServer(packetExtremeRecipe(recipe, recipeIndex));
}
}
private PacketExtremeRecipe packetExtremeRecipe(IRecipeHandler recipe, int recipeIndex) {
NBTTagCompound recipeInputs = new NBTTagCompound();
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
for (PositionedStack positionedStack : ingredients) {
int col = (positionedStack.relx - 3) / 18;
int row = (positionedStack.rely - 3) / 18;
if (positionedStack.rely == 129) {
col = (positionedStack.relx - 2) / 18;
}
int slotIndex = col + row * 9;
ItemStack currentStack = positionedStack.items[0];
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
if (preferModItem != null) {
currentStack = preferModItem;
}
for (ItemStack stack : positionedStack.items) {
if (ItemUtils.isPreferItems(stack)) {
currentStack = stack.copy();
}
}
recipeInputs.setTag("#" + slotIndex, currentStack.writeToNBT(new NBTTagCompound()));
}
return new PacketExtremeRecipe(recipeInputs);
}
private int getSlotIndex(int xy) {
switch (xy) {
case 7533:
return 1;
case 10333:
return 2;
case 4960:
return 3;
case 7660:
return 4;
case 10360:
return 5;
case 4987:
return 6;
case 7687:
return 7;
case 10387:
return 8;
case 4832:
default:
return 0;
}
}
private boolean isCraftingTableRecipe(IRecipeHandler recipe) {
TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe;
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
}
private boolean hasPatternTermExClz() {
try {
Class.forName("appeng.client.gui.implementations.GuiPatternTermEx");
} catch (ClassNotFoundException ignored) {
return false;
}
return true;
}
}
@@ -1,9 +1,11 @@
package com.github.vfyjxf.nee.network;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.network.packet.NEERecipeTransferPacket;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
public class NEENetworkHandler {
@@ -14,7 +16,9 @@ public class NEENetworkHandler {
}
public static void init() {
NEENetworkHandler.getInstance().registerMessage(NEERecipeTransferPacket.class, NEERecipeTransferPacket.class, 0, Side.SERVER);
INSTANCE.registerMessage(PacketNEIPatternRecipe.class, PacketNEIPatternRecipe.class, 0, Side.SERVER);
INSTANCE.registerMessage(PacketArcaneRecipe.class, PacketArcaneRecipe.class, 1, Side.SERVER);
INSTANCE.registerMessage(PacketExtremeRecipe.class, PacketExtremeRecipe.class, 2, Side.SERVER);
}
}
@@ -0,0 +1,97 @@
package com.github.vfyjxf.nee.network.packet;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.ReflectionHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import wanion.avaritiaddons.block.extremeautocrafter.ContainerExtremeAutoCrafter;
import wanion.avaritiaddons.block.extremeautocrafter.TileEntityExtremeAutoCrafter;
import javax.annotation.Nonnull;
import java.lang.reflect.Field;
/**
* @author vfyjxf
*/
public class PacketExtremeRecipe implements IMessage, IMessageHandler<PacketExtremeRecipe, IMessage> {
private NBTTagCompound input;
public PacketExtremeRecipe() {
}
public PacketExtremeRecipe(@Nonnull NBTTagCompound input) {
this.input = input;
}
public NBTTagCompound getInput() {
return input;
}
@Override
public void fromBytes(ByteBuf buf) {
this.input = ByteBufUtils.readTag(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeTag(buf, this.input);
}
@Override
public IMessage onMessage(PacketExtremeRecipe message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof ContainerExtremeAutoCrafter) {
ItemStack[] recipeInputs = new ItemStack[81];
NBTTagCompound currentStack;
for (int i = 0; i < recipeInputs.length; i++) {
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInputs[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
}
int inputIndex = 0;
for (int i = 81; i < 162; i++) {
Slot fakeSlot = container.getSlot(i);
ItemStack currentItem = recipeInputs[inputIndex];
fakeSlot.putStack(currentItem);
inputIndex++;
}
InventoryCrafting craftingMatrix = getCraftingMatrix((ContainerExtremeAutoCrafter) container);
if (craftingMatrix != null) {
container.onCraftMatrixChanged(craftingMatrix);
}
}
return null;
}
private InventoryCrafting getCraftingMatrix(ContainerExtremeAutoCrafter container) {
Field tileEntityExtremeAutoCrafterField = ReflectionHelper.findField(ContainerExtremeAutoCrafter.class, "tileEntityExtremeAutoCrafter");
TileEntityExtremeAutoCrafter tileEntityExtremeAutoCrafter = null;
try {
tileEntityExtremeAutoCrafter = (TileEntityExtremeAutoCrafter) tileEntityExtremeAutoCrafterField.get(container);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (tileEntityExtremeAutoCrafter != null) {
Field craftingMatrixField = ReflectionHelper.findField(TileEntityExtremeAutoCrafter.class, "craftingMatrix");
InventoryCrafting craftingMatrix = null;
try {
craftingMatrix = (InventoryCrafting) craftingMatrixField.get(tileEntityExtremeAutoCrafter);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return craftingMatrix;
}
return null;
}
}
@@ -1,73 +1,92 @@
package com.github.vfyjxf.nee.utils;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import mezz.jei.api.gui.IGuiIngredient;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import java.util.ArrayList;
import java.util.List;
import static com.github.vfyjxf.nee.NEEConfig.*;
/**
* @author vfyjxf
*/
public final class ItemUtils {
public static Gson gson = new Gson();
private static List<StackProcessor> getTransformItemBlacklist() {
public static List<StackProcessor> getTransformItemBlacklist() {
List<StackProcessor> transformItemBlacklist = new ArrayList<>();
for (String itemJsonString : itemBlacklist) {
JsonObject jsonObject = new JsonParser().parse(itemJsonString).getAsJsonObject();
if (jsonObject != null) {
String itemName = jsonObject.get("itemName").getAsString();
if (itemName == null || itemName.isEmpty()) {
continue;
for (String itemJsonString : transformBlacklist) {
StackProcessor processor = gson.fromJson(itemJsonString, StackProcessor.class);
if (processor != null) {
Item currentItem = GameRegistry.findItem(processor.modid, processor.name);
if (currentItem != null) {
ItemStack currentStack = processor.meta != null ? new ItemStack(currentItem, 1, Integer.parseInt(processor.meta)) : new ItemStack(currentItem);
if (processor.nbt != null) {
NBTTagCompound nbt = null;
try {
nbt = (NBTTagCompound) JsonToNBT.func_150315_a(processor.nbt);
} catch (NBTException e) {
e.printStackTrace();
}
if (nbt != null) {
currentStack.setTagCompound(nbt);
}
}
transformItemBlacklist.add(new StackProcessor(currentStack, currentItem, processor.recipeProcessor, processor.identifier));
}
int meta = itemJsonString.contains("meta") ? Integer.parseInt(jsonObject.get("meta").getAsString()) : 0;
String nbtJsonString = itemJsonString.contains("nbt") ? jsonObject.get("nbt").getAsString() : "";
ItemStack currentStack = GameRegistry.makeItemStack(itemName, meta, 1, nbtJsonString);
String recipeType = itemJsonString.contains("recipeType") ? jsonObject.get("name").getAsString() : "";
transformItemBlacklist.add(new StackProcessor(currentStack, recipeType));
}
}
return transformItemBlacklist;
}
private static List<StackProcessor> getTransformItemPriorityList() {
public static List<StackProcessor> getTransformItemPriorityList() {
List<StackProcessor> transformItemPriorityList = new ArrayList<>();
for (String itemJsonString : itemPriorityList) {
JsonObject jsonObject = new JsonParser().parse(itemJsonString).getAsJsonObject();
if (jsonObject != null) {
String itemName = jsonObject.get("itemName").getAsString();
if (itemName == null || itemName.isEmpty()) {
continue;
for (String itemJsonString : transformPriorityList) {
StackProcessor processor = gson.fromJson(itemJsonString, StackProcessor.class);
if (processor != null) {
Item currentItem = GameRegistry.findItem(processor.modid, processor.name);
if (currentItem != null) {
ItemStack currentStack = processor.meta != null ? new ItemStack(currentItem, 1, Integer.parseInt(processor.meta)) : new ItemStack(currentItem);
if (processor.nbt != null) {
NBTTagCompound nbt = null;
try {
nbt = (NBTTagCompound) JsonToNBT.func_150315_a(processor.nbt);
} catch (NBTException e) {
e.printStackTrace();
}
if (nbt != null) {
currentStack.setTagCompound(nbt);
}
}
transformItemPriorityList.add(new StackProcessor(currentStack, currentItem, processor.recipeProcessor, processor.identifier));
}
int meta = itemJsonString.contains("meta") ? Integer.parseInt(jsonObject.get("meta").getAsString()) : 0;
String nbtJsonString = itemJsonString.contains("nbt") ? jsonObject.get("nbt").getAsString() : "";
ItemStack currentStack = GameRegistry.makeItemStack(itemName, meta, 1, nbtJsonString);
String recipeType = itemJsonString.contains("recipeType") ? jsonObject.get("name").getAsString() : "";
transformItemPriorityList.add(new StackProcessor(currentStack, recipeType));
}
}
return transformItemPriorityList;
}
public static boolean isPreferItems(ItemStack itemStack, String recipeType) {
ItemStack stack = itemStack.copy();
stack.setCount(1);
for (StackProcessor stackProcessor : getTransformItemPriorityList()) {
if (ItemStack.areItemStacksEqual(stack, stackProcessor.itemStack)) {
String currentRecipeType = stackProcessor.recipeType;
if (currentRecipeType == null || currentRecipeType.isEmpty()) {
return true;
} else if (recipeType.equals(currentRecipeType)) {
public static boolean isPreferItems(ItemStack itemStack, String recipeProcessor, String identifier) {
for (StackProcessor processor : getTransformItemPriorityList()) {
ItemStack copyStack = itemStack.copy();
copyStack.stackSize = 1;
if (ItemStack.areItemStacksEqual(copyStack, processor.itemStack)) {
if (processor.recipeProcessor == null && processor.identifier == null) {
return true;
} else if (processor.recipeProcessor == null) {
return identifier.equals(processor.identifier);
} else if (processor.identifier == null) {
return recipeProcessor.equals(processor.recipeProcessor);
} else {
return recipeProcessor.equals(processor.recipeProcessor) && identifier.equals(processor.identifier);
}
}
}
@@ -75,51 +94,44 @@ public final class ItemUtils {
}
public static boolean isPreferItems(ItemStack itemStack) {
ItemStack stack = itemStack.copy();
stack.setCount(1);
for (StackProcessor stackProcessor : getTransformItemPriorityList()) {
if (ItemStack.areItemStacksEqual(stack, stackProcessor.itemStack)) {
for (StackProcessor processor : getTransformItemPriorityList()) {
ItemStack copyStack = itemStack.copy();
copyStack.stackSize = 1;
if (ItemStack.areItemStacksEqual(copyStack, processor.itemStack)) {
return true;
}
}
return false;
}
public static boolean isInBlackList(ItemStack itemStack, String recipeType) {
ItemStack stack = itemStack.copy();
stack.setCount(1);
for (StackProcessor stackProcessor : getTransformItemBlacklist()) {
if (ItemStack.areItemStacksEqual(stack, stackProcessor.itemStack)) {
String currentRecipeType = stackProcessor.recipeType;
if (currentRecipeType == null || currentRecipeType.isEmpty()) {
return true;
} else if (recipeType.equals(currentRecipeType)) {
public static boolean isInBlackList(ItemStack itemStack, String recipeProcessor, String identifier) {
for (StackProcessor processor : getTransformItemBlacklist()) {
ItemStack copyStack = itemStack.copy();
copyStack.stackSize = 1;
if (ItemStack.areItemStacksEqual(copyStack, processor.itemStack)) {
if (processor.recipeProcessor == null && processor.identifier == null) {
return true;
} else if (processor.recipeProcessor == null) {
return identifier.equals(processor.identifier);
} else if (processor.identifier == null) {
return recipeProcessor.equals(processor.recipeProcessor);
} else {
return recipeProcessor.equals(processor.recipeProcessor) && identifier.equals(processor.identifier);
}
}
}
return false;
}
public static ItemStack getPreferModItem(IGuiIngredient<ItemStack> ingredient) {
for (String currentId : modPriorityList) {
for (ItemStack currentIngredient : ingredient.getAllIngredients()) {
String itemModid = currentIngredient.getItem().getRegistryName().getNamespace();
if (itemModid.equals(currentId)) {
return currentIngredient;
public static ItemStack getPreferModItem(ItemStack[] items) {
for (String currentId : transformPriorityModList) {
for(ItemStack stack : items){
GameRegistry.UniqueIdentifier itemId = GameRegistry.findUniqueIdentifierFor(stack.getItem());
if(itemId.modId.equals(currentId)){
return stack;
}
}
}
return ItemStack.EMPTY;
}
public static boolean isPreferModItem(ItemStack stack) {
for (String currentId : modPriorityList) {
String itemModid = stack.getItem().getRegistryName().getNamespace();
if (itemModid.equals(currentId)) {
return true;
}
}
return false;
return null;
}
}