Skip to content

Commit

Permalink
Merge pull request #83 from asdflj/master
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
GlodBlock authored Feb 14, 2023
2 parents 0734dc4 + c8457bb commit f3052c3
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import appeng.api.AEApi;
import appeng.api.config.Actionable;
Expand All @@ -37,10 +39,12 @@
import appeng.util.Platform;

import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemBaseWirelessTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminal;
import com.glodblock.github.common.parts.PartFluidPatternTerminalEx;
import com.glodblock.github.inventory.InventoryHandler;
import com.glodblock.github.inventory.gui.GuiType;
import com.glodblock.github.inventory.item.IWirelessTerminal;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.BlockPos;
Expand Down Expand Up @@ -269,6 +273,12 @@ public void startJob() {
if (ah instanceof PartFluidPatternTerminalEx) {
originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX;
}
if (ah instanceof IWirelessTerminal) {
ItemStack terminal = ((IWirelessTerminal) ah).getItemStack();
if (terminal.getItem() instanceof ItemBaseWirelessTerminal) {
originalGui = ((ItemBaseWirelessTerminal) terminal.getItem()).guiGuiType(terminal);
}
}

if (this.result != null && !this.isSimulation() && getGrid() != null) {
final ICraftingGrid cc = this.getGrid().getCache(ICraftingGrid.class);
Expand All @@ -279,13 +289,22 @@ public void startJob() {
true,
this.getActionSrc());
this.setAutoStart(false);
if (g != null && originalGui != null && this.getOpenContext() != null) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(this.getOpenContext().getTile()),
Objects.requireNonNull(this.getOpenContext().getSide()),
originalGui);
if (g != null && originalGui != null) {
if (ah instanceof IWirelessTerminal) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(this.getPlayerInv().currentItem, 0, 0),
ForgeDirection.UNKNOWN,
originalGui);
} else if (this.getOpenContext() != null) {
InventoryHandler.openGui(
this.getInventoryPlayer().player,
getWorld(),
new BlockPos(this.getOpenContext().getTile()),
Objects.requireNonNull(this.getOpenContext().getSide()),
originalGui);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,54 @@
import net.minecraft.item.ItemStack;

import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;

import com.glodblock.github.inventory.item.IWirelessPatternTerminal;

public class WirelessFluidPatternTerminalPatterns extends AppEngInternalInventory {

private final ItemStack is;
private final IWirelessPatternTerminal terminal;

public WirelessFluidPatternTerminalPatterns(final ItemStack is) {
public WirelessFluidPatternTerminalPatterns(final ItemStack is, final IWirelessPatternTerminal term) {
super(null, 2);
this.is = is;
this.terminal = term;
this.readFromNBT(Platform.openNbtData(is), "pattern");

}

@Override
public void markDirty() {
this.writeToNBT(Platform.openNbtData(is), "pattern");
}

@Override
public void setInventorySlotContents(final int slot, final ItemStack newItemStack) {
final ItemStack oldStack = this.inv[slot];
this.inv[slot] = newItemStack;

if (this.eventsEnabled()) {
ItemStack removed = oldStack;
ItemStack added = newItemStack;

if (oldStack != null && newItemStack != null && Platform.isSameItemPrecise(oldStack, newItemStack)) {
if (oldStack.stackSize > newItemStack.stackSize) {
removed = removed.copy();
removed.stackSize -= newItemStack.stackSize;
added = null;
} else if (oldStack.stackSize < newItemStack.stackSize) {
added = added.copy();
added.stackSize -= oldStack.stackSize;
removed = null;
} else {
removed = added = null;
}
}
this.terminal.onChangeInventory(this, slot, InvOperation.setInventorySlotContents, removed, added);
}

this.markDirty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import net.minecraftforge.common.util.ForgeDirection;

import appeng.api.config.*;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
Expand All @@ -28,6 +30,7 @@
import appeng.util.ConfigManager;
import appeng.util.Platform;

import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.ItemBiggerAppEngInventory;
import com.glodblock.github.inventory.WirelessFluidPatternTerminalPatterns;
Expand Down Expand Up @@ -67,7 +70,7 @@ public WirelessPatternTerminalExInventory(final ItemStack is, final int slot, IG
this.inventorySlot = slot;
this.viewCell = new WirelessTerminalViewCells(is);
this.channel = StorageChannel.ITEMS;
this.pattern = new WirelessFluidPatternTerminalPatterns(is);
this.pattern = new WirelessFluidPatternTerminalPatterns(is, this);
this.crafting = new ItemBiggerAppEngInventory(is, "crafting_ex", 32);
this.output = new ItemBiggerAppEngInventory(is, "output_ex", 32);
}
Expand Down Expand Up @@ -167,7 +170,84 @@ public void saveChanges() {
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {
// NO-OP
if (inv == this.pattern && slot == 1) {
final ItemStack is = inv.getStackInSlot(1);

if (is != null && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern
.getPatternForItem(is, this.getActionableNode().getWorld());

if (details != null) {
final IAEItemStack[] inItems = details.getInputs();
final IAEItemStack[] outItems = details.getOutputs();
int inputsCount = 0;
int outputCount = 0;
for (IAEItemStack inItem : inItems) {
if (inItem != null) {
inputsCount++;
}
}
for (IAEItemStack outItem : outItems) {
if (outItem != null) {
outputCount++;
}
}

this.setSubstitution(details.canSubstitute());
if (newStack != null) {
NBTTagCompound data = newStack.getTagCompound();
this.setCombineMode(data.getInteger("combine") == 1);
this.setBeSubstitute(details.canBeSubstitute());
}
this.setInverted(inputsCount <= 8 && outputCount > 8);
this.setActivePage(0);

for (int i = 0; i < this.crafting.getSizeInventory(); i++) {
this.crafting.setInventorySlotContents(i, null);
}

for (int i = 0; i < this.output.getSizeInventory(); i++) {
this.output.setInventorySlotContents(i, null);
}

for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) {
final IAEItemStack item = inItems[i];
if (item != null) {
if (item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.crafting.setInventorySlotContents(i, packet);
} else this.crafting.setInventorySlotContents(i, item.getItemStack());
}
}

if (inverted) {
for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) {
final IAEItemStack item = outItems[i];
if (item != null) {
if (item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.output.setInventorySlotContents(i, packet);
} else this.output.setInventorySlotContents(i, item.getItemStack());
}
}
} else {
for (int i = 0; i < outItems.length && i < 8; i++) {
final IAEItemStack item = outItems[i];
if (item != null) {
if (item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, packet);
} else this.output.setInventorySlotContents(i >= 4 ? 12 + i : i, item.getItemStack());
}
}
}
}
}
}
}

private void fixCraftingRecipes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import net.minecraftforge.common.util.ForgeDirection;

import appeng.api.config.*;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.MEMonitorHandler;
Expand All @@ -28,6 +30,7 @@
import appeng.util.ConfigManager;
import appeng.util.Platform;

import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.inventory.ItemBiggerAppEngInventory;
import com.glodblock.github.inventory.WirelessFluidPatternTerminalPatterns;
Expand Down Expand Up @@ -67,7 +70,7 @@ public WirelessPatternTerminalInventory(final ItemStack is, final int slot, IGri
this.inventorySlot = slot;
this.viewCell = new WirelessTerminalViewCells(is);
this.channel = StorageChannel.ITEMS;
this.pattern = new WirelessFluidPatternTerminalPatterns(is);
this.pattern = new WirelessFluidPatternTerminalPatterns(is, this);
this.crafting = new ItemBiggerAppEngInventory(is, "crafting", 9);
this.output = new ItemBiggerAppEngInventory(is, "output", 3);
}
Expand Down Expand Up @@ -169,7 +172,58 @@ public void saveChanges() {
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {
// NO-OP
if (inv == this.pattern && slot == 1) {
final ItemStack is = inv.getStackInSlot(1);
if (is != null && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern
.getPatternForItem(is, this.getActionableNode().getWorld());
if (details != null) {
final IAEItemStack[] inItems = details.getInputs();
final IAEItemStack[] outItems = details.getOutputs();

this.setCraftingRecipe(details.isCraftable());
this.setSubstitution(details.canSubstitute());
if (newStack != null) {
NBTTagCompound data = newStack.getTagCompound();
this.setCombineMode(data.getInteger("combine") == 1);
this.setBeSubstitute(details.canBeSubstitute());
}
for (int i = 0; i < this.crafting.getSizeInventory(); i++) {
this.crafting.setInventorySlotContents(i, null);
}

for (int i = 0; i < this.output.getSizeInventory(); i++) {
this.output.setInventorySlotContents(i, null);
}

for (int i = 0; i < this.crafting.getSizeInventory() && i < inItems.length; i++) {
if (inItems[i] != null) {
final IAEItemStack item = inItems[i];
if (item != null && item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.crafting.setInventorySlotContents(i, packet);
} else this.crafting.setInventorySlotContents(i, item == null ? null : item.getItemStack());
}
}

for (int i = 0; i < this.output.getSizeInventory() && i < outItems.length; i++) {
if (outItems[i] != null) {
final IAEItemStack item = outItems[i];
if (item != null && item.getItem() instanceof ItemFluidDrop) {
ItemStack packet = ItemFluidPacket
.newStack(ItemFluidDrop.getFluidStack(item.getItemStack()));
this.output.setInventorySlotContents(i, packet);
} else this.output.setInventorySlotContents(i, item == null ? null : item.getItemStack());
}
}
}
}
}
if (inv == this.crafting) {
this.fixCraftingRecipes();
}
}

private void fixCraftingRecipes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
IAEItemStack iaeItemStack = AEApi.instance().storage().createItemStack(is);
if (storageList.findPrecise(iaeItemStack) == null) {
for (IAEItemStack tmp : storageList.findFuzzy(iaeItemStack, FuzzyMode.IGNORE_ALL)) {
ItemStack substitute = tmp.getItemStack().copy();
substitute.stackSize = is.stackSize;
stack.putStack(substitute);
break;
if (iaeItemStack.sameOre(tmp)) {
ItemStack substitute = tmp.getItemStack().copy();
substitute.stackSize = is.stackSize;
stack.putStack(substitute);
break;
}
}
}
}
Expand Down

0 comments on commit f3052c3

Please sign in to comment.