Fix external storage bug

This commit is contained in:
Raoul Van den Berge
2016-05-22 00:32:52 +02:00
parent 89084aea38
commit 398cc02924

View File

@@ -48,6 +48,13 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
@Override
public void addItems(List<ItemGroup> items) {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
if (storageUnit.getStoredItemType() != null) {
items.add(new ItemGroup(storageUnit.getStoredItemType().copy()));
}
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
@@ -56,18 +63,21 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
items.add(new ItemGroup(handler.getStackInSlot(i).copy()));
}
}
} else {
IDeepStorageUnit storageUnit = getStorageUnit();
// @todo: doesn't work
if (storageUnit != null && storageUnit.getStoredItemType() != null) {
items.add(new ItemGroup(storageUnit.getStoredItemType().copy()));
}
}
}
@Override
public void push(ItemStack stack) {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
if (storageUnit.getStoredItemType() == null) {
storageUnit.setStoredItemType(stack, stack.stackSize);
} else {
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize + stack.stackSize);
}
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
@@ -76,23 +86,32 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
break;
}
}
} else {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit.getStoredItemType() == null) {
storageUnit.setStoredItemType(stack, stack.stackSize);
} else {
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize + stack.stackSize);
}
}
}
@Override
public ItemStack take(ItemStack stack, int flags) {
IItemHandler handler = getItemHandler();
int quantity = stack.stackSize;
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
if (storageUnit.getStoredItemType() != null && RefinedStorageUtils.compareStackNoQuantity(storageUnit.getStoredItemType(), stack)) {
if (quantity > storageUnit.getStoredItemType().stackSize) {
quantity = storageUnit.getStoredItemType().stackSize;
}
ItemStack took = storageUnit.getStoredItemType().copy();
took.stackSize = quantity;
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize - quantity);
return took;
}
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
for (int i = 0; i < handler.getSlots(); ++i) {
ItemStack slot = handler.getStackInSlot(i);
@@ -110,20 +129,6 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
return took;
}
}
} else {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit.getStoredItemType() != null && RefinedStorageUtils.compareStackNoQuantity(storageUnit.getStoredItemType(), stack)) {
if (quantity > storageUnit.getStoredItemType().stackSize) {
quantity = storageUnit.getStoredItemType().stackSize;
}
ItemStack took = storageUnit.getStoredItemType().copy();
took.stackSize = quantity;
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize - quantity);
return took;
}
}
@@ -133,15 +138,6 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
@Override
public boolean mayPush(ItemStack stack) {
if (ModeConfigUtils.doesNotViolateMode(inventory, this, compare, stack)) {
IItemHandler handler = getItemHandler();
if (handler != null) {
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.insertItem(i, stack, true) == null) {
return true;
}
}
} else {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
@@ -150,6 +146,15 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
}
return RefinedStorageUtils.compareStackNoQuantity(storageUnit.getStoredItemType(), stack) && (storageUnit.getStoredItemType().stackSize + stack.stackSize) < storageUnit.getMaxStoredCount();
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.insertItem(i, stack, true) == null) {
return true;
}
}
}
}
}
@@ -157,14 +162,16 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
return false;
}
public IItemHandler getItemHandler() {
return RefinedStorageUtils.getItemHandler(worldObj.getTileEntity(pos.offset(getDirection())), getDirection().getOpposite());
public TileEntity getFront() {
return worldObj.getTileEntity(pos.offset(getDirection()));
}
public IDeepStorageUnit getStorageUnit() {
TileEntity front = worldObj.getTileEntity(pos.offset(getDirection()));
return getFront() instanceof IDeepStorageUnit ? (IDeepStorageUnit) getFront() : null;
}
return front instanceof IDeepStorageUnit ? (IDeepStorageUnit) front : null;
public IItemHandler getItemHandler() {
return RefinedStorageUtils.getItemHandler(getFront(), getDirection().getOpposite());
}
@Override
@@ -173,6 +180,11 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
buf.writeInt(priority);
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
buf.writeInt(storageUnit.getStoredItemType() == null ? 0 : storageUnit.getStoredItemType().stackSize);
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
@@ -185,11 +197,6 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
}
buf.writeInt(amount);
} else {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
buf.writeInt(storageUnit.getStoredItemType() == null ? 0 : storageUnit.getStoredItemType().stackSize);
} else {
buf.writeInt(0);
}
@@ -323,15 +330,15 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
@Override
public int getCapacity() {
IItemHandler handler = getItemHandler();
if (handler != null) {
return handler.getSlots() * 64;
} else {
IDeepStorageUnit storageUnit = getStorageUnit();
if (storageUnit != null) {
return storageUnit.getMaxStoredCount();
} else {
IItemHandler handler = getItemHandler();
if (handler != null) {
return handler.getSlots() * 64;
}
}