fix crafting terminal

This commit is contained in:
GlodBlock committed 2023-02-05 20:25:23 +08:00
1 parent e8e27d421a
commit 2632a9b1cd
6 files changed
+112 -70

No files matched your search

@@ -346,48 +346,28 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends AEBaseMEGui
if (drawSwitchGuiBtn) drawSwitchGuiBtns();
}
@SuppressWarnings("unchecked")
private void drawSwitchGuiBtns() {
if (!(this instanceof GuiFluidCraftingWireless)) {
this.buttonList.add(
this.CraftingTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.offsetY,
"CRAFT_TEM",
"YES",
false));
this.CraftingTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "CRAFT_TEM", "YES"));
this.offsetY += 20;
}
if (!(this instanceof GuiFluidPatternWireless)) {
this.buttonList.add(
this.PatternTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.offsetY,
"PATTERN_TEM",
"YES",
false));
this.PatternTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "PATTERN_TEM", "YES"));
this.offsetY += 20;
}
if (!(this instanceof GuiFluidPortableCell)) {
this.buttonList.add(
this.FluidTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.offsetY,
"FLUID_TEM",
"YES",
false));
this.buttonList
.add(this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "FLUID_TEM", "YES"));
this.offsetY += 20;
}
if (ModAndClassUtil.ThE && !(this instanceof GuiEssentiaTerminal)) {
this.buttonList.add(
this.EssentiaTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.offsetY,
"ESSENTIA_TEM",
"YES",
false));
this.EssentiaTerminal = new GuiFCImgButton(this.guiLeft - 18, this.offsetY, "ESSENTIA_TEM", "YES"));
this.offsetY += 20;
}
}
public void setSearchString(String memoryText, boolean updateView) {
@@ -0,0 +1,76 @@
package com.glodblock.github.nei;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIRecipe;
import appeng.util.Platform;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.IRecipeHandler;
import com.glodblock.github.client.gui.GuiFluidCraftingWireless;
public class FluidCraftingTransferHandler implements IOverlayHandler {
public static final FluidCraftingTransferHandler INSTANCE = new FluidCraftingTransferHandler();
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
try {
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
if (firstGui instanceof GuiFluidCraftingWireless
&& FluidPatternTerminalRecipeTransferHandler.craftSet.contains(recipe.getOverlayIdentifier())) {
PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients));
NetworkHandler.instance.sendToServer(packet);
}
} catch (final Exception | Error ignored) {
// NO-OP
}
}
private NBTTagCompound packIngredients(GuiContainer gui, List<PositionedStack> ingredients) throws IOException {
final NBTTagCompound recipe = new NBTTagCompound();
for (final PositionedStack positionedStack : ingredients) {
final int col = (positionedStack.relx - 25) / 18;
final int row = (positionedStack.rely - 6) / 18;
if (positionedStack.items != null && positionedStack.items.length > 0) {
for (final Object o : gui.inventorySlots.inventorySlots) {
if (o instanceof SlotCraftingMatrix || o instanceof SlotFakeCraftingMatrix) {
Slot slot = (Slot) o;
if (slot.getSlotIndex() == col + row * 3) {
final NBTTagList tags = new NBTTagList();
final List<ItemStack> list = new LinkedList<ItemStack>();
// prefer pure crystals.
for (int x = 0; x < positionedStack.items.length; x++) {
if (Platform.isRecipePrioritized(positionedStack.items[x])) {
list.add(0, positionedStack.items[x]);
} else {
list.add(positionedStack.items[x]);
}
}
for (final ItemStack is : list) {
final NBTTagCompound tag = new NBTTagCompound();
is.writeToNBT(tag);
tags.appendTag(tag);
}
recipe.setTag("#" + slot.getSlotIndex(), tags);
break;
}
}
}
}
}
return recipe;
}
}
@@ -10,7 +10,6 @@ import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.GuiFluidCraftingWireless;
import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal;
import com.glodblock.github.nei.object.OrderStack;
import com.glodblock.github.nei.recipes.FluidRecipe;
@@ -31,9 +30,8 @@ public class FluidPatternTerminalRecipeTransferHandler implements IOverlayHandle
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
if (firstGui instanceof FCGuiEncodeTerminal || firstGui instanceof GuiFluidCraftingWireless) {
boolean priority = !(firstGui instanceof GuiFluidCraftingWireless)
&& ((FCGuiEncodeTerminal) firstGui).container.prioritize;
if (firstGui instanceof FCGuiEncodeTerminal) {
boolean priority = ((FCGuiEncodeTerminal) firstGui).container.prioritize;
List<OrderStack<?>> in = FluidRecipe.getPackageInputs(recipe, recipeIndex, priority);
List<OrderStack<?>> out = FluidRecipe.getPackageOutputs(recipe, recipeIndex, !notUseOther(recipe));
boolean craft = shouldCraft(recipe);
@@ -19,7 +19,7 @@ public class NEI_FC_Config implements IConfigureNEI {
for (String identifier : FluidRecipe.getSupportRecipes()) {
API.registerGuiOverlayHandler(
GuiFluidCraftingWireless.class,
FluidPatternTerminalRecipeTransferHandler.INSTANCE,
FluidCraftingTransferHandler.INSTANCE,
identifier);
API.registerGuiOverlayHandler(
GuiFluidPatternWireless.class,
@@ -5,20 +5,23 @@ import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.helpers.InventoryAction;
import com.glodblock.github.client.gui.container.ContainerCraftingWireless;
import com.glodblock.github.client.gui.container.ContainerItemMonitor;
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
import com.glodblock.github.common.item.ItemFluidPacket;
@@ -106,41 +109,7 @@ public class CPacketTransferRecipe implements IMessage {
} else {
storageList = AEApi.instance().storage().createItemList();
}
if (c instanceof ContainerCraftingWireless && host != null) {
// crafting terminal only
ContainerCraftingWireless cf = (ContainerCraftingWireless) c;
IInventory inputSlot = cf.getInventoryByName("crafting");
if (!storageList.isEmpty()) {
int i = 0;
for (OrderStack stack : message.inputs) {
if (inputSlot.getStackInSlot(i) == null) {
ItemStack is = (ItemStack) stack.getStack();
IAEItemStack iaeItemStack = AEApi.instance().storage().createItemStack(is);
IAEItemStack storedItem = storageList.findPrecise(iaeItemStack);
if (storedItem == null) {
for (IAEItemStack tmp : storageList.findFuzzy(iaeItemStack, FuzzyMode.IGNORE_ALL)) {
tmp.setStackSize(is.stackSize);
ItemStack substitute = tmp.getItemStack().copy();
inputSlot.setInventorySlotContents(i, substitute);
host.getItemInventory()
.extractItems(tmp, Actionable.MODULATE, cf.getActionSource());
break;
}
} else {
host.getItemInventory()
.extractItems(iaeItemStack, Actionable.MODULATE, cf.getActionSource());
inputSlot.setInventorySlotContents(i, is);
}
}
i++;
}
}
c.onCraftMatrixChanged(inputSlot);
} else if (c instanceof FCContainerEncodeTerminal) {
if (c instanceof FCContainerEncodeTerminal) {
// pattern terminal only
FCContainerEncodeTerminal cf = (FCContainerEncodeTerminal) c;
@@ -203,5 +172,25 @@ public class CPacketTransferRecipe implements IMessage {
}
}
}
private boolean clearCraftingTable(AEBaseContainer c, EntityPlayerMP player) {
Slot s = null;
for (final Object j : c.inventorySlots) {
if (j instanceof SlotCraftingMatrix) {
s = (Slot) j;
}
}
if (s != null) {
c.doAction(player, InventoryAction.MOVE_REGION, s.slotNumber, 0);
}
for (final Object j : c.inventorySlots) {
if (j instanceof SlotCraftingMatrix) {
if (((SlotCraftingMatrix) j).getHasStack()) {
return false;
}
}
}
return true;
}
}
}