fix when open the auto filler, always to try update pattern

add using exists item to fill pattern slot
This commit is contained in:
asdflj committed 2023-02-02 11:13:59 +08:00
1 parent 7ecd7d246f
commit a8155c8b17
5 files changed
+51 -4

No files matched your search

@@ -25,12 +25,14 @@ public class ContainerFluidAutoFiller extends AEBaseContainer {
MutablePair<Boolean, ItemStack> result = ContainerFluidAutoFiller.isItemValid(is);
if (result.left) {
if (super.getHasStack()) super.clearStack();
hasChange = true;
super.putStack(result.right);
}
}
}
private final TileFluidAutoFiller tile;
private static boolean hasChange;
public ContainerFluidAutoFiller(InventoryPlayer ipl, TileFluidAutoFiller tile) {
super(ipl, tile);
@@ -54,6 +56,9 @@ public class ContainerFluidAutoFiller extends AEBaseContainer {
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
tile.updatePattern();
if (hasChange) {
tile.updatePattern();
hasChange = false;
}
}
}
@@ -109,7 +109,6 @@ public class TileFluidAutoFiller extends AENetworkInvTile
if (inventory.getStackInSlot(0) == null) {
inventory.setInventorySlotContents(0, BUCKET);
}
updatePattern();
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
@@ -35,7 +35,7 @@ public class FluidPatternTerminalRecipeTransferHandler implements IOverlayHandle
List<OrderStack<?>> in = FluidRecipe.getPackageInputs(recipe, recipeIndex, priority);
List<OrderStack<?>> out = FluidRecipe.getPackageOutputs(recipe, recipeIndex, !notUseOther(recipe));
boolean craft = shouldCraft(recipe);
FluidCraft.proxy.netHandler.sendToServer(new CPacketTransferRecipe(in, out, craft));
FluidCraft.proxy.netHandler.sendToServer(new CPacketTransferRecipe(in, out, craft, shift));
}
}
@@ -14,7 +14,7 @@ import com.glodblock.github.util.Util;
public class OrderStack<T> {
private final T RealStack;
private T RealStack;
private final int index;
public static final int ITEM = 1;
@@ -28,6 +28,10 @@ public class OrderStack<T> {
this.index = order;
}
public void putStack(T stack) {
this.RealStack = stack;
}
public T getStack() {
return RealStack;
}
@@ -11,6 +11,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.nei.NEIUtils;
@@ -28,13 +34,19 @@ public class CPacketTransferRecipe implements IMessage {
private List<OrderStack<?>> outputs;
private boolean isCraft;
private static final int MAX_INDEX = 32;
private boolean shift;
public CPacketTransferRecipe() {}
public CPacketTransferRecipe(List<OrderStack<?>> IN, List<OrderStack<?>> OUT, boolean craft) {
this(IN, OUT, craft, false);
}
public CPacketTransferRecipe(List<OrderStack<?>> IN, List<OrderStack<?>> OUT, boolean craft, boolean shift) {
this.inputs = IN;
this.outputs = OUT;
this.isCraft = craft;
this.shift = shift;
}
// I should use GZIP to compress the message, but i'm too lazy.
@@ -42,6 +54,7 @@ public class CPacketTransferRecipe implements IMessage {
@Override
public void toBytes(ByteBuf buf) {
buf.writeBoolean(isCraft);
buf.writeBoolean(shift);
NBTTagCompound nbt_m = new NBTTagCompound();
NBTTagCompound nbt_i = new NBTTagCompound();
NBTTagCompound nbt_o = new NBTTagCompound();
@@ -59,6 +72,7 @@ public class CPacketTransferRecipe implements IMessage {
@Override
public void fromBytes(ByteBuf buf) {
isCraft = buf.readBoolean();
shift = buf.readBoolean();
inputs = new LinkedList<>();
outputs = new LinkedList<>();
NBTTagCompound nbt_m = ByteBufUtils.readTag(buf);
@@ -78,10 +92,19 @@ public class CPacketTransferRecipe implements IMessage {
@Nullable
@Override
@SuppressWarnings("unchecked")
public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
Container c = ctx.getServerHandler().playerEntity.openContainer;
if (c instanceof FCContainerEncodeTerminal) {
FCContainerEncodeTerminal cf = (FCContainerEncodeTerminal) c;
ITerminalHost host = cf.getHost();
IItemList<IAEItemStack> storageList;
if (host != null) {
storageList = host.getItemInventory().getStorageList();
} else {
storageList = AEApi.instance().storage().createItemList();
}
boolean combine = cf.combine;
cf.getPatternTerminal().setCraftingRecipe(message.isCraft);
IInventory inputSlot = cf.getInventoryByName("crafting");
@@ -101,6 +124,22 @@ public class CPacketTransferRecipe implements IMessage {
message.inputs = NEIUtils.clearNull(message.inputs);
message.outputs = NEIUtils.clearNull(message.outputs);
}
// using exists item to fill slot
if (message.shift && !storageList.isEmpty()) {
for (OrderStack stack : message.inputs) {
if (stack.getStack() instanceof FluidStack) continue;
ItemStack is = (ItemStack) stack.getStack();
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;
}
}
}
}
transferPack(message.inputs, inputSlot);
transferPack(message.outputs, outputSlot);
c.onCraftMatrixChanged(inputSlot);