Fix sieve restocking and sieving with >64 sieves

This commit is contained in:
thedarkcolour 2024-06-10 11:34:27 -07:00
parent cf54235bc3
commit d606669a58
No known key found for this signature in database
GPG Key ID: 6599A8E0516C8F38
2 changed files with 37 additions and 21 deletions

View File

@ -153,7 +153,8 @@ dependencies {
compileOnly fg.deobf('maven.modrinth:embeddium:0.2.12+mc1.20.1')
// testing
implementation fg.deobf("curse.maven:allthecompressed-514045:4938351")
//implementation fg.deobf("curse.maven:allthecompressed-514045:4938351")
implementation fg.deobf("curse.maven:inventory-tweaks-refoxed-976858:5315928")
//implementation fg.deobf("curse.maven:inventorysorter-240633:4655091")
implementation fg.deobf("curse.maven:cyclic-239286:4994392")
implementation fg.deobf("curse.maven:flib-661261:4724762")

View File

@ -22,11 +22,13 @@ import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.stats.Stats;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType;
@ -102,8 +104,6 @@ public abstract class AbstractSieveBlockEntity extends EBlockEntity implements S
this.logic.setContents(buffer.readItem());
}
public InteractionResult use(Level level, Player player, InteractionHand hand) {
ItemStack playerItem = player.getItemInHand(hand);
boolean isClientSide = level.isClientSide;
@ -134,8 +134,9 @@ public abstract class AbstractSieveBlockEntity extends EBlockEntity implements S
if (this.logic.getContents().isEmpty()) {
// If the input has any sieve drops, insert it into the mesh
if (this.logic.isValidInput(playerItem)) {
playerItem = insertContents(player, hand, this.logic);
var usedItem = playerItem.getItem();
var realPlayer = !(player instanceof FakePlayer);
insertContents(player, playerItem, this.logic);
// prevent machines placing in multiple sieves if nerf is off to avoid confusion
if ((realPlayer || !EConfig.SERVER.nerfAutomatedSieves.get()) && canUseSimultaneously()) {
@ -148,7 +149,11 @@ public abstract class AbstractSieveBlockEntity extends EBlockEntity implements S
for (int x = -range; x <= range; x++) {
for (int z = -range; z <= range; z++) {
if (playerItem.isEmpty()) {
break otherSieves;
playerItem = restockSieveMaterial(player, hand, usedItem);
if (playerItem.isEmpty()) {
break otherSieves;
}
}
if ((x | z) != 0) {
@ -157,7 +162,7 @@ public abstract class AbstractSieveBlockEntity extends EBlockEntity implements S
if (otherLogic.getContents().isEmpty()) {
if (this.logic.getMesh().getItem() == otherLogic.getMesh().getItem()) {
playerItem = insertContents(player, hand, otherLogic);
insertContents(player, playerItem, otherLogic);
}
}
}
@ -202,25 +207,35 @@ public abstract class AbstractSieveBlockEntity extends EBlockEntity implements S
return InteractionResult.sidedSuccess(isClientSide);
}
// Fills the sieve (assumes contents is EMPTY) and returns the remaining item, putting it in the player's hand
public static ItemStack insertContents(Player player, InteractionHand hand, SieveLogic logic) {
var consume = !player.getAbilities().instabuild;
var playerItem = player.getItemInHand(hand);
// search for another stack in inventory and restock held item
private static ItemStack restockSieveMaterial(Player player, InteractionHand hand, Item usedItem) {
var inventory = player.getInventory();
var inventorySize = inventory.getContainerSize();
if (consume) {
if (playerItem.getCount() == 1) {
logic.startSifting(playerItem);
player.setItemInHand(hand, ItemStack.EMPTY);
playerItem = ItemStack.EMPTY;
} else {
logic.startSifting(singleCopy(playerItem));
playerItem.shrink(1);
for (int i = 0; i < inventorySize; i++) {
var stack = inventory.getItem(i);
if (stack.is(usedItem)) {
stack = stack.copy();
player.setItemInHand(hand, stack);
inventory.setItem(i, ItemStack.EMPTY);
return stack;
}
} else {
logic.startSifting(singleCopy(playerItem));
}
return playerItem;
return ItemStack.EMPTY;
}
// Fills the sieve (assumes contents is EMPTY) and returns the remaining item, putting it in the player's hand
public static void insertContents(Player player, ItemStack playerItem, SieveLogic logic) {
var consume = !player.getAbilities().instabuild;
logic.startSifting(singleCopy(playerItem));
player.awardStat(Stats.ITEM_USED.get(playerItem.getItem()));
if (consume) {
playerItem.shrink(1);
}
}
// Do not call on client side