Transceiver item buffers would allow multiple non-stackable items of the same type

This commit is contained in:
CrazyPants committed 2014-10-30 11:12:13 +08:00
1 parent ac8b7c3493
commit e425a8e370
4 files changed
+28 -11

No files matched your search

@@ -216,13 +216,13 @@ public class ServerChannelRegister extends ChannelRegister {
private ItemStack sendItem(TileTransceiver from, int slot, ItemStack contents, TileTransceiver to) {
SlotDefinition sd = to.getSlotDefinition();
//try merging into existing stacks
boolean recieverHasItem = false; // Only allow 1 stack per item type
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot && !recieverHasItem; i++) {
//try merging into existing stacks
boolean sendComplete = false; // Only allow 1 stack per item type
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot && !sendComplete; i++) {
ItemStack existing = to.getStackInSlot(i);
if(ItemUtil.areStackTypesEqual(existing, contents)) {
recieverHasItem = true;
if(ItemUtil.areStacksEqual(existing, contents)) {
sendComplete = true;
int numCanMerge = existing.getMaxStackSize() - existing.stackSize;
numCanMerge = Math.min(numCanMerge, contents.stackSize);
ItemStack remaining;
@@ -243,7 +243,7 @@ public class ServerChannelRegister extends ChannelRegister {
}
}
}
if(!recieverHasItem) {
if(!sendComplete) {
//then fill empty stack
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot; i++) {
ItemStack existing = to.getStackInSlot(i);
@@ -479,7 +479,7 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid
if(slotDefinition.isInputSlot(slot)) {
for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) {
if(i != slot) {
if(ItemUtil.areStackTypesEqual(itemstack, getStackInSlot(i))) {
if(ItemUtil.areStacksEqual(itemstack, getStackInSlot(i))) {
return false;
}
}
@@ -487,7 +487,7 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid
} else if(slotDefinition.isOutputSlot(slot)) {
for (int i = slotDefinition.getMinOutputSlot(); i <= slotDefinition.getMaxOutputSlot(); i++) {
if(i != slot) {
if(ItemUtil.areStackTypesEqual(itemstack, getStackInSlot(i))) {
if(ItemUtil.areStacksEqual(itemstack, getStackInSlot(i))) {
return false;
}
}
+18 -2
View File
@@ -164,14 +164,30 @@ public class ItemUtil {
return inv;
}
/**
* Checks if items, damage and NBT are equal and the items are stackable.
* @param s1
* @param s2
* @return
*/
public static boolean areStackMergable(ItemStack s1, ItemStack s2) {
if(s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) {
return false;
}
if(!s1.isItemEqual(s2)) {
return false;
}
return ItemStack.areItemStackTagsEqual(s1, s2);
}
/**
* Checks if items, damage and NBT are equal.
* @param s1
* @param s2
* @return
*/
public static boolean areStackTypesEqual(ItemStack s1, ItemStack s2) {
if(s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) {
public static boolean areStacksEqual(ItemStack s1, ItemStack s2) {
if(s1 == null || s2 == null) {
return false;
}
if(!s1.isItemEqual(s2)) {