Skip to content

Commit

Permalink
Merge pull request #72 from asdflj/bookmark
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
GlodBlock authored Feb 2, 2023
2 parents f40e088 + a8155c8 commit f14e168
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public void putStack(ItemStack is) {
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);
Expand All @@ -54,6 +56,9 @@ public static MutablePair<Boolean, ItemStack> isItemValid(ItemStack itemStack) {
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
tile.updatePattern();
if (hasChange) {
tile.updatePattern();
hasChange = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void readFromNBTEvent(NBTTagCompound data) {
if (inventory.getStackInSlot(0) == null) {
inventory.setInventorySlotContents(0, BUCKET);
}
updatePattern();
}

@TileEvent(TileEventType.WORLD_NBT_WRITE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int reci
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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class OrderStack<T> {

private final T RealStack;
private T RealStack;
private final int index;

public static final int ITEM = 1;
Expand All @@ -28,6 +28,10 @@ public OrderStack(T stack, int order) {
this.index = order;
}

public void putStack(T stack) {
this.RealStack = stack;
}

public T getStack() {
return RealStack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
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;
Expand All @@ -28,20 +34,27 @@ 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.
// NBT to ByteBuf has a compress stream
@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();
Expand All @@ -59,6 +72,7 @@ public void toBytes(ByteBuf buf) {
@Override
public void fromBytes(ByteBuf buf) {
isCraft = buf.readBoolean();
shift = buf.readBoolean();
inputs = new LinkedList<>();
outputs = new LinkedList<>();
NBTTagCompound nbt_m = ByteBufUtils.readTag(buf);
Expand All @@ -78,10 +92,19 @@ public static class Handler implements IMessageHandler<CPacketTransferRecipe, IM

@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");
Expand All @@ -101,6 +124,22 @@ public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
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);
Expand Down

0 comments on commit f14e168

Please sign in to comment.