Merge remote-tracking branch 'vfyjxf/main'

# Conflicts:
#	gradle.properties
#	src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java
This commit is contained in:
Martin Robertz committed 2022-01-02 14:14:26 +01:00
commit a7919fe707
36 files changed
+1383 -423

No files matched your search

@@ -57,7 +57,7 @@ public class NEINeeConfig implements IConfigureNEI {
for (String ident : identifiers) {
API.registerGuiOverlay(GuiPatternTerm.class, ident);
API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident);
API.registerGuiOverlayHandler(GuiPatternTerm.class, NEECraftingHandler.INSTANCE, ident);
}
installCraftingTermSupport();
@@ -1,6 +1,7 @@
package com.github.vfyjxf.nee;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.gui.NEEGuiHandler;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.proxy.CommonProxy;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -8,7 +9,9 @@ import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.launchwrapper.Launch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -33,6 +36,9 @@ public class NotEnoughEnergistics {
@SidedProxy(clientSide = "com.github.vfyjxf.nee.proxy.ClientProxy", serverSide = "com.github.vfyjxf.nee.proxy.ServerProxy")
public static CommonProxy proxy;
@Mod.Instance(MODID)
public static NotEnoughEnergistics instance;
@EventHandler
public void preInit(FMLPreInitializationEvent e) {
NEENetworkHandler.init();
@@ -40,6 +46,11 @@ public class NotEnoughEnergistics {
FMLCommonHandler.instance().bus().register(new NEEConfig());
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
NetworkRegistry.INSTANCE.registerGuiHandler(this, new NEEGuiHandler());
}
@EventHandler
public void init(FMLInitializationEvent event) {
proxy.init(event);
@@ -0,0 +1,89 @@
package com.github.vfyjxf.nee.asm;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.*;
import java.util.Arrays;
import java.util.List;
import static org.objectweb.asm.Opcodes.*;
public class NEEClassTransformer implements IClassTransformer {
private static final List<String> transformedClassNames = Arrays.asList(
"appeng/integration/modules/NEIHelpers/NEIInscriberRecipeHandler",
"appeng/integration/modules/NEIHelpers/NEIGrinderRecipeHandler"
);
private static final String METHOD_OWNER = "codechicken/nei/recipe/TemplateRecipeHandler";
private static final String METHOD_NAME_1 = "getOverlayHandler";
private static final String METHOD_NAME_2 = "hasOverlay";
private static final String METHOD_TARGET_1 = "(Lnet/minecraft/client/gui/inventory/GuiContainer;I)Lcodechicken/nei/api/IOverlayHandler;";
private static final String METHOD_TARGET_2 = "(Lnet/minecraft/client/gui/inventory/GuiContainer;Lnet/minecraft/inventory/Container;I)Z";
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
String internalName = transformedName.replace('.', '/');
//rewrite ae2's methods to support recipe transfer.
if (transformedClassNames.contains(internalName)) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
for (MethodNode methodNode : classNode.methods) {
if (METHOD_NAME_1.equals(methodNode.name) && METHOD_TARGET_1.equals(methodNode.desc)) {
NotEnoughEnergistics.logger.info("Transforming : " + internalName + methodNode.name + methodNode.desc);
for (AbstractInsnNode instruction : methodNode.instructions.toArray()) {
if (instruction.getOpcode() == ACONST_NULL) {
InsnList insnList = new InsnList();
insnList.add(new VarInsnNode(ALOAD, 0));
insnList.add(new VarInsnNode(ALOAD, 1));
insnList.add(new VarInsnNode(ILOAD, 2));
insnList.add(new MethodInsnNode(INVOKESPECIAL,
METHOD_OWNER,
METHOD_NAME_1,
METHOD_TARGET_1,
false));
methodNode.instructions.insert(instruction, insnList);
methodNode.instructions.remove(instruction);
}
}
}
if (METHOD_NAME_2.equals(methodNode.name) && METHOD_TARGET_2.equals(methodNode.desc)) {
NotEnoughEnergistics.logger.info("Transforming : " + internalName + methodNode.name + methodNode.desc);
for (AbstractInsnNode instruction : methodNode.instructions.toArray()) {
if (instruction.getOpcode() == ICONST_0) {
InsnList insnList = new InsnList();
insnList.add(new VarInsnNode(ALOAD, 0));
insnList.add(new VarInsnNode(ALOAD, 1));
insnList.add(new VarInsnNode(ALOAD, 2));
insnList.add(new VarInsnNode(ILOAD, 3));
insnList.add(new MethodInsnNode(INVOKESPECIAL,
METHOD_OWNER,
METHOD_NAME_2,
METHOD_TARGET_2,
false));
methodNode.instructions.insert(instruction, insnList);
methodNode.instructions.remove(instruction);
}
}
}
}
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(classWriter);
return classWriter.toByteArray();
}
return basicClass;
}
}
@@ -0,0 +1,37 @@
package com.github.vfyjxf.nee.asm;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import java.util.Map;
@IFMLLoadingPlugin.Name("NEELoadingPlugin")
@IFMLLoadingPlugin.MCVersion("1.7.10")
@IFMLLoadingPlugin.TransformerExclusions("com.github.vfyjxf.nee.asm")
public class NEELoadingPlugin implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
return new String[]{
"com.github.vfyjxf.nee.asm.NEEClassTransformer"
};
}
@Override
public String getModContainerClass() {
return null;
}
@Override
public String getSetupClass() {
return null;
}
@Override
public void injectData(Map<String, Object> data) {
}
@Override
public String getAccessTransformerClass() {
return null;
}
}
@@ -1,11 +1,13 @@
package com.github.vfyjxf.nee.client;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiInterface;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.slot.SlotFake;
import appeng.util.item.AEItemStack;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.PositionedStack;
import codechicken.nei.VisiblityData;
@@ -14,7 +16,7 @@ import codechicken.nei.api.TaggedInventoryArea;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingHelper;
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange;
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
import com.github.vfyjxf.nee.utils.GuiUtils;
@@ -71,8 +73,9 @@ public class GuiHandler implements INEIGuiHandler {
boolean isGuiCraftingTerm = event.gui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(event.gui);
boolean isGuiCraftConfirm = currentScreen instanceof GuiCraftConfirm || GuiUtils.isWirelessGuiCraftConfirm(currentScreen);
if (isGuiCraftingTerm && isGuiCraftConfirm && tracker != null) {
if (tracker.getRequireToCraftStacks().size() > 1 && stackIndex < tracker.getRequireToCraftStacks().size()) {
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(stackIndex), noPreview));
if (!tracker.getRequireStacks().isEmpty() && stackIndex < tracker.getRequireStacks().size()) {
IAEItemStack stack = AEItemStack.create(tracker.getRequireStacks().get(stackIndex));
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
stackIndex++;
}
} else if (!isGuiCraftingTerm && isGuiCraftConfirm && tracker != null) {
@@ -20,7 +20,6 @@ import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.GuiScreenEvent;
import org.lwjgl.input.Keyboard;
@@ -84,7 +83,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
this.overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons");
this.recipesPerPageMethod = GuiRecipe.class.getDeclaredMethod("getRecipesPerPage");
this.overlayButtonsField.setAccessible(true);
recipesPerPageMethod.setAccessible(true);
this.recipesPerPageMethod.setAccessible(true);
} catch (NoSuchMethodException | NoSuchFieldException e) {
this.isGtnhNei = false;
}
@@ -112,8 +111,8 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
}
} else {
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay2");
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
@@ -134,27 +133,43 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
if (recipesPerPage >= 0 && handler != null) {
int recipeIndex = guiRecipe.page * recipesPerPage + button.id - OVERLAY_BUTTON_ID_START;
List<PositionedStack> ingredients = handler.getIngredientStacks(recipeIndex);
IngredientTracker tracker = createTracker(guiRecipe.firstGui, ingredients);
IngredientTracker tracker = new IngredientTracker(guiRecipe.firstGui, handler, recipeIndex);
for (int var1 = 0; var1 < ingredients.size(); var1++) {
PositionedStack stack = ingredients.get(var1);
Ingredient ingredient = tracker.getIngredients().get(var1);
Slot stackSlot = guiRecipe.slotcontainer.getSlotWithStack(stack, guiRecipe.getRecipePosition(recipeIndex).x, guiRecipe.getRecipePosition(recipeIndex).y);
if (stackSlot.equals(slot)) {
boolean renderAutoAbleItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft();
boolean renderCraftableItems = (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) && ingredient.isCraftable();
boolean renderMissingItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft();
if (renderAutoAbleItems || renderCraftableItems) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB());
this.drawCraftableTooltip = renderCraftableItems;
this.drawRequestTooltip = renderAutoAbleItems;
} else if (renderMissingItems) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB());
this.drawMissingTooltip = true;
if (!NEEConfig.enableCraftAmountSettingGui) {
boolean renderAutoAbleItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft();
boolean renderCraftableItems = (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) && ingredient.isCraftable();
boolean renderMissingItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft();
if (renderAutoAbleItems || renderCraftableItems) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB());
this.drawCraftableTooltip = renderCraftableItems;
this.drawRequestTooltip = renderAutoAbleItems;
}
if (renderMissingItems) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB());
this.drawMissingTooltip = true;
}
} else {
if (ingredient.isCraftable()) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB());
this.drawRequestTooltip = true;
} else {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB());
this.drawMissingTooltip = true;
}
}
}
}
@@ -168,7 +183,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
@SubscribeEvent
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
if (this.drawCraftableTooltip || this.drawRequestTooltip) {
if (this.drawCraftableTooltip || this.drawRequestTooltip || this.drawMissingTooltip) {
if (event.gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
List<GuiButton> overlayButtons = null;
@@ -180,8 +195,8 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
}
} else {
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay2");
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
@@ -203,12 +218,12 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
List<String> tooltips = new ArrayList<>();
boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui);
if (isCraftingTerm) {
if(this.drawRequestTooltip) {
if (this.drawRequestTooltip) {
tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " +
EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting"),
EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview"))));
}
if(this.drawMissingTooltip){
if (this.drawMissingTooltip) {
tooltips.add(EnumChatFormatting.RED + I18n.format("neenergistics.gui.tooltip.missing"));
}
}
@@ -219,31 +234,4 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
//drawHoveringText
guiRecipe.func_146283_a(tooltips, mouseX, mouseY);
}
@SuppressWarnings("unchecked")
private IngredientTracker createTracker(GuiContainer firstGui, List<PositionedStack> ingredients) {
IngredientTracker tracker = new IngredientTracker(firstGui, ingredients);
//check stacks in player's inventory and crafting grid
List<ItemStack> inventoryStacks = new ArrayList<>();
for (Slot slot : (List<Slot>) firstGui.inventorySlots.inventorySlots) {
boolean canGetStack = slot != null &&
slot.getHasStack() &&
slot.getStack().stackSize > 0 &&
slot.isItemValid(slot.getStack()) &&
slot.canTakeStack(Minecraft.getMinecraft().thePlayer);
if (canGetStack) {
inventoryStacks.add(slot.getStack().copy());
}
}
for (int i = 0; i < tracker.getIngredients().size(); i++) {
for (ItemStack stack : inventoryStacks) {
tracker.addAvailableStack(stack);
}
}
return tracker;
}
}
@@ -23,7 +23,8 @@ public class NEEConfig {
public static boolean matchOtherItems = true;
public static boolean drawHighlight = true;
public static boolean allowSynchronousSwitchIngredient = true;
public static boolean useStackSizeFromNEI = true;
public static boolean useStackSizeFromNEI = false;
public static boolean enableCraftAmountSettingGui = true;
public static int draggedStackDefaultSize = 1;
@@ -53,9 +54,12 @@ public class NEEConfig {
allowSynchronousSwitchIngredient = config.get("client", "allowSynchronousSwitchIngredient", true,
"If true, it will make all similar ingredient switch at the same time").getBoolean(true);
useStackSizeFromNEI = config.get("client","useStackSizeFromNEI",true,
useStackSizeFromNEI = config.get("client", "useStackSizeFromNEI", false,
"Use the StackSize set by NEI").getBoolean();
enableCraftAmountSettingGui = config.get("client", "enableCraftAmountSettingGui", true,
"If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean();
draggedStackDefaultSize = config.get("client", "draggedStackDefaultSize", 1,
"The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt();
@@ -80,9 +84,12 @@ public class NEEConfig {
allowSynchronousSwitchIngredient = config.get("client", "allowSynchronousSwitchIngredient", true,
"If true, it will make all similar ingredient switch at the same time").getBoolean(true);
useStackSizeFromNEI = config.get("client","useStackSizeFromNEI",true,
useStackSizeFromNEI = config.get("client", "useStackSizeFromNEI", false,
"Use the StackSize set by NEI").getBoolean();
enableCraftAmountSettingGui = config.get("client", "enableCraftAmountSettingGui", true,
"If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean();
draggedStackDefaultSize = config.get("client", "draggedStackDefaultSize", 1,
"The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt();
@@ -0,0 +1,58 @@
package com.github.vfyjxf.nee.container;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotInaccessible;
import appeng.tile.inventory.AppEngInternalInventory;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ContainerCraftingAmount extends AEBaseContainer {
private final Slot resultSlot;
private ItemStack resultStack;
public ContainerCraftingAmount(InventoryPlayer ip, Object anchor) {
super(ip, anchor);
this.resultSlot = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53);
this.addSlotToContainer(resultSlot);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
this.verifyPermissions(SecurityPermissions.CRAFT, false);
}
public IGrid getGrid() {
final IActionHost h = ((IActionHost) this.getTarget());
return h.getActionableNode().getGrid();
}
public World getWorld() {
return this.getPlayerInv().player.worldObj;
}
public BaseActionSource getActionSrc() {
return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget());
}
public Slot getResultSlot() {
return resultSlot;
}
public ItemStack getResultStack() {
return resultStack;
}
public void setResultStack(ItemStack resultStack) {
this.resultStack = resultStack;
}
}
@@ -0,0 +1,271 @@
package com.github.vfyjxf.nee.gui;
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.definitions.IParts;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiNumberBox;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.container.AEBaseContainer;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.helpers.Reflected;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.util.item.AEItemStack;
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.ModIDs;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum;
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
import java.util.Collections;
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*;
public class GuiCraftingAmount extends AEBaseGui {
private GuiNumberBox amountToCraft;
private GuiTabButton originalGuiBtn;
private GuiButton start;
private GuiButton plus1;
private GuiButton plus10;
private GuiButton plus100;
private GuiButton plus1000;
private GuiButton minus1;
private GuiButton minus10;
private GuiButton minus100;
private GuiButton minus1000;
private GuiBridge originalGui;
private boolean isWirelessCrafting;
@Reflected
public GuiCraftingAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
super(new ContainerCraftingAmount(inventoryPlayer, te));
}
@SuppressWarnings("unchecked")
@Override
public void initGui() {
super.initGui();
final int a = AEConfig.instance.craftItemsByStackAmounts(0);
final int b = AEConfig.instance.craftItemsByStackAmounts(1);
final int c = AEConfig.instance.craftItemsByStackAmounts(2);
final int d = AEConfig.instance.craftItemsByStackAmounts(3);
this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a));
this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b));
this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c));
this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d));
this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a));
this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b));
this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c));
this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d));
this.buttonList.add(this.start = new GuiButton(0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal()));
ItemStack myIcon = null;
final Object target = ((AEBaseContainer) this.inventorySlots).getTarget();
final IDefinitions definitions = AEApi.instance().definitions();
final IParts parts = definitions.parts();
if (target instanceof PartCraftingTerminal) {
for (final ItemStack stack : parts.craftingTerminal().maybeStack(1).asSet()) {
myIcon = stack;
}
this.originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
}
if (Loader.isModLoaded(ModIDs.WCT) && GuiUtils.isWirelessTerminalGuiObject(target)) {
myIcon = new ItemStack(ItemEnum.WIRELESS_CRAFTING_TERMINAL.getItem());
this.isWirelessCrafting = true;
}
if (this.originalGui != null && myIcon != null) {
this.buttonList.add(this.originalGuiBtn = new GuiTabButton(this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender));
}
if (this.isWirelessCrafting && myIcon != null) {
this.buttonList.add(this.originalGuiBtn = new GuiTabButton(this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender));
}
this.amountToCraft = new GuiNumberBox(this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT, Integer.class);
this.amountToCraft.setEnableBackgroundDrawing(false);
this.amountToCraft.setMaxStringLength(16);
this.amountToCraft.setTextColor(0xFFFFFF);
this.amountToCraft.setVisible(true);
this.amountToCraft.setFocused(true);
this.amountToCraft.setText("1");
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRendererObj.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 4210752);
}
@Override
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.start.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
this.bindTexture("guis/craftAmt.png");
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
try {
Long.parseLong(this.amountToCraft.getText());
this.start.enabled = this.amountToCraft.getText().length() > 0;
} catch (final NumberFormatException e) {
this.start.enabled = false;
}
if (tracker.getRequireStacks().isEmpty()) {
this.start.enabled = false;
}
this.amountToCraft.drawTextBox();
}
@Override
public void drawScreen(int mouseX, int mouseY, float btn) {
super.drawScreen(mouseX, mouseY, btn);
if (start.func_146115_a() && !start.enabled && start.visible && tracker.getRequireStacks().isEmpty()) {
//drawHoveringText
this.func_146283_a(Collections.singletonList(I18n.format("gui.neenergistics.button.without")), mouseX, mouseY);
}
}
@Override
protected void keyTyped(final char character, final int key) {
if (!this.checkHotbarKeys(key)) {
if (key == 28) {
this.actionPerformed(this.start);
}
if ((key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit(character)) && this.amountToCraft.textboxKeyTyped(character, key)) {
try {
String out = this.amountToCraft.getText();
boolean fixed = false;
while (out.startsWith("0") && out.length() > 1) {
out = out.substring(1);
fixed = true;
}
if (fixed) {
this.amountToCraft.setText(out);
}
if (out.isEmpty()) {
out = "0";
}
final long result = Long.parseLong(out);
if (result < 0) {
this.amountToCraft.setText("1");
}
} catch (final NumberFormatException e) {
// :P
}
} else {
super.keyTyped(character, key);
}
}
}
@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);
try {
if (btn == this.originalGuiBtn) {
if (!this.isWirelessCrafting) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui));
} else if (Loader.isModLoaded(ModIDs.WCT)) {
openWirelessCraftingGui();
}
}
if (btn == this.start) {
int craftingAmount = Integer.parseInt(amountToCraft.getText());
tracker.setCraftingAmount(craftingAmount);
tracker.calculateIngredients();
if (!tracker.getRequireStacks().isEmpty()) {
IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(0));
noPreview = isShiftKeyDown();
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
stackIndex = 1;
}
}
} catch (final NumberFormatException e) {
// nope..
this.amountToCraft.setText("1");
}
final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
if (isPlus || isMinus) {
this.addQty(this.getQty(btn));
}
}
private void addQty(final int i) {
try {
String out = this.amountToCraft.getText();
boolean fixed = false;
while (out.startsWith("0") && out.length() > 1) {
out = out.substring(1);
fixed = true;
}
if (fixed) {
this.amountToCraft.setText(out);
}
if (out.isEmpty()) {
out = "0";
}
long result = Integer.parseInt(out);
if (result == 1 && i > 1) {
result = 0;
}
result += i;
if (result < 1) {
result = 1;
}
out = Long.toString(result);
Integer.parseInt(out);
this.amountToCraft.setText(out);
} catch (final NumberFormatException e) {
// :P
}
}
protected String getBackground() {
return "guis/craftAmt.png";
}
@Optional.Method(modid = ModIDs.WCT)
private void openWirelessCraftingGui() {
net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler.instance.sendToServer(new net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis(Reference.GUI_WCT));
}
}
@@ -0,0 +1,124 @@
package com.github.vfyjxf.nee.gui;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.storage.ITerminalHost;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.parts.reporting.PartCraftingTerminal;
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
import com.github.vfyjxf.nee.utils.ModIDs;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
import javax.annotation.Nullable;
import static com.github.vfyjxf.nee.NotEnoughEnergistics.instance;
public class NEEGuiHandler implements IGuiHandler {
public static final int CRAFTING_AMOUNT_ID = 0;
public static final int CRAFTING_AMOUNT_WIRELESS_ID = 1;
@Nullable
@Override
public Object getServerGuiElement(int ordinal, EntityPlayer player, World world, int x, int y, int z) {
final int guiId = ordinal >> 4;
if (guiId != CRAFTING_AMOUNT_WIRELESS_ID) {
final ForgeDirection side = ForgeDirection.getOrientation(ordinal & 7);
if (side != ForgeDirection.UNKNOWN) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IPartHost) {
IPartHost partHost = (IPartHost) tile;
IPart part = partHost.getPart(side);
if (guiId == CRAFTING_AMOUNT_ID) {
if (part instanceof PartCraftingTerminal) {
return updateGui(new ContainerCraftingAmount(player.inventory, part), world, x, y, z, side, part);
}
}
}
}
} else if (Loader.isModLoaded(ModIDs.WCT)) {
final IPortableCell wirelessTerminal = getWirelessTerminalGui(player, world, x, y, z);
if (wirelessTerminal != null) {
return new ContainerCraftingAmount(player.inventory, wirelessTerminal);
}
}
return null;
}
@Nullable
@Override
public Object getClientGuiElement(int ordinal, EntityPlayer player, World world, int x, int y, int z) {
final int guiId = ordinal >> 4;
if (guiId != CRAFTING_AMOUNT_WIRELESS_ID) {
final ForgeDirection side = ForgeDirection.getOrientation(ordinal & 7);
if (side != ForgeDirection.UNKNOWN) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IPartHost) {
IPartHost partHost = (IPartHost) tile;
IPart part = partHost.getPart(side);
if (guiId == CRAFTING_AMOUNT_ID) {
if (part instanceof PartCraftingTerminal) {
return updateGui(new GuiCraftingAmount(player.inventory, (ITerminalHost) part), world, x, y, z, side, part);
}
}
}
}
} else if (Loader.isModLoaded(ModIDs.WCT)) {
final IPortableCell wirelessTerminal = getWirelessTerminalGui(player, world, x, y, z);
if (wirelessTerminal != null) {
return new GuiCraftingAmount(player.inventory, wirelessTerminal);
}
}
return null;
}
private Object updateGui(Object newContainer, final World w, final int x, final int y, final int z, final ForgeDirection side, final IPart part) {
if (newContainer instanceof AEBaseContainer) {
final AEBaseContainer bc = (AEBaseContainer) newContainer;
bc.setOpenContext(new ContainerOpenContext(part));
bc.getOpenContext().setWorld(w);
bc.getOpenContext().setX(x);
bc.getOpenContext().setY(y);
bc.getOpenContext().setZ(z);
bc.getOpenContext().setSide(side);
}
return newContainer;
}
public static void openGui(EntityPlayer player, int ID, TileEntity tile, ForgeDirection side) {
int x = tile.xCoord;
int y = tile.yCoord;
int z = tile.zCoord;
player.openGui(instance, ID << 4 | (side.ordinal()), tile.getWorldObj(), x, y, z);
}
public static void openGui(EntityPlayer player, int ID, World world) {
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
player.openGui(instance, (ID << 4), world, x, y, z);
}
@Optional.Method(modid = "ae2wct")
private WirelessTerminalGuiObject getWirelessTerminalGui(EntityPlayer player, World world, int x, int y, int z) {
final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) AEApi.instance().registries().wireless().getWirelessTerminalHandler(RandomUtils.getWirelessTerm(player.inventory));
if (wh != null) {
return new WirelessTerminalGuiObject(wh, RandomUtils.getWirelessTerm(player.inventory), player, world, x, y, z);
}
return null;
}
}
@@ -17,7 +17,6 @@ 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 net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.HashMap;
@@ -29,9 +28,18 @@ import java.util.Map;
*/
public class NEECraftingHandler implements IOverlayHandler {
public static final String INPUT_KEY = "input";
public static final String OUTPUT_KEY = "Outputs";
public static Map<String, PositionedStack> ingredients = new HashMap<>();
public static final NEECraftingHandler INSTANCE = new NEECraftingHandler();
public static boolean isCraftingTableRecipe(IRecipeHandler recipe) {
TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe;
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
}
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
if (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) {
@@ -102,12 +110,12 @@ public class NEECraftingHandler implements IOverlayHandler {
}
//Fix ItemStack with wrong meta
if (currentStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
if (currentStack.getItemDamage() == 32767) {
currentStack.setItemDamage(0);
}
recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
NEECraftingHandler.ingredients.put("input" + inputIndex, positionedStack);
NEECraftingHandler.ingredients.put(INPUT_KEY + inputIndex, positionedStack);
inputIndex++;
}
@@ -118,7 +126,7 @@ public class NEECraftingHandler implements IOverlayHandler {
ItemStack outputStack = positionedStack.item.copy();
//Fix ItemStack with wrong meta(maybe ?)
if (outputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
if (outputStack.getItemDamage() == 32767) {
outputStack.setItemDamage(0);
}
@@ -155,12 +163,12 @@ public class NEECraftingHandler implements IOverlayHandler {
}
//Fix ItemStack with wrong meta
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
if (stack.getItemDamage() == 32767) {
stack.setItemDamage(0);
}
recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound()));
NEECraftingHandler.ingredients.put("input" + slotIndex, positionedStack);
NEECraftingHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack);
}
}
return new PacketNEIPatternRecipe(recipeInputs, null);
@@ -271,10 +279,4 @@ public class NEECraftingHandler implements IOverlayHandler {
}
}
public static boolean isCraftingTableRecipe(IRecipeHandler recipe) {
TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe;
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
}
}
@@ -1,5 +1,6 @@
package com.github.vfyjxf.nee.nei;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.slot.SlotCraftingMatrix;
@@ -9,6 +10,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIRecipe;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
@@ -18,7 +20,8 @@ import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingHelper;
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.IngredientTracker;
import cpw.mods.fml.common.Optional;
@@ -48,21 +51,29 @@ import java.util.List;
public class NEECraftingHelper implements IOverlayHandler {
public static final NEECraftingHelper INSTANCE = new NEECraftingHelper();
public static IngredientTracker tracker = null;
public static int stackIndex = 1;
public static boolean noPreview = false;
public static final NEECraftingHelper INSTANCE = new NEECraftingHelper();
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
boolean isCraftingGuiTerm = firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui);
if (isCraftingGuiTerm && NEECraftingHandler.isCraftingTableRecipe(recipe)) {
tracker = createTracker(firstGui, recipe, recipeIndex);
tracker = new IngredientTracker(firstGui, recipe, recipeIndex);
boolean doCraftingHelp = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview")) || Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"));
noPreview = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"));
if (doCraftingHelp && !tracker.getRequireToCraftStacks().isEmpty()) {
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(0), noPreview));
if (doCraftingHelp) {
if (noPreview) {
if (!tracker.getRequireStacks().isEmpty()) {
IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(0));
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
} else {
moveItem(firstGui, recipe, recipeIndex);
}
} else if (NEEConfig.enableCraftAmountSettingGui) {
NEENetworkHandler.getInstance().sendToServer(new PacketOpenCraftAmount(recipe.getResultStack(recipeIndex).item));
}
stackIndex = 1;
} else {
moveItem(firstGui, recipe, recipeIndex);
@@ -70,21 +81,6 @@ public class NEECraftingHelper implements IOverlayHandler {
}
}
@SuppressWarnings("unchecked")
private IngredientTracker createTracker(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
IngredientTracker tracker = new IngredientTracker(firstGui, recipe, recipeIndex);
//check stacks in player's inventory and crafting grid
for (Slot slot : (List<Slot>) firstGui.inventorySlots.inventorySlots) {
boolean canGetStack = slot != null && slot.getHasStack() && slot.getStack().stackSize > 0 && slot.isItemValid(slot.getStack()) && slot.canTakeStack(Minecraft.getMinecraft().thePlayer);
if (canGetStack) {
tracker.addAvailableStack(slot.getStack());
}
}
return tracker;
}
/**
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
*/
@@ -214,8 +210,8 @@ public class NEECraftingHelper implements IOverlayHandler {
}
if (!isGtnhNei) {
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class,guiRecipe,"overlay2");
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
@@ -8,18 +8,25 @@ import cpw.mods.fml.relauncher.Side;
public class NEENetworkHandler {
private static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(NotEnoughEnergistics.MODID);
private static int packId = 0;
private static int nextId() {
return packId++;
}
public static SimpleNetworkWrapper getInstance() {
return INSTANCE;
}
public static void init() {
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);
INSTANCE.registerMessage(PacketStackCountChange.class, PacketStackCountChange.class, 3, Side.SERVER);
INSTANCE.registerMessage(PacketSlotStackChange.class, PacketSlotStackChange.class, 4, Side.SERVER);
INSTANCE.registerMessage(PacketCraftingHelper.class, PacketCraftingHelper.class, 5, Side.SERVER);
INSTANCE.registerMessage(PacketNEIPatternRecipe.class, PacketNEIPatternRecipe.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketArcaneRecipe.class, PacketArcaneRecipe.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketExtremeRecipe.class, PacketExtremeRecipe.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketStackCountChange.class, PacketStackCountChange.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketSlotStackChange.class, PacketSlotStackChange.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketCraftingRequest.class, PacketCraftingRequest.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketOpenCraftAmount.class, PacketOpenCraftAmount.class, nextId(), Side.SERVER);
INSTANCE.registerMessage(PacketOpenGui.class, PacketOpenGui.class, nextId(), Side.SERVER);
}
}
@@ -22,7 +22,8 @@ public class PacketArcaneRecipe implements IMessage, IMessageHandler<PacketArcan
NBTTagCompound input;
public PacketArcaneRecipe() {}
public PacketArcaneRecipe() {
}
public PacketArcaneRecipe(NBTTagCompound input) {
this.input = input;
@@ -1,142 +0,0 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.core.AELog;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.github.vfyjxf.nee.utils.GuiUtils;
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 io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
import java.util.concurrent.Future;
public class PacketCraftingHelper implements IMessage, IMessageHandler<PacketCraftingHelper, IMessage> {
private ItemStack requireToCraftStack;
private boolean noPreview;
public PacketCraftingHelper() {
}
public PacketCraftingHelper(ItemStack requireToCraftStack, boolean noPreview) {
this.requireToCraftStack = requireToCraftStack;
this.noPreview = noPreview;
}
public ItemStack getRequireToCraftStack() {
return requireToCraftStack;
}
public boolean isNoPreview() {
return noPreview;
}
@Override
public void fromBytes(ByteBuf buf) {
this.requireToCraftStack = ByteBufUtils.readItemStack(buf);
this.noPreview = buf.readBoolean();
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeItemStack(buf, this.requireToCraftStack);
buf.writeBoolean(this.noPreview);
}
@Override
public IMessage onMessage(PacketCraftingHelper message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof AEBaseContainer) {
AEBaseContainer baseContainer = (AEBaseContainer) container;
Object target = baseContainer.getTarget();
if (target instanceof IGridHost) {
IGridHost gh = (IGridHost) target;
IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
if (gn != null) {
IGrid grid = gn.getGrid();
if (grid != null && message.getRequireToCraftStack() != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
IAEItemStack result = AEItemStack.create(message.getRequireToCraftStack());
futureJob = cg.beginCraftingJob(player.worldObj, grid, baseContainer.getActionSource(), result, null);
final ContainerOpenContext context = baseContainer.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
Platform.openGUI(player, te, baseContainer.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
if (player.openContainer instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setJob(futureJob);
ccc.setAutoStart(message.isNoPreview());
}
}
} catch (final Throwable e) {
if (futureJob != null) {
futureJob.cancel(true);
}
AELog.debug(e);
}
}
}
}
} else if (GuiUtils.isWirelessCraftingTermContainer(container)) {
ContainerWirelessCraftingTerminal cwt = (ContainerWirelessCraftingTerminal) container;
Object target = cwt.getTarget();
if (target instanceof WirelessTerminalGuiObject) {
IGrid grid = ((WirelessTerminalGuiObject) target).getTargetGrid();
if (grid != null && message.getRequireToCraftStack() != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
IAEItemStack result = AEItemStack.create(message.getRequireToCraftStack());
futureJob = cg.beginCraftingJob(player.worldObj, grid, cwt.getActionSource(), result, null);
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z);
if (player.openContainer instanceof net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) {
final net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm ccc = (net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) player.openContainer;
ccc.setJob(futureJob);
ccc.setAutoStart(message.isNoPreview());
}
} catch (final Throwable e) {
if (futureJob != null) {
futureJob.cancel(true);
}
AELog.debug(e);
}
}
}
}
return null;
}
}
@@ -0,0 +1,234 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.security.IActionHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.core.AELog;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.ModIDs;
import cpw.mods.fml.common.Loader;
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 io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
import java.io.IOException;
import java.util.concurrent.Future;
public class PacketCraftingRequest implements IMessage, IMessageHandler<PacketCraftingRequest, IMessage> {
private IAEItemStack requireToCraftStack;
private boolean noPreview;
private int craftAmount;
public PacketCraftingRequest() {
}
public PacketCraftingRequest(IAEItemStack requireToCraftStack, boolean noPreview) {
this.requireToCraftStack = requireToCraftStack;
this.noPreview = noPreview;
}
public PacketCraftingRequest(int craftAmount, boolean noPreview) {
this.craftAmount = craftAmount;
this.noPreview = noPreview;
}
public IAEItemStack getRequireToCraftStack() {
return requireToCraftStack;
}
public boolean isNoPreview() {
return noPreview;
}
public int getCraftAmount() {
return craftAmount;
}
@Override
public void fromBytes(ByteBuf buf) {
if (buf.readBoolean()) {
try {
this.requireToCraftStack = AEItemStack.loadItemStackFromPacket(buf);
} catch (IOException e) {
e.printStackTrace();
}
}
this.noPreview = buf.readBoolean();
this.craftAmount = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
if (this.requireToCraftStack != null) {
try {
buf.writeBoolean(true);
this.requireToCraftStack.writeToPacket(buf);
} catch (IOException e) {
e.printStackTrace();
}
} else {
buf.writeBoolean(false);
}
buf.writeBoolean(this.noPreview);
buf.writeInt(this.craftAmount);
}
@Override
public IMessage onMessage(PacketCraftingRequest message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof AEBaseContainer) {
AEBaseContainer baseContainer = (AEBaseContainer) container;
Object target = baseContainer.getTarget();
if (container instanceof ContainerCraftingTerm) {
handlerCraftingTermRequest((ContainerCraftingTerm) container, message, target, player);
}
if (container instanceof ContainerCraftingAmount) {
handlerCraftingAmountRequest((ContainerCraftingAmount) container, message, target, player);
}
} else if (GuiUtils.isWirelessCraftingTermContainer(container)) {
handlerWirelessCraftingRequest((ContainerWirelessCraftingTerminal) container, message, player);
}
return null;
}
private void handlerCraftingTermRequest(ContainerCraftingTerm container, PacketCraftingRequest message, Object target, EntityPlayerMP player) {
if (target instanceof IGridHost) {
IGridHost gh = (IGridHost) target;
IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
if (gn != null) {
IGrid grid = gn.getGrid();
if (grid != null && message.getRequireToCraftStack() != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), message.getRequireToCraftStack(), null);
final ContainerOpenContext context = container.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
Platform.openGUI(player, te, container.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
if (player.openContainer instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setJob(futureJob);
ccc.setAutoStart(message.isNoPreview());
}
}
} catch (final Throwable e) {
if (futureJob != null) {
futureJob.cancel(true);
}
AELog.debug(e);
}
}
}
}
}
private void handlerCraftingAmountRequest(ContainerCraftingAmount container, PacketCraftingRequest message, Object target, EntityPlayerMP player) {
if (target instanceof IActionHost) {
IActionHost ah = (IActionHost) target;
IGridNode gn = ah.getActionableNode();
IGrid grid = gn.getGrid();
ItemStack resultStack = container.getResultStack();
IAEItemStack result = message.getRequireToCraftStack();
if (resultStack != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), result, null);
final ContainerOpenContext context = container.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
Platform.openGUI(player, te, context.getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
if (player.openContainer instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setAutoStart(message.isNoPreview());
ccc.setJob(futureJob);
ccc.detectAndSendChanges();
}
} else if (Loader.isModLoaded(ModIDs.WCT)) {
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z);
if (player.openContainer instanceof net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) {
final net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm ccc = (net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) player.openContainer;
ccc.setJob(futureJob);
ccc.setAutoStart(message.isNoPreview());
}
}
} catch (final Throwable e) {
if (futureJob != null) {
futureJob.cancel(true);
}
AELog.debug(e);
}
}
}
}
private void handlerWirelessCraftingRequest(ContainerWirelessCraftingTerminal container, PacketCraftingRequest message, EntityPlayerMP player) {
Object target = container.getTarget();
if (target instanceof WirelessTerminalGuiObject) {
IGrid grid = ((WirelessTerminalGuiObject) target).getTargetGrid();
if (grid != null && message.getRequireToCraftStack() != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), message.getRequireToCraftStack(), null);
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z);
if (player.openContainer instanceof net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) {
final net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm ccc = (net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) player.openContainer;
ccc.setJob(futureJob);
ccc.setAutoStart(message.isNoPreview());
}
} catch (final Throwable e) {
if (futureJob != null) {
futureJob.cancel(true);
}
AELog.debug(e);
}
}
}
}
}
@@ -28,7 +28,8 @@ 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;
@@ -65,9 +66,9 @@ public class PacketNEIPatternRecipe implements IMessage, IMessageHandler<PacketN
} else if (container instanceof ContainerPatternTerm) {
((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(false);
message.processRecipeHandler((ContainerPatternTerm) container, message);
} else if (container instanceof ContainerPatternTermEx && message.output != null){
} else if (container instanceof ContainerPatternTermEx && message.output != null) {
((ContainerPatternTermEx) container).getPatternTerminal().setInverted(false);
message.processRecipeHandler((ContainerPatternTermEx) container,message);
message.processRecipeHandler((ContainerPatternTermEx) container, message);
}
return null;
}
@@ -0,0 +1,79 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftingTerm;
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
import com.github.vfyjxf.nee.gui.NEEGuiHandler;
import com.github.vfyjxf.nee.utils.GuiUtils;
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 io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import static com.github.vfyjxf.nee.gui.NEEGuiHandler.CRAFTING_AMOUNT_ID;
import static com.github.vfyjxf.nee.gui.NEEGuiHandler.CRAFTING_AMOUNT_WIRELESS_ID;
public class PacketOpenCraftAmount implements IMessage, IMessageHandler<PacketOpenCraftAmount, IMessage> {
private ItemStack resultStack;
public PacketOpenCraftAmount() {
}
public PacketOpenCraftAmount(ItemStack resultStack) {
this.resultStack = resultStack;
}
@Override
public void fromBytes(ByteBuf buf) {
this.resultStack = ByteBufUtils.readItemStack(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeItemStack(buf, this.resultStack);
}
@Override
public IMessage onMessage(PacketOpenCraftAmount message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof ContainerCraftingTerm) {
final ContainerOpenContext context = ((ContainerCraftingTerm) container).getOpenContext();
if (context != null) {
final TileEntity tile = context.getTile();
NEEGuiHandler.openGui(player, CRAFTING_AMOUNT_ID, tile, context.getSide());
if (player.openContainer instanceof ContainerCraftingAmount) {
ContainerCraftingAmount cca = (ContainerCraftingAmount) player.openContainer;
if (message.resultStack != null) {
cca.setResultStack(message.resultStack);
cca.getResultSlot().putStack(message.resultStack);
}
cca.detectAndSendChanges();
}
}
} else if (GuiUtils.isWirelessCraftingTermContainer(container)) {
NEEGuiHandler.openGui(player, CRAFTING_AMOUNT_WIRELESS_ID, player.worldObj);
if (player.openContainer instanceof ContainerCraftingAmount) {
ContainerCraftingAmount cca = (ContainerCraftingAmount) player.openContainer;
if (message.resultStack != null) {
cca.setResultStack(message.resultStack);
cca.getResultSlot().putStack(message.resultStack);
}
cca.detectAndSendChanges();
}
}
return null;
}
}
@@ -0,0 +1,50 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import com.github.vfyjxf.nee.gui.NEEGuiHandler;
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 io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
public class PacketOpenGui implements IMessage, IMessageHandler<PacketOpenGui, IMessage> {
private int guiId;
public PacketOpenGui() {
}
public PacketOpenGui(int guiId) {
this.guiId = guiId;
}
@Override
public void fromBytes(ByteBuf buf) {
this.guiId = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.guiId);
}
@Override
public IMessage onMessage(PacketOpenGui message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof AEBaseContainer) {
final ContainerOpenContext context = ((AEBaseContainer) container).getOpenContext();
if (context != null) {
final TileEntity tile = context.getTile();
NEEGuiHandler.openGui(player, message.guiId, tile, context.getSide());
}
}
return null;
}
}
@@ -19,14 +19,6 @@ public class PacketStackCountChange implements IMessage, IMessageHandler<PacketS
private int slotIndex;
private int changeCount;
public int getSlotIndex() {
return slotIndex;
}
public int getChangeCount() {
return changeCount;
}
public PacketStackCountChange() {
}
@@ -36,6 +28,14 @@ public class PacketStackCountChange implements IMessage, IMessageHandler<PacketS
this.changeCount = changeCount;
}
public int getSlotIndex() {
return slotIndex;
}
public int getChangeCount() {
return changeCount;
}
@Override
public void fromBytes(ByteBuf buf) {
this.slotIndex = buf.readInt();
@@ -0,0 +1,43 @@
package com.github.vfyjxf.nee.processor;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import javax.annotation.Nonnull;
import java.util.*;
public class AppengRecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
return new HashSet<>(Arrays.asList(
"inscriber", "grindstone"
));
}
@Nonnull
@Override
public String getRecipeProcessorId() {
return "appliedenergistics2";
}
@Nonnull
@Override
public List<PositionedStack> getRecipeInput(IRecipeHandler recipe, int recipeIndex, String identifier) {
List<PositionedStack> recipeInputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeInputs.addAll(recipe.getIngredientStacks(recipeIndex));
}
return recipeInputs;
}
@Nonnull
@Override
public List<PositionedStack> getRecipeOutput(IRecipeHandler recipe, int recipeIndex, String identifier) {
List<PositionedStack> recipeOutputs = new ArrayList<>();
if (this.getAllOverlayIdentifier().contains(identifier)) {
recipeOutputs.add(recipe.getResultStack(recipeIndex));
}
return recipeOutputs;
}
}
@@ -36,6 +36,24 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor {
gtAssLineClz = gtAL;
}
/**
* For resolving NoSuchMethodError
* Copied from GTNewHorizons/GT5-Unofficial.
*/
public static FluidStack getFluidFromDisplayStack(ItemStack aDisplayStack) {
if (!isStackValid(aDisplayStack) ||
aDisplayStack.getItem() != ItemList.Display_Fluid.getItem() ||
!aDisplayStack.hasTagCompound()) {
return null;
}
Fluid tFluid = FluidRegistry.getFluid(ItemList.Display_Fluid.getItem().getDamage(aDisplayStack));
return new FluidStack(tFluid, (int) aDisplayStack.getTagCompound().getLong("mFluidDisplayAmount"));
}
public static boolean isStackValid(Object aStack) {
return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null && ((ItemStack) aStack).stackSize >= 0;
}
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
@@ -88,22 +106,4 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor {
return recipeOutputs;
}
/**
* For resolving NoSuchMethodError
* Copied from GTNewHorizons/GT5-Unofficial.
*/
public static FluidStack getFluidFromDisplayStack(ItemStack aDisplayStack) {
if (!isStackValid(aDisplayStack) ||
aDisplayStack.getItem() != ItemList.Display_Fluid.getItem() ||
!aDisplayStack.hasTagCompound()) {
return null;
}
Fluid tFluid = FluidRegistry.getFluid(ItemList.Display_Fluid.getItem().getDamage(aDisplayStack));
return new FluidStack(tFluid, (int) aDisplayStack.getTagCompound().getLong("mFluidDisplayAmount"));
}
public static boolean isStackValid(Object aStack) {
return (aStack instanceof ItemStack) && ((ItemStack) aStack).getItem() != null && ((ItemStack) aStack).stackSize >= 0;
}
}
@@ -14,7 +14,7 @@ import java.util.Set;
public interface IRecipeProcessor {
@Nonnull
default Set<String> getAllOverlayIdentifier(){
default Set<String> getAllOverlayIdentifier() {
return Collections.emptySet();
}
@@ -14,6 +14,12 @@ public class RecipeProcessor {
NotEnoughEnergistics.logger.info("Install Vanilla Support");
recipeProcessors.add(new VanillaRecipeProcessor());
if (Loader.isModLoaded("appliedenergistics2")) {
NotEnoughEnergistics.logger.info("Found Applied Energistics 2,install Applied Energistics 2 support");
recipeProcessors.add(new AppengRecipeProcessor());
}
if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi")) {
NotEnoughEnergistics.logger.info("Found GregTech5,install GregTech5 support");
recipeProcessors.add(new GregTech5RecipeProcessor());
@@ -67,9 +73,6 @@ public class RecipeProcessor {
recipeProcessors.add(new GTPPRecipeProcessor());
}
if (Loader.isModLoaded("appliedenergistics2")) {
NotEnoughEnergistics.logger.info("Applied Energistics 2 will not be supported");
}
NotEnoughEnergistics.logger.info("-----Not Enough Energistics Init Finished-----");
}
@@ -2,7 +2,7 @@ package com.github.vfyjxf.nee.proxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
public class ServerProxy extends CommonProxy{
public class ServerProxy extends CommonProxy {
@Override
public void init(FMLInitializationEvent event) {
// NO-OP
@@ -83,4 +83,13 @@ public class GuiUtils {
}
}
public static boolean isWirelessTerminalGuiObject(Object guiObj) {
try {
Class<?> wirelessTerminalGuiObjClass = Class.forName("net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject");
return wirelessTerminalGuiObjClass.isInstance(guiObj);
} catch (ClassNotFoundException e) {
return false;
}
}
}
@@ -5,46 +5,64 @@ import net.minecraft.item.ItemStack;
public class Ingredient {
private PositionedStack ingredients;
private long requireCount;
private final long defaultRequireCount;
private final PositionedStack ingredient;
private ItemStack craftableIngredient;
private final long requireCount;
private long currentCount = 0;
public Ingredient(PositionedStack ingredients) {
this.ingredients = ingredients;
this.ingredient = ingredients;
this.requireCount = ingredients.items[0].stackSize;
this.defaultRequireCount = ingredients.items[0].stackSize;
}
public void setCraftableIngredient(ItemStack craftableIngredient) {
this.craftableIngredient = craftableIngredient;
}
public PositionedStack getIngredients() {
return ingredients;
public PositionedStack getIngredient() {
return ingredient;
}
public ItemStack getCraftableIngredient() {
return craftableIngredient;
}
public long getMissingCount(){
public void setCraftableIngredient(ItemStack craftableIngredient) {
this.craftableIngredient = craftableIngredient;
}
public long getMissingCount() {
return requireCount - currentCount;
}
public long getDefaultRequireCount() {
return defaultRequireCount;
}
public long getRequireCount() {
return requireCount;
}
public boolean isCraftable(){
public void setRequireCount(long requireCount) {
this.requireCount = requireCount;
}
public void setCurrentCount(long currentCount) {
this.currentCount = currentCount;
}
public boolean isCraftable() {
return this.craftableIngredient != null;
}
public boolean requiresToCraft(){
public boolean requiresToCraft() {
return this.getMissingCount() > 0;
}
public void addCurrentCount(long count){
currentCount += count;
public void addCount(long count) {
if (currentCount + count < requireCount) {
currentCount += count;
} else {
currentCount = requireCount;
}
}
}
@@ -8,7 +8,9 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.config.NEEConfig;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
@@ -18,109 +20,56 @@ import java.util.List;
public class IngredientTracker {
private final List<Ingredient> ingredients = new ArrayList<>();
private int craftingAmount = 1;
private final GuiContainer termGui;
private List<ItemStack> requireStacks;
public IngredientTracker(GuiContainer gui, IRecipeHandler recipe, int recipeIndex) {
List<IAEItemStack> craftableStacks = getCraftableStacks(gui);
List<PositionedStack> requiredIngredients = new ArrayList<>();
for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
boolean find = false;
for (PositionedStack currentIngredient : requiredIngredients) {
boolean areItemStackEquals = currentIngredient.items[0].isItemEqual(positionedStack.items[0]) && ItemStack.areItemStackTagsEqual(currentIngredient.items[0], positionedStack.items[0]);
if (areItemStackEquals) {
currentIngredient.items[0].stackSize += positionedStack.items[0].stackSize;
find = true;
}
}
/**
* For NEECraftingHelper
*/
public IngredientTracker(GuiContainer termGui, IRecipeHandler recipe, int recipeIndex) {
this.termGui = termGui;
if (!find) {
requiredIngredients.add(positionedStack);
}
}
for (PositionedStack requiredIngredient : requiredIngredients) {
for (PositionedStack requiredIngredient : recipe.getIngredientStacks(recipeIndex)) {
Ingredient ingredient = new Ingredient(requiredIngredient);
ingredients.add(ingredient);
for (IAEItemStack stack : NEEConfig.matchOtherItems ? this.getStorageStacks(gui) : craftableStacks) {
if (requiredIngredient.contains(stack.getItemStack())) {
if (stack.isCraftable()) {
ingredient.setCraftableIngredient(stack.getItemStack());
}
ingredient.addCurrentCount(stack.getItemStack().stackSize);
}
}
}
}
public IngredientTracker(GuiContainer gui, List<PositionedStack> requiredIngredients) {
for (PositionedStack positionedStack : requiredIngredients) {
this.ingredients.add(new Ingredient(positionedStack));
}
List<IAEItemStack> craftableStacks = this.getCraftableStacks(gui);
//set craftable stack
for (Ingredient ingredient : this.ingredients) {
for (IAEItemStack stack : craftableStacks) {
if (ingredient.getIngredients().contains(stack.getItemStack())) {
if (!ingredient.isCraftable()) {
ingredient.setCraftableIngredient(stack.getItemStack());
}
if (stack.getStackSize() > 0) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.getStackSize());
if (ingredient.requiresToCraft()) {
stack.setStackSize(0);
} else {
stack.setStackSize(stack.getStackSize() - missingCount);
}
}
}
}
}
if (NEEConfig.matchOtherItems) {
List<IAEItemStack> otherStacks = this.getStorageStacks(gui);
otherStacks.removeAll(craftableStacks);
for (Ingredient ingredient : this.ingredients) {
for (IAEItemStack stack : otherStacks) {
if (ingredient.requiresToCraft() && ingredient.getIngredients().contains(stack.getItemStack())) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.getStackSize());
if (ingredient.requiresToCraft()) {
stack.setStackSize(0);
} else {
stack.setStackSize(stack.getStackSize() - missingCount);
}
}
for (IAEItemStack stack : getCraftableStacks()) {
if (ingredient.getIngredient().contains(stack.getItemStack())) {
ingredient.setCraftableIngredient(stack.getItemStack());
}
}
}
this.calculateIngredients();
}
@SuppressWarnings("unchecked")
private List<IAEItemStack> getCraftableStacks(GuiContainer gui) {
private List<IAEItemStack> getCraftableStacks() {
List<IAEItemStack> craftableStacks = new ArrayList<>();
IItemList<IAEItemStack> list = null;
try {
if (!GuiUtils.isGuiWirelessCrafting(gui)) {
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(gui);
list = (IItemList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "list").get(repo);
} else {
//wireless crafting terminal support
net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo repo = (net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo) ReflectionHelper.findField(GuiWirelessCraftingTerminal.class, "repo").get(gui);
list = (IItemList<IAEItemStack>) ReflectionHelper.findField(net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo.class,
"list").get(repo);
if (termGui != null) {
IItemList<IAEItemStack> list = null;
try {
if (!GuiUtils.isGuiWirelessCrafting(termGui)) {
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(termGui);
list = (IItemList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "list").get(repo);
} else {
//wireless crafting terminal support
net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo repo = (net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo) ReflectionHelper.findField(GuiWirelessCraftingTerminal.class, "repo").get(termGui);
list = (IItemList<IAEItemStack>) ReflectionHelper.findField(net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo.class,
"list").get(repo);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (list != null) {
for (IAEItemStack stack : list) {
if (stack.isCraftable()) {
craftableStacks.add(stack.copy());
if (list != null) {
for (IAEItemStack stack : list) {
if (stack.isCraftable()) {
craftableStacks.add(stack.copy());
}
}
}
}
@@ -128,24 +77,26 @@ public class IngredientTracker {
}
@SuppressWarnings("unchecked")
private List<IAEItemStack> getStorageStacks(GuiContainer gui) {
private List<IAEItemStack> getStorageStacks() {
List<IAEItemStack> list = new ArrayList<>();
try {
if (!GuiUtils.isGuiWirelessCrafting(gui)) {
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(gui);
for (IAEItemStack stack : (IItemList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "list").get(repo)) {
list.add(stack.copy());
}
} else {
//wireless crafting terminal support
net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo repo = (net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo) ReflectionHelper.findField(GuiWirelessCraftingTerminal.class, "repo").get(gui);
for (IAEItemStack stack : (IItemList<IAEItemStack>) ReflectionHelper.findField(net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo.class,
"list").get(repo)) {
list.add(stack.copy());
if (termGui != null) {
try {
if (!GuiUtils.isGuiWirelessCrafting(termGui)) {
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(termGui);
for (IAEItemStack stack : (IItemList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "list").get(repo)) {
list.add(stack.copy());
}
} else {
//wireless crafting terminal support
net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo repo = (net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo) ReflectionHelper.findField(GuiWirelessCraftingTerminal.class, "repo").get(termGui);
for (IAEItemStack stack : (IItemList<IAEItemStack>) ReflectionHelper.findField(net.p455w0rd.wirelesscraftingterminal.client.me.ItemRepo.class,
"list").get(repo)) {
list.add(stack.copy());
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return list;
}
@@ -156,24 +107,70 @@ public class IngredientTracker {
public List<ItemStack> getRequireToCraftStacks() {
List<ItemStack> requireToCraftStacks = new ArrayList<>();
for (Ingredient ingredient : this.ingredients) {
ItemStack craftableStack = ingredient.getCraftableIngredient();
if (craftableStack != null && ingredient.requiresToCraft()) {
ItemStack requireStack = craftableStack.copy();
requireStack.stackSize = (int) ingredient.getMissingCount();
requireToCraftStacks.add(requireStack);
if (NEEConfig.enableCraftAmountSettingGui) {
for (Ingredient ingredient : this.getIngredients()) {
boolean find = false;
if (ingredient.isCraftable()) {
for (ItemStack stack : requireToCraftStacks) {
boolean areStackEqual = stack.isItemEqual(ingredient.getCraftableIngredient()) && ItemStack.areItemStackTagsEqual(stack, ingredient.getCraftableIngredient());
if (areStackEqual) {
stack.stackSize += ingredient.getRequireCount();
find = true;
break;
}
}
if (!find) {
ItemStack requireStack = ingredient.getCraftableIngredient().copy();
requireStack.stackSize = ((int) ingredient.getRequireCount());
requireToCraftStacks.add(requireStack);
}
}
}
} else {
for (Ingredient ingredient : this.getIngredients()) {
boolean find = false;
if (ingredient.isCraftable() && ingredient.requiresToCraft()) {
for (ItemStack stack : requireToCraftStacks) {
boolean areStackEqual = stack.isItemEqual(ingredient.getCraftableIngredient()) && ItemStack.areItemStackTagsEqual(stack, ingredient.getCraftableIngredient());
if (areStackEqual) {
stack.stackSize = (int) (stack.stackSize + ingredient.getMissingCount());
find = true;
}
}
if (!find) {
ItemStack requireStack = ingredient.getCraftableIngredient().copy();
requireStack.stackSize = ((int) ingredient.getMissingCount());
requireToCraftStacks.add(requireStack);
}
}
}
}
return requireToCraftStacks;
}
public List<ItemStack> getRequireStacks() {
return requireStacks;
}
public ItemStack getRequiredStack(int index) {
return this.getRequireStacks().get(index);
}
public void setCraftingAmount(int craftingAmount) {
this.craftingAmount = craftingAmount;
}
public void addAvailableStack(ItemStack stack) {
for (Ingredient ingredient : this.ingredients) {
if (ingredient.requiresToCraft()) {
if (NEEConfig.matchOtherItems) {
if (stack.stackSize > 0 && ingredient.getIngredients().contains(stack)) {
if (stack.stackSize > 0 && ingredient.getIngredient().contains(stack)) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.stackSize);
ingredient.addCount(stack.stackSize);
if (ingredient.requiresToCraft()) {
stack.stackSize = 0;
} else {
@@ -185,7 +182,7 @@ public class IngredientTracker {
ItemStack craftableStack = ingredient.getCraftableIngredient();
if (craftableStack != null && craftableStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(craftableStack, stack) && stack.stackSize > 0) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.stackSize);
ingredient.addCount(stack.stackSize);
if (ingredient.requiresToCraft()) {
stack.stackSize = 0;
} else {
@@ -198,4 +195,51 @@ public class IngredientTracker {
}
}
@SuppressWarnings("unchecked")
public void calculateIngredients() {
//set requireCount and reset currentCount
for (Ingredient ingredient : this.getIngredients()) {
ingredient.setRequireCount(ingredient.getDefaultRequireCount() * craftingAmount);
ingredient.setCurrentCount(0);
}
List<IAEItemStack> stacks = NEEConfig.matchOtherItems ? getStorageStacks() : getCraftableStacks();
for (Ingredient ingredient : this.ingredients) {
for (IAEItemStack stack : stacks) {
if (ingredient.getIngredient().contains(stack.getItemStack())) {
if (stack.getStackSize() > 0) {
ingredient.addCount(stack.getStackSize());
if (ingredient.requiresToCraft()) {
stack.setStackSize(0);
} else {
stack.setStackSize(stack.getStackSize() - ingredient.getRequireCount());
}
}
}
}
}
List<ItemStack> inventoryStacks = new ArrayList<>();
for (Slot slot : (List<Slot>) termGui.inventorySlots.inventorySlots) {
boolean canGetStack = slot != null &&
slot.getHasStack() &&
slot.getStack().stackSize > 0 &&
slot.isItemValid(slot.getStack()) &&
slot.canTakeStack(Minecraft.getMinecraft().thePlayer);
if (canGetStack) {
inventoryStacks.add(slot.getStack().copy());
}
}
for (int i = 0; i < getIngredients().size(); i++) {
for (ItemStack stack : inventoryStacks) {
addAvailableStack(stack);
}
}
this.requireStacks = this.getRequireToCraftStacks();
}
}
@@ -0,0 +1,8 @@
package com.github.vfyjxf.nee.utils;
public class ModIDs {
public static final String WCT = "ae2wct";
}
@@ -13,23 +13,25 @@ public class StackProcessor {
public String recipeProcessor;
public String identifier;
public StackProcessor(String modid, String name, String meta, String nbt){
public StackProcessor(String modid, String name, String meta, String nbt) {
this.modid = modid;
this.name = name;
this.meta = meta;
this.nbt = nbt;
}
public StackProcessor(String modid, String name, String meta){
public StackProcessor(String modid, String name, String meta) {
this.modid = modid;
this.name = name;
this.meta = meta;
}
public StackProcessor(String modid, String name){
public StackProcessor(String modid, String name) {
this.modid = modid;
this.name = name;
}
public StackProcessor(ItemStack itemStack, Item item, String recipeProcessor, String identifier){
public StackProcessor(ItemStack itemStack, Item item, String recipeProcessor, String identifier) {
this.itemStack = itemStack;
this.item = item;
this.recipeProcessor = recipeProcessor;