Fix slot issues
This commit is contained in:
@@ -7,9 +7,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
import refinedstorage.container.slot.SlotDisabled;
|
import refinedstorage.container.slot.*;
|
||||||
import refinedstorage.container.slot.SlotSpecimen;
|
|
||||||
import refinedstorage.container.slot.SlotSpecimenLegacy;
|
|
||||||
import refinedstorage.tile.TileBase;
|
import refinedstorage.tile.TileBase;
|
||||||
import refinedstorage.tile.grid.WirelessGrid;
|
import refinedstorage.tile.grid.WirelessGrid;
|
||||||
|
|
||||||
@@ -109,15 +107,17 @@ public abstract class ContainerBase extends Container {
|
|||||||
|
|
||||||
protected ItemStack mergeItemStackToSpecimen(ItemStack stack, int begin, int end) {
|
protected ItemStack mergeItemStackToSpecimen(ItemStack stack, int begin, int end) {
|
||||||
for (int i = begin; i < end; ++i) {
|
for (int i = begin; i < end; ++i) {
|
||||||
if (CompareUtils.compareStackNoQuantity(getSlot(i).getStack(), stack)) {
|
if (CompareUtils.compareStackNoQuantity(getStackFromSlot(getSlot(i)), stack)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = begin; i < end; ++i) {
|
for (int i = begin; i < end; ++i) {
|
||||||
if (!getSlot(i).getHasStack() && getSlot(i).isItemValid(stack)) {
|
Slot slot = getSlot(i);
|
||||||
getSlot(i).putStack(ItemHandlerHelper.copyStackWithSize(stack, 1));
|
|
||||||
getSlot(i).onSlotChanged();
|
if (getStackFromSlot(slot) == null && slot.isItemValid(stack)) {
|
||||||
|
slot.putStack(ItemHandlerHelper.copyStackWithSize(stack, 1));
|
||||||
|
slot.onSlotChanged();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -126,6 +126,20 @@ public abstract class ContainerBase extends Container {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ItemStack getStackFromSlot(Slot slot) {
|
||||||
|
ItemStack stackInSlot = slot.getStack();
|
||||||
|
|
||||||
|
if (stackInSlot == null) {
|
||||||
|
if (slot instanceof SlotSpecimenFluid) {
|
||||||
|
stackInSlot = ((SlotSpecimenFluid) slot).getRealStack();
|
||||||
|
} else if (slot instanceof SlotSpecimenType) {
|
||||||
|
stackInSlot = ((SlotSpecimenType) slot).getRealStack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stackInSlot;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer player) {
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class SlotSpecimen extends SlotItemHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack stack) {
|
public boolean isItemValid(ItemStack stack) {
|
||||||
return isBlockOnly() ? (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable) : true;
|
return super.isItemValid(stack) && (isBlockOnly() ? (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable) : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
package refinedstorage.container.slot;
|
package refinedstorage.container.slot;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.SlotItemHandler;
|
|
||||||
|
|
||||||
/**
|
public class SlotSpecimenFluid extends SlotSpecimen {
|
||||||
* Created by Raoul on 13/08/2016.
|
private boolean server;
|
||||||
*/
|
|
||||||
// @TODO: REMOVAL
|
public SlotSpecimenFluid(boolean server, IItemHandler handler, int id, int x, int y) {
|
||||||
public class SlotSpecimenFluid extends SlotItemHandler {
|
super(handler, id, x, y);
|
||||||
public SlotSpecimenFluid(boolean b, IItemHandler filters, int i, int i1, int i2) {
|
|
||||||
super(filters, i, i1, i2);
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStack() {
|
||||||
|
return server ? super.getStack() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getRealStack() {
|
||||||
|
return super.getStack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,4 +37,8 @@ public class SlotSpecimenType extends SlotSpecimen {
|
|||||||
public ItemStack getStack() {
|
public ItemStack getStack() {
|
||||||
return (type.getType() == IType.ITEMS || !((TileEntity) type).getWorld().isRemote) ? super.getStack() : null;
|
return (type.getType() == IType.ITEMS || !((TileEntity) type).getWorld().isRemote) ? super.getStack() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemStack getRealStack() {
|
||||||
|
return super.getStack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user