Merge pull request #6285 from JensenJ-Modding/mc1.18/dev

Versioned Inventories for funnel input
This commit is contained in:
simibubi 2024-07-25 13:27:26 +02:00 committed by GitHub
commit f8e8c476ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View file

@ -30,6 +30,7 @@ import com.simibubi.create.content.kinetics.belt.transport.ItemHandlerBeltSegmen
import com.simibubi.create.content.kinetics.belt.transport.TransportedItemStack;
import com.simibubi.create.content.logistics.tunnel.BrassTunnelBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.inventory.VersionedInventoryTrackerBehaviour;
import com.simibubi.create.foundation.utility.NBTHelper;
import net.minecraft.client.renderer.LightTexture;
@ -73,6 +74,7 @@ public class BeltBlockEntity extends KineticBlockEntity {
protected BlockPos controller;
protected BeltInventory inventory;
protected LazyOptional<IItemHandler> itemHandler;
public VersionedInventoryTrackerBehaviour invVersionTracker;
public CompoundTag trackerUpdateTag;
@ -98,6 +100,7 @@ public class BeltBlockEntity extends KineticBlockEntity {
.setInsertionHandler(this::tryInsertingFromSide).considerOccupiedWhen(this::isOccupied));
behaviours.add(new TransportedItemStackHandlerBehaviour(this, this::applyToAllItems)
.withStackPlacement(this::getWorldPositionOf));
behaviours.add(invVersionTracker = new VersionedInventoryTrackerBehaviour(this));
}
@Override

View file

@ -45,7 +45,6 @@ public class BeltFunnelInteractionHandler {
float funnelEntry = segment + .5f;
if (funnelState.getValue(BeltFunnelBlock.SHAPE) == Shape.EXTENDED)
funnelEntry += .499f * (beltMovementPositive ? -1 : 1);
boolean hasCrossed = nextOffset > funnelEntry && beltMovementPositive
|| nextOffset < funnelEntry && !beltMovementPositive;
if (!hasCrossed)
@ -73,9 +72,12 @@ public class BeltFunnelInteractionHandler {
else
continue;
if(beltInventory.belt.invVersionTracker.stillWaiting(inserting))
continue;
int amountToExtract = funnelBE.getAmountToExtract();
ExtractionCountMode modeToExtract = funnelBE.getModeToExtract();
ItemStack toInsert = currentItem.stack.copy();
if (amountToExtract > toInsert.getCount() && modeToExtract != ExtractionCountMode.UPTO)
if (blocking)
@ -92,14 +94,18 @@ public class BeltFunnelInteractionHandler {
return true;
else
continue;
else
beltInventory.belt.invVersionTracker.awaitNewVersion(inserting);
}
ItemStack remainder = inserting.insert(toInsert);
if (toInsert.equals(remainder, false))
if (toInsert.equals(remainder, false)) {
beltInventory.belt.invVersionTracker.awaitNewVersion(inserting);
if (blocking)
return true;
else
continue;
}
int notFilled = currentItem.stack.getCount() - toInsert.getCount();
if (!remainder.isEmpty()) {