Fix retrieval items with NBT. Closes #2810

This commit is contained in:
drcrazy 2022-08-07 02:34:48 +03:00
parent e30d618d86
commit 3509947e93

View file

@ -30,6 +30,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.MiningToolItem;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
@ -100,26 +101,35 @@ public class StorageUnitBlock extends BlockMachineBase {
if (world.isClient) return; if (world.isClient) return;
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos); final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
ItemStack stackInHand = player.getStackInHand(Hand.MAIN_HAND); if (storageEntity == null) {
return;
if (storageEntity != null && (stackInHand.isEmpty() || storageEntity.canAcceptStack(stackInHand)) && !storageEntity.isEmpty()) { }
RebornInventory<StorageUnitBaseBlockEntity> inventory = storageEntity.getInventory(); if (storageEntity.isEmpty()) {
ItemStack out = inventory.getStack(StorageUnitBaseBlockEntity.OUTPUT_SLOT); return;
// Drop stack if sneaking
if (player.isSneaking()) {
WorldUtils.dropItem(new ItemStack(out.getItem()), world, player.getBlockPos());
out.decrement(1);
} else {
WorldUtils.dropItem(out, world, player.getBlockPos());
out.setCount(0);
}
inventory.setHashChanged();
} }
} ItemStack stackInHand = player.getStackInHand(Hand.MAIN_HAND);
// Let's assume that player is trying to break this block, rather than get an item from storage
if (stackInHand.getItem() instanceof MiningToolItem) {
return;
}
RebornInventory<StorageUnitBaseBlockEntity> inventory = storageEntity.getInventory();
ItemStack out = inventory.getStack(StorageUnitBaseBlockEntity.OUTPUT_SLOT);
// Full stack if sneaking
if (player.isSneaking()) {
WorldUtils.dropItem(out, world, player.getBlockPos());
out.setCount(0);
} else {
ItemStack dropStack = out.copy();
dropStack.setCount(1);
WorldUtils.dropItem(dropStack, world, player.getBlockPos());
out.decrement(1);
}
inventory.setHashChanged();
}
@Override @Override
public IMachineGuiHandler getGui() { public IMachineGuiHandler getGui() {