Add TCNEIPlugin support and ThaumicEnergistics support

This commit is contained in:
vfyjxf committed 2021-08-08 17:31:14 +08:00
1 parent 5b53c52f71
commit fffc512469
27 files changed
+266 -24

No files matched your search

@@ -7,6 +7,8 @@ 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 java.util.*;
@@ -18,32 +20,24 @@ public class NEINeeConfig implements IConfigureNEI {
RecipeProcessor.init();
Set<String> defaultIdentifiers= new HashSet<>(
Arrays.asList("crafting", "crafting2x2","brewing","smelting","fuel",null)
Set<String> defaultIdentifiers = new HashSet<>(
Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null)
);
Set<String> identifiers = new HashSet<>(defaultIdentifiers);
for(IRecipeProcessor processor : RecipeProcessor.recipeProcessors){
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);
for (String ident : identifiers) {
API.registerGuiOverlay(GuiPatternTerm.class, ident);
API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident);
}
try {
Class.forName("appeng.client.gui.implementations.GuiPatternTermEx");
} catch (ClassNotFoundException e) {
return;
}
installPatternTerminalExSupport(identifiers);
installThaumicEnergisticsSupport();
identifiers.removeAll(defaultIdentifiers);
//PatternTermEx Support
for(String ident : identifiers){
API.registerGuiOverlay(GuiPatternTermEx.class, ident);
API.registerGuiOverlayHandler(GuiPatternTermEx.class, new NEECraftingHandler(), ident);
}
}
@Override
@@ -55,4 +49,36 @@ public class NEINeeConfig implements IConfigureNEI {
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);
}
}
}
@@ -8,6 +8,7 @@ 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.PacketNEIPatternRecipe;
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
import com.github.vfyjxf.nee.processor.RecipeProcessor;
@@ -29,8 +30,9 @@ public class NEECraftingHandler implements IOverlayHandler {
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
if (firstGui instanceof GuiPatternTerm || firstGui instanceof GuiPatternTermEx) {
NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex));
} else {
knowledgeInscriberHandler(firstGui, recipe, recipeIndex);
}
}
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) {
@@ -84,7 +86,7 @@ public class NEECraftingHandler implements IOverlayHandler {
}
for (PositionedStack positionedStack : outputs) {
if (outputIndex >= 4 ||positionedStack == null || positionedStack.item == null) {
if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) {
continue;
}
recipeOutputs.setTag(OUTPUT_KEY + outputIndex, positionedStack.item.writeToNBT(new NBTTagCompound()));
@@ -117,6 +119,72 @@ public class NEECraftingHandler implements IOverlayHandler {
return new PacketNEIPatternRecipe(recipeInputs, null);
}
private void knowledgeInscriberHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
Class<?> knowledgeInscriberClz = null;
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);
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 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();
@@ -1,6 +1,7 @@
package com.github.vfyjxf.nee.network;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
@@ -15,6 +16,7 @@ public class NEENetworkHandler {
public static void init(){
INSTANCE.registerMessage(PacketNEIPatternRecipe.class, PacketNEIPatternRecipe.class,0, Side.SERVER);
INSTANCE.registerMessage(PacketArcaneRecipe.class, PacketArcaneRecipe.class, 1, Side.SERVER);
}
}
@@ -0,0 +1,77 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.container.slot.SlotFakeCraftingMatrix;
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.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import thaumicenergistics.common.container.ContainerKnowledgeInscriber;
import java.lang.reflect.Field;
/**
* @author vfyjxf
*/
public class PacketArcaneRecipe implements IMessage, IMessageHandler<PacketArcaneRecipe, IMessage> {
NBTTagCompound input;
public PacketArcaneRecipe() {}
public PacketArcaneRecipe(NBTTagCompound input) {
this.input = 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(PacketArcaneRecipe message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof ContainerKnowledgeInscriber) {
ItemStack[] recipeInput = new ItemStack[9];
NBTTagCompound currentStack;
for (int i = 0; i < recipeInput.length; i++) {
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
}
Field craftingSlots = ReflectionHelper.findField(ContainerKnowledgeInscriber.class, "craftingSlots");
SlotFakeCraftingMatrix[] craftMatrix = getCraftingSlots(craftingSlots, (ContainerKnowledgeInscriber) container);
if (craftMatrix != null && message.input != null) {
for (int i = 0; i < recipeInput.length; i++) {
ItemStack currentItem = null;
if (recipeInput[i] != null) {
currentItem = recipeInput[i].copy();
}
craftMatrix[i].putStack(currentItem);
}
((ContainerKnowledgeInscriber) container).func_75130_a(craftMatrix[0].inventory);
}
}
return null;
}
private SlotFakeCraftingMatrix[] getCraftingSlots(Field field, ContainerKnowledgeInscriber container) {
try {
return (SlotFakeCraftingMatrix[]) field.get(container);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
@@ -27,8 +27,7 @@ public class PacketNEIPatternRecipe implements IMessage, IMessageHandler<PacketN
NBTTagCompound input;
NBTTagCompound output;
public PacketNEIPatternRecipe() {
}
public PacketNEIPatternRecipe() {}
public PacketNEIPatternRecipe(@Nonnull NBTTagCompound input, NBTTagCompound output) {
this.input = input;
@@ -119,6 +118,7 @@ public class PacketNEIPatternRecipe implements IMessage, IMessageHandler<PacketN
for (int i = 0; i < recipeInput.length; i++) {
NBTTagCompound currentStack = (NBTTagCompound) message.input.getTag("#" + i);
recipeInput[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
System.out.println(currentStack);
}
for (int i = 0; i < recipeOutput.length; i++) {
@@ -34,6 +34,10 @@ public class RecipeProcessor {
NotEnoughEnergistics.logger.info("Found Forestry, install Forestry support");
recipeProcessors.add(new ForestryRecipeProcessor());
}
if(Loader.isModLoaded("thaumcraftneiplugin")){
NotEnoughEnergistics.logger.info("Found TCNEIPlugin, install TCNEIPlugin support");
recipeProcessors.add(new TCNEIPluginRecipeProcessor());
}
if (Loader.isModLoaded("appliedenergistics2")) {
NotEnoughEnergistics.logger.info("Applied Energistics 2 will not be supported");
}
@@ -0,0 +1,45 @@
package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect;
import java.util.*;
/**
* @author vfyjxf
*/
public class TCNEIPluginRecipeProcessor implements IRecipeProcessor{
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
"arcaneshapedrecipes","arcaneshapelessrecipes","aspectsRecipe",
"cruciblerecipe","infusionCrafting"
));
}
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for(String ident : getAllOverlayIdentifier()){
if(ident.equals(identifier)){
List<PositionedStack> recipeInputs = new ArrayList<>(recipe.getIngredientStacks(recipeIndex));
recipeInputs.removeIf(positionedStack -> positionedStack.item.getItem() instanceof ItemAspect);
return recipeInputs;
}
}
return null;
}
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
for(String ident : getAllOverlayIdentifier()){
if(ident.equals(identifier)){
List<PositionedStack> recipeOutputs = new ArrayList<>();
recipeOutputs.add(recipe.getResultStack(recipeIndex));
return recipeOutputs;
}
}
return null;
}
}