diff --git a/README.md b/README.md index de91066..4c3be58 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This mod removes that functionality and allows the player to use NEI's transfer - [x] Mekanism - [x] BloodMagic - [x] BuildCraft - +- [x] Avaritiaddons(auto extreme crafting table support) If you want other Mod support,see [RecipeProcessor](./src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java) and [Mod support Issue](https://github.com/vfyjxf/NotEnoughEnergistics/issues/1) ## TODO diff --git a/READNE_CN.md b/READNE_CN.md index fa67aaf..1b28ec9 100644 --- a/READNE_CN.md +++ b/READNE_CN.md @@ -31,7 +31,7 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min - [x] Mekanism - [x] BloodMagic - [x] BuildCraft - +- [x] Avaritiaddons(允许你从nei转移终极工作台配方到梦魇工作台) 如果你想要别的Mod的支持,请看[RecipeProcessor](./src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java) 或者[模组支持处理区](https://github.com/vfyjxf/NotEnoughEnergistics/issues/1) ## TODO diff --git a/src/main/java/com/github/vfyjxf/nee/jei/NEEJEIPlugin.java b/src/main/java/com/github/vfyjxf/nee/jei/NEEJEIPlugin.java deleted file mode 100644 index 54e1f39..0000000 --- a/src/main/java/com/github/vfyjxf/nee/jei/NEEJEIPlugin.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copied from Just Enough Energistics(https://github.com/p455w0rd/JustEnoughEnergistics/blob/master/src/main/java/p455w0rd/jee/integration/JEI.java) - */ -package com.github.vfyjxf.nee.jei; - -import appeng.container.implementations.ContainerPatternTerm; -import com.github.vfyjxf.nee.NotEnoughEnergistics; -import com.github.vfyjxf.nee.utils.WrappedTable; -import mezz.jei.api.IModPlugin; -import mezz.jei.api.IModRegistry; -import mezz.jei.api.JEIPlugin; -import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; -import mezz.jei.collect.Table; -import com.google.common.collect.Table.Cell; -import mezz.jei.config.Constants; -import mezz.jei.recipes.RecipeTransferRegistry; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; - -/** - * @author vfyjxf - */ -@JEIPlugin -public class NEEJEIPlugin implements IModPlugin { - - public static IModRegistry registry; - - @Override - public void register(IModRegistry registry) { - NEEJEIPlugin.registry = registry; - Table, String, IRecipeTransferHandler> newRegistry = Table.hashBasedTable(); - boolean ae2found = false; - for (final Cell currentCell : ((RecipeTransferRegistry) registry.getRecipeTransferRegistry()).getRecipeTransferHandlers().cellSet()) { - if (currentCell.getRowKey().equals(ContainerPatternTerm.class)) { - ae2found = true; - continue; - } - newRegistry.put(currentCell.getRowKey(), currentCell.getColumnKey(), currentCell.getValue()); - } - newRegistry.put(ContainerPatternTerm.class, Constants.UNIVERSAL_RECIPE_TRANSFER_UID, new NEERecipeTransferHandler()); - if (ae2found) { - NotEnoughEnergistics.logger.info("AE2 RecipeTransferHandler Replaced Successfully (Registered prior)"); - } else { - newRegistry = new WrappedTable<>(newRegistry); - } - ObfuscationReflectionHelper.setPrivateValue(RecipeTransferRegistry.class, (RecipeTransferRegistry) registry.getRecipeTransferRegistry(), newRegistry, "recipeTransferHandlers"); - } -} diff --git a/src/main/java/com/github/vfyjxf/nee/jei/NEERecipeTransferHandler.java b/src/main/java/com/github/vfyjxf/nee/jei/NEERecipeTransferHandler.java deleted file mode 100644 index d60a7ac..0000000 --- a/src/main/java/com/github/vfyjxf/nee/jei/NEERecipeTransferHandler.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.github.vfyjxf.nee.jei; - -import appeng.container.implementations.ContainerPatternTerm; -import com.github.vfyjxf.nee.NEEConfig; -import com.github.vfyjxf.nee.NotEnoughEnergistics; -import com.github.vfyjxf.nee.network.NEENetworkHandler; -import com.github.vfyjxf.nee.network.packet.NEERecipeTransferPacket; -import com.github.vfyjxf.nee.utils.ItemUtils; -import com.github.vfyjxf.nee.utils.StackProcessor; -import mezz.jei.api.gui.IGuiIngredient; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.recipe.VanillaRecipeCategoryUid; -import mezz.jei.api.recipe.transfer.IRecipeTransferError; -import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import static com.github.vfyjxf.nee.jei.NEEJEIPlugin.registry; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * @author vfyjxf - */ -public class NEERecipeTransferHandler implements IRecipeTransferHandler { - - public static final String OUTPUT_KEY = "Outputs"; - - public NEERecipeTransferHandler() { - } - - @Override - public Class getContainerClass() { - return ContainerPatternTerm.class; - } - - @Nullable - @Override - public IRecipeTransferError transferRecipe(ContainerPatternTerm container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) { - String recipeType = recipeLayout.getRecipeCategory().getUid(); - boolean isCraftingRecipe = isCraftingRecipe(recipeType); - if (container.isCraftingMode()) { - if (!isCraftingRecipe && !NEEConfig.allowAutomaticSwitchPatternTerminalMode) { - return registry.getJeiHelpers().recipeTransferHandlerHelper().createUserErrorWithTooltip(I18n.format("jei.tooltip.nee.need.processing")); - } - } else { - if (isCraftingRecipe && !NEEConfig.allowAutomaticSwitchPatternTerminalMode) { - return registry.getJeiHelpers().recipeTransferHandlerHelper().createUserErrorWithTooltip(I18n.format("jei.tooltip.nee.need.crating")); - } - } - if (doTransfer) { - final Map> ingredients = recipeLayout.getItemStacks().getGuiIngredients(); - final NBTTagCompound recipeInputs = new NBTTagCompound(); - final NBTTagCompound recipeOutputs = new NBTTagCompound(); - int inputIndex = 0; - int outputIndex = 0; - List tInputs = new ArrayList<>(); - for (Map.Entry> entry : ingredients.entrySet()) { - final IGuiIngredient ingredient = entry.getValue(); - if (ingredient != null) { - ItemStack currentStack = ingredient.getDisplayedIngredient() == null ? ItemStack.EMPTY : ingredient.getDisplayedIngredient().copy(); - if (ingredient.isInput()) { - if (isCraftingRecipe) { - tInputs.add(new StackProcessor(ingredient, currentStack.getCount())); - } else { - boolean find = false; - if (currentStack.isEmpty()) { - continue; - } - for (StackProcessor storedIngredient : tInputs) { - ItemStack storedStack = storedIngredient.ingredient.getDisplayedIngredient(); - if (storedStack != null && currentStack.isItemEqual(storedStack) && ItemStack.areItemStackTagsEqual(currentStack, storedStack)) { - if (currentStack.getCount() + storedIngredient.stackSize <= storedStack.getMaxStackSize()) { - find = true; - storedIngredient.stackSize = currentStack.getCount() + storedIngredient.stackSize; - } - } - } - if (!find) { - tInputs.add(new StackProcessor(ingredient, currentStack.getCount())); - } - } - } else { - if (outputIndex >= 3 || currentStack.isEmpty() || (container.isCraftingMode() && !NEEConfig.allowAutomaticSwitchPatternTerminalMode)) { - continue; - } - recipeOutputs.setTag(OUTPUT_KEY + outputIndex, currentStack.writeToNBT(new NBTTagCompound())); - outputIndex++; - } - } - - } - - for (StackProcessor currentIngredient : tInputs) { - ItemStack currentStack = currentIngredient.ingredient.getDisplayedIngredient() == null ? ItemStack.EMPTY : currentIngredient.ingredient.getDisplayedIngredient().copy(); - ItemStack preferModItem = ItemUtils.isPreferModItem(currentStack) ? currentStack : ItemUtils.getPreferModItem(currentIngredient.ingredient); - - if (!currentStack.isEmpty()) { - currentStack.setCount(currentIngredient.stackSize); - } - - if (!currentStack.isEmpty() && preferModItem != null && !preferModItem.isEmpty()) { - currentStack = preferModItem.copy(); - currentStack.setCount(currentIngredient.stackSize); - } - for (ItemStack stack : currentIngredient.ingredient.getAllIngredients()) { - if (ItemUtils.isPreferItems(stack, recipeType) && !currentStack.isEmpty()) { - currentStack = stack.copy(); - currentStack.setCount(currentIngredient.stackSize); - } - } - if (!currentStack.isEmpty() && ItemUtils.isInBlackList(currentStack, recipeType)) { - continue; - } - recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound())); - inputIndex++; - } - NEENetworkHandler.getInstance().sendToServer(new NEERecipeTransferPacket(recipeInputs, recipeOutputs, isCraftingRecipe)); - if (NEEConfig.allowPrintRecipeType) { - NotEnoughEnergistics.logger.info(recipeType); - } - } - - return null; - } - - private boolean isCraftingRecipe(String recipeType) { - if (!recipeType.equals(VanillaRecipeCategoryUid.INFORMATION) && !recipeType.equals(VanillaRecipeCategoryUid.FUEL)) { - return recipeType.equals(VanillaRecipeCategoryUid.CRAFTING); - } - return false; - } - -} diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/NEERecipeTransferPacket.java b/src/main/java/com/github/vfyjxf/nee/network/packet/NEERecipeTransferPacket.java deleted file mode 100644 index e82a8b3..0000000 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/NEERecipeTransferPacket.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.github.vfyjxf.nee.network.packet; - -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.networking.storage.IStorageGrid; -import appeng.container.implementations.ContainerPatternTerm; -import appeng.helpers.IContainerCraftingPacket; -import appeng.util.helpers.ItemHandlerUtil; -import appeng.util.inv.WrapperInvItemHandler; -import io.netty.buffer.ByteBuf; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Container; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.items.IItemHandler; - -import javax.annotation.Nonnull; - -import static com.github.vfyjxf.nee.jei.NEERecipeTransferHandler.OUTPUT_KEY; - -/** - * @author vfyjxf - */ -public class NEERecipeTransferPacket implements IMessage, IMessageHandler { - - private NBTTagCompound input; - private NBTTagCompound output; - private boolean craftingMode; - - public NEERecipeTransferPacket() { - - } - - public NEERecipeTransferPacket(@Nonnull NBTTagCompound input, NBTTagCompound output, boolean craftingMode) { - this.input = input; - this.output = output; - this.craftingMode = craftingMode; - } - - public NBTTagCompound getInput() { - return input; - } - - public NBTTagCompound getOutput() { - return output; - } - - public boolean getCraftingMode() { - return craftingMode; - } - - @Override - public void fromBytes(ByteBuf buf) { - this.input = ByteBufUtils.readTag(buf); - this.craftingMode = buf.readBoolean(); - if (buf.readBoolean()) { - this.output = ByteBufUtils.readTag(buf); - } - } - - @Override - public void toBytes(ByteBuf buf) { - ByteBufUtils.writeTag(buf, this.input); - buf.writeBoolean(this.craftingMode); - if (this.output != null) { - buf.writeBoolean(true); - ByteBufUtils.writeTag(buf, this.output); - } else { - buf.writeBoolean(false); - } - } - - @Override - public IMessage onMessage(NEERecipeTransferPacket message, MessageContext ctx) { - EntityPlayerMP player = ctx.getServerHandler().player; - Container container = player.openContainer; - player.getServerWorld().addScheduledTask(() -> { - if (container instanceof ContainerPatternTerm) { - ((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(message.getCraftingMode()); - ItemStack[] recipeInputs = new ItemStack[9]; - ItemStack[] recipeOutputs = null; - NBTTagCompound currentStack; - - for (int i = 0; i < recipeInputs.length; i++) { - currentStack = message.getInput().getCompoundTag("#" + i); - recipeInputs[i] = currentStack.isEmpty() ? ItemStack.EMPTY : new ItemStack(currentStack); - } - - if (!message.output.isEmpty()) { - recipeOutputs = new ItemStack[3]; - for (int i = 0; i < recipeOutputs.length; i++) { - currentStack = message.getOutput().getCompoundTag(OUTPUT_KEY + i); - recipeOutputs[i] = currentStack.isEmpty() ? ItemStack.EMPTY : new ItemStack(currentStack); - } - } - final IContainerCraftingPacket cct = (IContainerCraftingPacket) container; - final IGridNode node = cct.getNetworkNode(); - if (node == null) { - return; - } - final IGrid grid = node.getGrid(); - final IStorageGrid inv = grid.getCache(IStorageGrid.class); - final ISecurityGrid security = grid.getCache(ISecurityGrid.class); - final IItemHandler craftMatrix = cct.getInventoryByName("crafting"); - if (message.input != null) { - for (int i = 0; i < craftMatrix.getSlots(); i++) { - ItemStack currentItem = ItemStack.EMPTY; - if (recipeInputs[i] != null) { - currentItem = recipeInputs[i].copy(); - } - ItemHandlerUtil.setStackInSlot(craftMatrix, i, currentItem); - } - if (recipeOutputs != null && !message.getCraftingMode()) { - final IItemHandler outputMatrix = cct.getInventoryByName("output"); - for (int i = 0; i < outputMatrix.getSlots(); i++) { - ItemStack currentItem = ItemStack.EMPTY; - if (recipeOutputs[i] != null) { - currentItem = recipeOutputs[i].copy(); - } - ItemHandlerUtil.setStackInSlot(outputMatrix, i, currentItem); - } - } - container.onCraftMatrixChanged(new WrapperInvItemHandler(craftMatrix)); - } - } - }); - return null; - } - -} diff --git a/src/main/java/com/github/vfyjxf/nee/utils/WrappedTable.java b/src/main/java/com/github/vfyjxf/nee/utils/WrappedTable.java deleted file mode 100644 index 0a8d44d..0000000 --- a/src/main/java/com/github/vfyjxf/nee/utils/WrappedTable.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copied from Just Enough Energistics(https://github.com/p455w0rd/JustEnoughEnergistics/blob/master/src/main/java/p455w0rd/jee/util/WrappedTable.java) - */ -package com.github.vfyjxf.nee.utils; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Supplier; - -import com.github.vfyjxf.nee.NotEnoughEnergistics; -import com.github.vfyjxf.nee.jei.NEERecipeTransferHandler; -import com.google.common.collect.ImmutableTable; - -import appeng.container.implementations.ContainerPatternTerm; -import mezz.jei.collect.Table; - -public class WrappedTable extends Table { - - private static final Field f_modifiers; - private static final Field f_table; - private static final Field f_rowMappingFunction; - private final Table wrapped; - - static { - try { - f_modifiers = Field.class.getDeclaredField("modifiers"); - f_modifiers.setAccessible(true); - - f_table = Table.class.getDeclaredField("table"); - f_table.setAccessible(true); - makeWriteable(f_table); - - f_rowMappingFunction = Table.class.getDeclaredField("rowMappingFunction"); - f_rowMappingFunction.setAccessible(true); - makeWriteable(f_rowMappingFunction); - - } - catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException("Unable to do reflection things.", e); - } - } - - public WrappedTable(Table other) { - super(new HashMap<>(), HashMap::new);//Dummy values to constructor, will be replaced. - wrapped = other; - - //Set underlying table stuff incase anyone else reflects it. - try { - f_table.set(this, f_table.get(other)); - f_rowMappingFunction.set(this, f_rowMappingFunction.get(other)); - } - catch (IllegalAccessException e) { - throw new RuntimeException("Unable to do reflection things.", e); - } - } - - @SuppressWarnings("unchecked") - public V onValueSet(R row, V value) { - if (row == ContainerPatternTerm.class && value.getClass().getCanonicalName().equals("appeng.integration.modules.jei.RecipeTransferHandler")) { - value = (V) new NEERecipeTransferHandler(); - NotEnoughEnergistics.logger.info("AE2 RecipeTransfeHandler Replaced Successfully (Overwrite Denied)"); - } - return value; - } - - @Override - public V computeIfAbsent(R row, C col, Supplier valueSupplier) { - Map rowMap = getRow(row); - return rowMap.computeIfAbsent(col, k -> onValueSet(row, valueSupplier.get())); - } - - @Override - public V put(R row, C col, V val) { - Map rowMap = getRow(row); - return rowMap.put(col, onValueSet(row, val)); - } - - @Override - public V get(R row, C col) { - return wrapped.get(row, col); - } - - @Override - public Map getRow(R row) { - return wrapped.getRow(row); - } - - @Override - public ImmutableTable toImmutable() { - return wrapped.toImmutable(); - } - - private static void makeWriteable(Field field) throws IllegalAccessException { - if ((field.getModifiers() & Modifier.FINAL) != 0) { - f_modifiers.set(field, field.getModifiers() & ~Modifier.FINAL); - } - } - -}