Fix storage units wrenching. Closes #2889
This commit is contained in:
parent
554a63dbba
commit
e30d618d86
2 changed files with 38 additions and 26 deletions
|
@ -183,7 +183,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
|
|
||||||
public ItemStack processInput(ItemStack inputStack) {
|
public ItemStack processInput(ItemStack inputStack) {
|
||||||
|
|
||||||
boolean isSameStack = isSameType(inputStack);
|
boolean isSameStack = canAcceptStack(inputStack);
|
||||||
|
|
||||||
if (storeItemStack == ItemStack.EMPTY && (isSameStack || (getCurrentCapacity() == 0 && !isLocked()))) {
|
if (storeItemStack == ItemStack.EMPTY && (isSameStack || (getCurrentCapacity() == 0 && !isLocked()))) {
|
||||||
// Check if storage is empty, NOT including the output slot
|
// Check if storage is empty, NOT including the output slot
|
||||||
|
@ -218,15 +218,19 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
return inputStack;
|
return inputStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSameType(ItemStack inputStack) {
|
public boolean canAcceptStack(ItemStack inputStack) {
|
||||||
|
if (inputStack == ItemStack.EMPTY){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (isLocked()) {
|
if (isLocked()) {
|
||||||
return ItemUtils.isItemEqual(lockedItemStack, inputStack, true, true);
|
return ItemUtils.isItemEqual(lockedItemStack, inputStack, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputStack != ItemStack.EMPTY) {
|
if (isEmpty()){
|
||||||
return ItemUtils.isItemEqual(getStoredStack(), inputStack, true, true);
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return ItemUtils.isItemEqual(getStoredStack(), inputStack, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creative function
|
// Creative function
|
||||||
|
@ -284,7 +288,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(int index, ItemStack stack, @Nullable Direction direction) {
|
public boolean canInsert(int index, ItemStack stack, @Nullable Direction direction) {
|
||||||
return super.canInsert(index, stack, direction) && (this.isEmpty() && !isLocked() || isSameType(stack));
|
return super.canInsert(index, stack, direction) && (this.isEmpty() && !isLocked() || canAcceptStack(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -385,7 +389,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (slot == INPUT_SLOT && !(isEmpty() || isSameType(stack))) {
|
if (slot == INPUT_SLOT && !(isEmpty() || canAcceptStack(stack))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return super.isValid(slot, stack);
|
return super.isValid(slot, stack);
|
||||||
|
|
|
@ -30,8 +30,6 @@ 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.Items;
|
|
||||||
import net.minecraft.item.ToolItem;
|
|
||||||
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;
|
||||||
|
@ -44,6 +42,7 @@ import reborncore.common.util.WorldUtils;
|
||||||
import techreborn.blockentity.GuiType;
|
import techreborn.blockentity.GuiType;
|
||||||
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
|
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
|
||||||
import techreborn.init.TRContent;
|
import techreborn.init.TRContent;
|
||||||
|
import techreborn.items.tool.WrenchItem;
|
||||||
|
|
||||||
public class StorageUnitBlock extends BlockMachineBase {
|
public class StorageUnitBlock extends BlockMachineBase {
|
||||||
|
|
||||||
|
@ -66,23 +65,32 @@ public class StorageUnitBlock extends BlockMachineBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) worldIn.getBlockEntity(pos);
|
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) worldIn.getBlockEntity(pos);
|
||||||
ItemStack stackInHand = playerIn.getStackInHand(Hand.MAIN_HAND);
|
if (storageEntity == null) {
|
||||||
Item itemInHand = stackInHand.getItem();
|
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
||||||
|
|
||||||
if (storageEntity != null && itemInHand != Items.AIR && (storageEntity.isSameType(stackInHand) && !storageEntity.isFull() ||
|
|
||||||
(!storageEntity.isLocked() && storageEntity.isEmpty() && (!(itemInHand instanceof ToolItem))))) {
|
|
||||||
|
|
||||||
// Add item which is the same type (in users inventory) into storage
|
|
||||||
for (int i = 0; i < playerIn.getInventory().size() && !storageEntity.isFull(); i++) {
|
|
||||||
ItemStack curStack = playerIn.getInventory().getStack(i);
|
|
||||||
if (curStack.getItem() == itemInHand) {
|
|
||||||
playerIn.getInventory().setStack(i, storageEntity.processInput(curStack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ActionResult.SUCCESS;
|
|
||||||
}
|
}
|
||||||
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
if (storageEntity.isFull()) {
|
||||||
|
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stackInHand = playerIn.getStackInHand(Hand.MAIN_HAND);
|
||||||
|
if (!storageEntity.canAcceptStack(stackInHand)) {
|
||||||
|
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
Item itemInHand = stackInHand.getItem();
|
||||||
|
if (itemInHand instanceof WrenchItem){
|
||||||
|
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add item which is the same type (in users inventory) into storage
|
||||||
|
for (int i = 0; i < playerIn.getInventory().size() && !storageEntity.isFull(); i++) {
|
||||||
|
ItemStack curStack = playerIn.getInventory().getStack(i);
|
||||||
|
if (curStack.getItem() == itemInHand) {
|
||||||
|
playerIn.getInventory().setStack(i, storageEntity.processInput(curStack));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,7 +102,7 @@ public class StorageUnitBlock extends BlockMachineBase {
|
||||||
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
|
final StorageUnitBaseBlockEntity storageEntity = (StorageUnitBaseBlockEntity) world.getBlockEntity(pos);
|
||||||
ItemStack stackInHand = player.getStackInHand(Hand.MAIN_HAND);
|
ItemStack stackInHand = player.getStackInHand(Hand.MAIN_HAND);
|
||||||
|
|
||||||
if (storageEntity != null && (stackInHand.isEmpty() || storageEntity.isSameType(stackInHand)) && !storageEntity.isEmpty()) {
|
if (storageEntity != null && (stackInHand.isEmpty() || storageEntity.canAcceptStack(stackInHand)) && !storageEntity.isEmpty()) {
|
||||||
RebornInventory<StorageUnitBaseBlockEntity> inventory = storageEntity.getInventory();
|
RebornInventory<StorageUnitBaseBlockEntity> inventory = storageEntity.getInventory();
|
||||||
ItemStack out = inventory.getStack(StorageUnitBaseBlockEntity.OUTPUT_SLOT);
|
ItemStack out = inventory.getStack(StorageUnitBaseBlockEntity.OUTPUT_SLOT);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue