Fix simulate false positive on some cases (#1299)

Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Kogepan229 <73163994+Kogepan229@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kogepan229 <kogepan25629@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-05-27 00:29:45 -04:00
1 parent bf273a5c9f
commit 5ddc4fbce2
11 files changed
+398 -80

No files matched your search

@@ -126,4 +126,6 @@ public interface IItems {
IItemDefinition toolNetworkVisualiser();
IItemDefinition toolWirelessKit();
IItemDefinition itemMEStackPacket();
}
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.gtnewhorizon.gtnhlib.item.ItemStackNBT;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -88,6 +89,7 @@ import appeng.helpers.IPinsHandler;
import appeng.helpers.MonitorableAction;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.items.contents.PinsHandler;
import appeng.items.misc.ItemMEStackPacket;
import appeng.items.storage.ItemViewCell;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
@@ -599,6 +601,25 @@ public class ContainerMEMonitorable extends AEBaseContainer
slotItem = itemMonitor.getAvailableItem(ais, fetchNewId());
}
final ItemStack tempHand = player.inventory.getItemStack();
if (tempHand != null && tempHand.getItem() instanceof ItemMEStackPacket) {
if (this.getPowerSource() == null) return;
final IAEStack<?> tempAes = ItemMEStackPacket.toAEStack(tempHand);
if (tempAes == null) return;
final IMEMonitor tempMonitor = getMonitorWithFilter(tempAes.getStackType());
if (tempMonitor == null) return;
player.inventory.setItemStack(null);
this.updateHeld(player);
final IAEStack<?> res = Platform
.poweredInsert(this.getPowerSource(), tempMonitor, tempAes, this.getActionSource());
if (res != null) Platform.handleLeftover(player, res);
return;
}
switch (action) {
case AUTO_CRAFT -> {} // handled in PacketMonitorableAction
case SET_PIN -> {
@@ -757,6 +778,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
}
case DRAIN_SINGLE_CONTAINER -> {
ItemStack hand = player.inventory.getItemStack();
if (hand == null) return;
final IAEStackType type = getStackTypeForContainer(hand);
if (type == null) return;
@@ -776,17 +798,30 @@ public class ContainerMEMonitorable extends AEBaseContainer
long amountToInject = leftover == null ? stack.getStackSize()
: stack.getStackSize() - leftover.getStackSize();
ObjectLongPair<ItemStack> simulated = type
.drainStackFromContainer(hand.copy(), stack.setStackSize(amountToInject));
ObjectLongPair<ItemStack> simulated = type.drainStackFromContainer(
Platform.copyStackWithSizeOne(hand),
stack.setStackSize(amountToInject));
if (simulated.rightLong() == 0 || simulated.left() == null) return;
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
if (adaptor.addItems(simulated.left()) != null) return;
ItemStack result = simulated.left();
monitor.injectItems(
final IAEStack<?> modulateLeftover = monitor.injectItems(
stack.setStackSize(simulated.rightLong()),
Actionable.MODULATE,
this.getActionSource());
if (modulateLeftover != null) {
if (modulateLeftover.getStackSize() == simulated.rightLong()) return;
ObjectLongPair<ItemStack> modulateResult = type.fillContainer(result.copy(), modulateLeftover);
if (modulateResult.left() != null) result = modulateResult.left();
final long diff = modulateLeftover.getStackSize() - modulateResult.rightLong();
if (diff != 0) Platform.handleLeftover(player, modulateLeftover.copy().setStackSize(diff));
}
Platform.addToPlayerInvOrDrop(player, result);
hand.stackSize--;
this.updateHeld(player);
}
@@ -795,7 +830,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
case DRAIN_CONTAINERS -> {
final ItemStack hand = player.inventory.getItemStack();
final IAEStackType<?> type = getStackTypeForContainer(hand);
final IAEStackType type = getStackTypeForContainer(hand);
if (type == null) return;
final IMEMonitor monitor = this.getMonitorWithFilter(type);
@@ -822,7 +857,23 @@ public class ContainerMEMonitorable extends AEBaseContainer
// If all stack in hand can be empty
if (injected == toInjectAmount && hand.stackSize <= cleared.getMaxStackSize()) {
toInject.setStackSize(toInjectAmount);
monitor.injectItems(toInject, Actionable.MODULATE, this.getActionSource());
IAEStack<?> modulateLeftover = monitor
.injectItems(toInject, Actionable.MODULATE, this.getActionSource());
if (modulateLeftover != null) {
if (modulateLeftover.getStackSize() == toInjectAmount) return;
ObjectLongPair<ItemStack> modulateResult = type
.fillContainer(cleared.copy(), modulateLeftover);
ItemStack result = modulateResult.left() != null ? modulateResult.left() : cleared.copy();
final long diff = modulateLeftover.getStackSize() - modulateResult.rightLong();
if (diff != 0) Platform.handleLeftover(player, modulateLeftover.copy().setStackSize(diff));
Platform.addToPlayerInvOrDrop(player, result);
hand.stackSize--;
}
cleared.stackSize = hand.stackSize;
player.inventory.setItemStack(cleared);
this.updateHeld(player);
@@ -830,18 +881,30 @@ public class ContainerMEMonitorable extends AEBaseContainer
// If partial stack in hand will be empty
else {
int stackSize = hand.stackSize;
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
for (int i = 0; i < stackSize; i++) {
toInject.setStackSize(amountPerItem);
leftover = monitor.injectItems(toInject, Actionable.SIMULATE, this.getActionSource());
injected = leftover == null ? amountPerItem : amountPerItem - leftover.getStackSize();
if (injected != amountPerItem) break;
if (adaptor.addItems(cleared.copy()) != null) break;
toInject.setStackSize(amountPerItem);
monitor.injectItems(toInject, Actionable.MODULATE, this.getActionSource());
ItemStack result = cleared.copy();
final IAEStack<?> modulateLeftover = monitor
.injectItems(toInject, Actionable.MODULATE, this.getActionSource());
if (modulateLeftover != null) {
if (modulateLeftover.getStackSize() == amountPerItem) continue;
final ObjectLongPair<ItemStack> modulateResult = type
.fillContainer(cleared.copy(), modulateLeftover);
if (modulateResult.left() != null) result = modulateResult.left();
final long diff = modulateLeftover.getStackSize() - modulateResult.rightLong();
if (diff != 0)
Platform.handleLeftover(player, modulateLeftover.copy().setStackSize(diff));
}
Platform.addToPlayerInvOrDrop(player, result);
hand.stackSize--;
}
this.updateHeld(player);
@@ -859,7 +922,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
IMEMonitor monitor = this.getMonitorWithFilter(type);
if (monitor == null) return;
stackInSlot = monitor.getAvailableItem(stackInSlot, fetchNewId());
stackInSlot = monitor.extractItems(stackInSlot, Actionable.SIMULATE, this.getActionSource());
if (stackInSlot == null || stackInSlot.getStackSize() <= 0) return;
if (hand.stackSize == 1) {
@@ -870,18 +933,36 @@ public class ContainerMEMonitorable extends AEBaseContainer
ItemStack itemToFill = hand.copy();
itemToFill.stackSize = 1;
ObjectLongPair<ItemStack> filledPair = type.fillContainer(itemToFill, stackInSlot);
ObjectLongPair<ItemStack> filledPair = type.fillContainer(itemToFill.copy(), stackInSlot);
ItemStack filledContainer = filledPair.left();
long filledAmount = filledPair.rightLong();
if (filledContainer == null || filledAmount <= 0) return;
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
if (adaptor.addItems(filledContainer) != null) return;
monitor.extractItems(
final IAEStack<?> modulateResult = monitor.extractItems(
stackInSlot.copy().setStackSize(filledAmount),
Actionable.MODULATE,
this.getActionSource());
if (modulateResult == null) return;
if (modulateResult.getStackSize() != filledAmount) {
final ObjectLongPair<ItemStack> filled = type.fillContainer(itemToFill, modulateResult);
filledContainer = filled.left();
final long diff = modulateResult.getStackSize() - filled.rightLong();
if (diff != 0) {
final IAEStack<?> injectLeftover = monitor.injectItems(
modulateResult.copy().setStackSize(diff),
Actionable.MODULATE,
this.getActionSource());
if (injectLeftover != null) Platform.handleLeftover(player, injectLeftover);
}
if (filledContainer == null) return;
}
Platform.addToPlayerInvOrDrop(player, filledContainer);
hand.stackSize--;
this.updateHeld(player);
}
@@ -897,7 +978,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
IMEMonitor monitor = this.getMonitorWithFilter(type);
if (monitor == null) return;
stackInSlot = monitor.getAvailableItem(stackInSlot, fetchNewId());
stackInSlot = monitor.extractItems(stackInSlot, Actionable.SIMULATE, this.getActionSource());
if (stackInSlot == null || stackInSlot.getStackSize() <= 0) return;
// Set filled item to player hand
@@ -907,25 +988,58 @@ public class ContainerMEMonitorable extends AEBaseContainer
long capacity = type.getContainerItemCapacity(hand, stackInSlot);
if (capacity <= 0) return;
ObjectLongPair<ItemStack> fullFilledPair = type
.fillContainer(hand.copy(), stackInSlot.copy().setStackSize(Long.MAX_VALUE));
ObjectLongPair<ItemStack> fullFilledPair = type.fillContainer(
Platform.copyStackWithSizeOne(hand),
stackInSlot.copy().setStackSize(Long.MAX_VALUE));
ItemStack fullFilledContainer = fullFilledPair.left();
if (fullFilledContainer == null) return;
if (fullFilledContainer.getMaxStackSize() >= hand.stackSize
&& capacity * hand.stackSize <= stackInSlot.getStackSize()) {
// Fill all item in player hand
monitor.extractItems(
final IAEStack<?> stackToFill = monitor.extractItems(
stackInSlot.copy().setStackSize(capacity * hand.stackSize),
Actionable.MODULATE,
this.getActionSource());
fullFilledContainer.stackSize = hand.stackSize;
player.inventory.setItemStack(fullFilledContainer);
if (stackToFill == null) return;
if (stackToFill.getStackSize() == capacity * hand.stackSize) {
fullFilledContainer.stackSize = hand.stackSize;
player.inventory.setItemStack(fullFilledContainer);
}
// If the amount extracted from the network is not enough to fill all container
else {
final ObjectLongPair<ItemStack> filled = type
.fillContainer(Platform.copyStackWithSizeOne(hand), stackToFill);
if (filled.left() != null && filled.rightLong() != 0) {
final int filledContainerNum = (int) (stackToFill.getStackSize() / filled.rightLong());
Platform.addToPlayerInvOrDrop(
player,
Platform.copyStackWithSize(filled.left(), filledContainerNum));
hand.stackSize -= filledContainerNum;
stackToFill.decStackSize(filled.rightLong() * filledContainerNum);
final ObjectLongPair<ItemStack> filled2 = type
.fillContainer(Platform.copyStackWithSizeOne(hand), stackToFill);
if (filled2.left() != null && filled2.rightLong() != 0) {
Platform.addToPlayerInvOrDrop(player, filled2.left());
hand.stackSize -= 1;
if (hand.stackSize <= 0) player.inventory.setItemStack(null);
stackToFill.decStackSize(filled2.rightLong());
}
}
if (stackToFill.getStackSize() > 0) {
final IAEStack<?> injectLeftover = monitor
.injectItems(stackToFill, Actionable.MODULATE, this.getActionSource());
if (injectLeftover != null) Platform.handleLeftover(player, injectLeftover);
}
}
this.updateHeld(player);
} else {
// Set all filled item to player hand
IAEStack<?> aes = stackInSlot.copy();
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
int stackSize = hand.stackSize;
for (int i = 0; i < stackSize; i++) {
ItemStack itemToFill = hand.copy();
@@ -936,16 +1050,35 @@ public class ContainerMEMonitorable extends AEBaseContainer
long filledAmount = filledPair.rightLong();
if (filledContainer == null || filledAmount <= 0) break;
if (hand.stackSize - 1 == 0) {
player.inventory.setItemStack(filledContainer);
} else if (adaptor.addItems(filledContainer) != null) break;
long amountBeforeExtract = aes.getStackSize();
monitor.extractItems(
final IAEStack<?> modulateResult = monitor.extractItems(
aes.setStackSize(filledAmount),
Actionable.MODULATE,
this.getActionSource());
aes.setStackSize(amountBeforeExtract - filledAmount);
if (modulateResult == null) break;
if (modulateResult.getStackSize() != filledAmount) {
final ObjectLongPair<ItemStack> filled = type
.fillContainer(itemToFill.copy(), modulateResult);
filledContainer = filled.left();
final long diff = modulateResult.getStackSize() - filled.rightLong();
if (diff != 0) {
final IAEStack<?> injectLeftover = monitor.injectItems(
modulateResult.copy().setStackSize(diff),
Actionable.MODULATE,
this.getActionSource());
if (injectLeftover != null) Platform.handleLeftover(player, injectLeftover);
}
if (filledContainer == null) break;
aes.setStackSize(0);
}
if (hand.stackSize - 1 == 0) player.inventory.setItemStack(filledContainer);
else Platform.addToPlayerInvOrDrop(player, filledContainer);
hand.stackSize--;
if (aes.getStackSize() <= 0) break;
@@ -989,13 +1122,19 @@ public class ContainerMEMonitorable extends AEBaseContainer
clearedContainer.stackSize = stackSize;
Platform.poweredInsert(
IAEStack<?> leftover = Platform.poweredInsert(
this.getPowerSource(),
monitor,
stack,
this.getActionSource(),
Actionable.MODULATE);
if (leftover != null) {
if (leftover.getStackSize() == stack.getStackSize()) return;
Platform.handleLeftover(player, leftover);
}
slot.putStack(clearedContainer);
}
}
@@ -1049,13 +1188,30 @@ public class ContainerMEMonitorable extends AEBaseContainer
@SuppressWarnings({ "unchecked", "rawtypes" })
private void fillSingleFluidContainer(EntityPlayerMP player, ItemStack hand, IAEStack<?> stack,
final IAEStackType type, final IMEMonitor monitor) {
ObjectLongPair<ItemStack> filledPair = type.fillContainer(hand, stack);
ObjectLongPair<ItemStack> filledPair = type.fillContainer(hand.copy(), stack);
ItemStack filledContainer = filledPair.left();
long filledAmount = filledPair.rightLong();
if (filledContainer == null || filledAmount <= 0) return;
monitor.extractItems(stack.copy().setStackSize(filledAmount), Actionable.MODULATE, this.getActionSource());
IAEStack<?> modulateResult = monitor
.extractItems(stack.copy().setStackSize(filledAmount), Actionable.MODULATE, this.getActionSource());
if (modulateResult == null) return;
if (modulateResult.getStackSize() != filledAmount) {
ObjectLongPair<ItemStack> filled = type.fillContainer(hand.copy(), modulateResult);
filledContainer = filled.left();
final long diff = modulateResult.getStackSize() - filled.rightLong();
if (diff != 0) {
final IAEStack<?> injectLeftover = monitor.injectItems(
modulateResult.copy().setStackSize(diff),
Actionable.MODULATE,
this.getActionSource());
if (injectLeftover != null) Platform.handleLeftover(player, injectLeftover);
}
if (filledContainer == null) return;
}
player.inventory.setItemStack(filledContainer);
this.updateHeld(player);
@@ -1075,9 +1231,22 @@ public class ContainerMEMonitorable extends AEBaseContainer
ObjectLongPair<ItemStack> simulated = type
.drainStackFromContainer(hand.copy(), stack.setStackSize(amountToInject));
if (simulated.rightLong() == 0 || simulated.left() == null) return;
ItemStack result = simulated.left();
monitor.injectItems(stack.setStackSize(simulated.rightLong()), Actionable.MODULATE, this.getActionSource());
player.inventory.setItemStack(simulated.left());
final IAEStack<?> modulateLeftover = monitor
.injectItems(stack.setStackSize(simulated.rightLong()), Actionable.MODULATE, this.getActionSource());
if (modulateLeftover != null) {
if (modulateLeftover.getStackSize() == simulated.rightLong()) return;
final ObjectLongPair<ItemStack> filled = type.fillContainer(result, modulateLeftover);
if (filled.left() != null) result = filled.left();
final long leftoverAmount = modulateLeftover.getStackSize() - filled.rightLong();
if (leftoverAmount != 0)
Platform.handleLeftover(player, modulateLeftover.copy().setStackSize(leftoverAmount));
}
player.inventory.setItemStack(result);
this.updateHeld(player);
}
@@ -1105,11 +1274,33 @@ public class ContainerMEMonitorable extends AEBaseContainer
return null;
}
protected ItemStack shiftStoreItem(final ItemStack input) {
protected ItemStack shiftStoreItem(@Nonnull final ItemStack input) {
if (this.getPowerSource() == null) return input;
if (input.getItem() instanceof ItemMEStackPacket) {
final IAEStack<?> tempAes = ItemMEStackPacket.toAEStack(input);
if (tempAes == null) return null;
final IMEMonitor tempMonitor = getMonitorWithFilter(tempAes.getStackType());
if (tempMonitor == null) return input;
final IAEStack<?> res = Platform
.poweredInsert(this.getPowerSource(), tempMonitor, tempAes, this.getActionSource());
if (res != null) {
final ItemStack stackPacket = AEApi.instance().definitions().items().itemMEStackPacket().maybeStack(1)
.get();
Platform.writeStackNBT(res, ItemStackNBT.get(stackPacket));
return stackPacket;
} else {
return null;
}
}
IMEMonitor<IAEItemStack> itemMonitor = this.getMonitorWithFilter(ITEM_STACK_TYPE);
if (this.getPowerSource() == null || itemMonitor == null) {
if (itemMonitor == null) {
return input;
}
final IAEItemStack ais = Platform.poweredInsert(
this.getPowerSource(),
itemMonitor,
@@ -22,6 +22,7 @@ import appeng.items.materials.MaterialType;
import appeng.items.misc.ItemCrystalSeed;
import appeng.items.misc.ItemEncodedPattern;
import appeng.items.misc.ItemEncodedUltimatePattern;
import appeng.items.misc.ItemMEStackPacket;
import appeng.items.misc.ItemPaintBall;
import appeng.items.misc.ItemTunnelPattern;
import appeng.items.parts.ItemFacade;
@@ -130,6 +131,8 @@ public final class ApiItems implements IItems {
private final IItemDefinition toolNetworkVisualiser;
private final IItemDefinition toolWirelessKit;
private final IItemDefinition itemMEStackPacket;
public ApiItems(final DefinitionConstructor constructor) {
this.certusQuartzAxe = constructor.registerItemDefinition(new ToolQuartzAxe(AEFeature.CertusQuartzTools));
this.certusQuartzHoe = constructor.registerItemDefinition(new ToolQuartzHoe(AEFeature.CertusQuartzTools));
@@ -209,6 +212,8 @@ public final class ApiItems implements IItems {
this.toolReplicatorCard = constructor.registerItemDefinition(new ToolReplicatorCard());
this.toolNetworkVisualiser = constructor.registerItemDefinition(new ToolNetworkVisualiser());
this.toolWirelessKit = constructor.registerItemDefinition(new ToolWirelessKit());
this.itemMEStackPacket = constructor.registerItemDefinition(new ItemMEStackPacket());
}
@Override
@@ -476,6 +481,11 @@ public final class ApiItems implements IItems {
return this.toolNetworkVisualiser;
}
@Override
public IItemDefinition itemMEStackPacket() {
return this.itemMEStackPacket;
}
public IItemDefinition paintBall() {
return this.paintBall;
}
@@ -389,7 +389,10 @@ public enum GuiText implements Localization {
GuiDimensionalCoord,
GuiDimensionalCoordShort,
GuiDimensionalCoordNoDim,
GuiDimensionalCoordShortNoDim;
GuiDimensionalCoordShortNoDim,
itemMEStackPacketDesc1,
itemMEStackPacketDesc2;
private final String root;
@@ -0,0 +1,51 @@
package appeng.items.misc;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.gtnewhorizon.gtnhlib.item.ItemStackNBT;
import appeng.api.storage.data.IAEStack;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
public class ItemMEStackPacket extends AEBaseItem {
public ItemMEStackPacket() {
this.setFeature(EnumSet.of(AEFeature.Core));
this.setMaxStackSize(1);
}
@Override
protected void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> lines,
boolean displayMoreInfo) {
super.addCheckedInformation(stack, player, lines, displayMoreInfo);
lines.add(GuiText.itemMEStackPacketDesc1.getLocal());
lines.add(GuiText.itemMEStackPacketDesc2.getLocal());
final IAEStack<?> aes = toAEStack(stack);
if (aes != null) lines.add(aes.getDisplayName() + ": " + aes.getStackSize());
}
@Nullable
public static IAEStack<?> toAEStack(@NotNull final ItemStack is) {
if (is.getItem() instanceof ItemMEStackPacket) {
return IAEStack.fromNBTGeneric(ItemStackNBT.get(is));
}
return null;
}
// hide from creative tab & nei
@Override
protected void getCheckedSubItems(Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks) {}
}
@@ -46,6 +46,7 @@ import appeng.util.SortedArrayList;
import appeng.util.inv.ItemListIgnoreCrafting;
import appeng.util.item.NetworkItemList;
import appeng.util.item.PrioritizedNetworkItemList;
import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap;
public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMENetworkInventory<T> {
@@ -144,6 +145,10 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMENetwor
IMEInventoryHandler<T> inv = priorityInventory.get(i);
int lastPriority = inv.getPriority();
outer: while (true) {
// Simulate doesn't have memory, so pass 2 must account for amounts already accepted by pass 1 in
// the same inventory.
final Int2LongOpenHashMap simulatedPass1Inserted = new Int2LongOpenHashMap();
int passTwoIndex = -1;
// Pass 1
while (true) {
@@ -154,8 +159,17 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMENetwor
final boolean validForPass1 = inv.validForPass(1);
if (validForPass1 && (canAcceptInput = inv.canAccept(input))
&& (inv.isPrioritized(input) || inv.extractItems(input, Actionable.SIMULATE, src) != null)) {
long before = input.getStackSize();
input = inv.injectItems(input, type, src);
if (input == null) break outer;
if (type == Actionable.SIMULATE && inv.validForPass(2)) {
long accepted = before - input.getStackSize();
if (accepted > 0) {
simulatedPass1Inserted.addTo(i, accepted);
}
}
}
// We remember at which index the second pass should start iterating. Additionally, we check if the
@@ -191,7 +205,27 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMENetwor
lastPriority = inv.getPriority();
while (true) {
if (inv.canAccept(input) && !inv.isPrioritized(input)) {
input = inv.injectItems(input, type, src);
if (type == Actionable.SIMULATE) {
final long pass1Inserted = simulatedPass1Inserted.getOrDefault(i, 0);
if (pass1Inserted > 0) {
final T pass2Input = input.copy();
pass2Input.setStackSize(pass2Input.getStackSize() + pass1Inserted);
final T pass2Leftover = inv.injectItems(pass2Input, type, src);
if (pass2Leftover == null) {
input = null;
break outer;
}
if (pass2Leftover.getStackSize() < input.getStackSize()) {
input.setStackSize(pass2Leftover.getStackSize());
}
} else {
input = inv.injectItems(input, type, src);
}
} else {
input = inv.injectItems(input, type, src);
}
if (input == null) break outer;
}
@@ -12,14 +12,9 @@ package appeng.parts.reporting;
import static appeng.server.ServerHelper.CONTAINER_INTERACTION_KEY;
import java.util.Collections;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
@@ -33,8 +28,6 @@ import appeng.client.texture.CableBusTextures;
import appeng.core.AELog;
import appeng.helpers.Reflected;
import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor;
import appeng.util.IterationCounter;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import it.unimi.dsi.fastutil.objects.ObjectLongPair;
@@ -157,18 +150,7 @@ public class PartConversionMonitor extends AbstractPartMonitor {
.poweredExtraction(energy, cell, input, new PlayerSource(player, this));
if (retrieved != null) {
ItemStack newItems = retrieved.getItemStack();
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
newItems = adaptor.addItems(newItems);
if (newItems != null) {
final TileEntity te = this.getTile();
final List<ItemStack> list = Collections.singletonList(newItems);
Platform.spawnDrops(
player.worldObj,
te.xCoord + this.getSide().offsetX,
te.yCoord + this.getSide().offsetY,
te.zCoord + this.getSide().offsetZ,
list);
}
Platform.addToPlayerInvOrDrop(player, newItems);
if (player.openContainer != null) {
player.openContainer.detectAndSendChanges();
@@ -211,17 +193,27 @@ public class PartConversionMonitor extends AbstractPartMonitor {
ObjectLongPair<ItemStack> drained = type
.drainStackFromContainer(hand, stack.setStackSize(amountToInject));
if (drained.rightLong() == 0 || drained.left() == null) return;
Platform.poweredInsert(energy, monitor, stack.setStackSize(drained.rightLong()), source);
ItemStack result = drained.left();
final IAEStack<?> modulateLeftover = Platform
.poweredInsert(energy, monitor, stack.setStackSize(drained.rightLong()), source);
if (modulateLeftover != null) {
if (modulateLeftover.getStackSize() == drained.rightLong()) return;
ObjectLongPair<ItemStack> filled = type.fillContainer(result, modulateLeftover);
if (filled.left() != null) result = filled.left();
final long leftoverAmount = modulateLeftover.getStackSize() - filled.rightLong();
if (leftoverAmount != 0)
Platform.handleLeftover(player, modulateLeftover.copy().setStackSize(leftoverAmount));
}
if (stackSize == 1) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, result);
} else {
player.getCurrentEquippedItem().stackSize -= 1;
if (result != null && !player.inventory.addItemStackToInventory(result)) {
player.entityDropItem(result, 0);
}
Platform.addToPlayerInvOrDrop(player, result);
}
} catch (GridAccessException e) {
AELog.error(e);
@@ -245,32 +237,36 @@ public class PartConversionMonitor extends AbstractPartMonitor {
final IEnergySource energy = this.getProxy().getEnergy();
final IMEMonitor monitor = this.getProxy().getStorage().getMEMonitor(type);
if (monitor == null) return;
final PlayerSource src = new PlayerSource(player, this);
IAEStack<?> stored = monitor.getAvailableItem(displayed, IterationCounter.fetchNewId());
IAEStack<?> stored = monitor.extractItems(displayed, Actionable.SIMULATE, src);
if (stored == null || stored.getStackSize() <= 0) return;
long amountToFill = type.fillContainer(hand.copy(), stored).rightLong();
long amountToFill = type.fillContainer(Platform.copyStackWithSizeOne(hand), stored).rightLong();
IAEStack<?> extracted = Platform
.poweredExtraction(energy, monitor, stored.copy().setStackSize(amountToFill), src);
IAEStack<?> extracted = Platform.poweredExtraction(
energy,
monitor,
stored.copy().setStackSize(amountToFill),
new PlayerSource(player, this));
if (extracted == null) return;
ObjectLongPair<ItemStack> filled = type.fillContainer(hand.copy(), extracted);
ObjectLongPair<ItemStack> filled = type.fillContainer(Platform.copyStackWithSizeOne(hand), extracted);
ItemStack result = filled.left();
final long leftoverAmount = extracted.getStackSize() - filled.rightLong();
if (leftoverAmount != 0) {
final IAEStack<?> aes = monitor
.injectItems(extracted.setStackSize(leftoverAmount), Actionable.MODULATE, src);
if (aes != null) Platform.handleLeftover(player, aes);
}
if (result == null || filled.rightLong() == 0) return;
if (hand.stackSize == 1) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, result);
} else {
hand.stackSize--;
if (result != null && !player.inventory.addItemStackToInventory(result)) {
player.entityDropItem(result, 0);
}
if (player.openContainer != null) {
player.openContainer.detectAndSendChanges();
}
Platform.addToPlayerInvOrDrop(player, result);
}
} catch (final GridAccessException e) {
AELog.error(e);
+1 -1
View File
@@ -78,7 +78,7 @@ public class FluidUtils {
} else if (FluidContainerRegistry.isContainer(itemStack)) {
return FluidContainerRegistry.getFluidForFilledItem(itemStack);
} else {
return StackInfo.getFluid(Platform.copyStackWithSize(itemStack, 1));
return StackInfo.getFluid(Platform.copyStackWithSizeOne(itemStack));
}
}
+26
View File
@@ -69,8 +69,12 @@ import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.gtnewhorizon.gtnhlib.item.ItemStackNBT;
import com.mojang.authlib.GameProfile;
import appeng.api.AEApi;
@@ -2166,4 +2170,26 @@ public class Platform {
return null;
}
}
@NotNull
@Contract("_ -> new")
public static ItemStack copyStackWithSizeOne(@NotNull ItemStack itemStack) {
ItemStack copy = itemStack.copy();
copy.stackSize = 1;
return copy;
}
public static void addToPlayerInvOrDrop(final EntityPlayer p, @Nullable final ItemStack is) {
if (is == null) return;
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(p, ForgeDirection.UNKNOWN);
final ItemStack leftOver = adaptor.addItems(is);
p.openContainer.detectAndSendChanges();
if (leftOver != null) p.entityDropItem(leftOver, 0);
}
public static void handleLeftover(final EntityPlayer p, final IAEStack<?> aes) {
final ItemStack container = AEApi.instance().definitions().items().itemMEStackPacket().maybeStack(1).get();
Platform.writeStackNBT(aes, ItemStackNBT.get(container));
addToPlayerInvOrDrop(p, container);
}
}
@@ -499,6 +499,9 @@ gui.appliedenergistics2.GuiDimensionalCoordShort=§c%s§r, §a%s§r, §9%s§r,
gui.appliedenergistics2.GuiDimensionalCoordNoDim=§cX: %s§r,§aY: %s§r,§9Z: %s
gui.appliedenergistics2.GuiDimensionalCoordShortNoDim=§c%s§r, §a%s§r, §9%s
gui.appliedenergistics2.itemMEStackPacketDesc1=Leftover after inject in system operation
gui.appliedenergistics2.itemMEStackPacketDesc2=Make sure you have free space and then put this item in ME Terminal
# GUI Colors - ARGB
gui.color.appliedenergistics2.SearchboxFocused=6E000000
gui.color.appliedenergistics2.SearchboxUnfocused=00000000
@@ -918,6 +921,8 @@ item.appliedenergistics2.ItemCrystalSeed.Certus.name=Certus Quartz Seed
item.appliedenergistics2.ItemCrystalSeed.Nether.name=Nether Quartz Seed
item.appliedenergistics2.ItemCrystalSeed.Fluix.name=Fluix Seed
item.appliedenergistics2.ItemMEStackPacket.name=ME Stack Packet
item.appliedenergistics2.ItemPart.InvalidType.name=Disabled Item
item.appliedenergistics2.ItemMaterial.InvalidType.name=This item is disabled.
Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B