Fix external storage bug
This commit is contained in:
@@ -48,6 +48,13 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItems(List<ItemGroup> items) {
|
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();
|
IItemHandler handler = getItemHandler();
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
@@ -56,18 +63,21 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
items.add(new ItemGroup(handler.getStackInSlot(i).copy()));
|
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
|
@Override
|
||||||
public void push(ItemStack stack) {
|
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();
|
IItemHandler handler = getItemHandler();
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
@@ -76,23 +86,32 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
IDeepStorageUnit storageUnit = getStorageUnit();
|
|
||||||
|
|
||||||
if (storageUnit.getStoredItemType() == null) {
|
|
||||||
storageUnit.setStoredItemType(stack, stack.stackSize);
|
|
||||||
} else {
|
|
||||||
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize + stack.stackSize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int flags) {
|
||||||
IItemHandler handler = getItemHandler();
|
|
||||||
|
|
||||||
int quantity = stack.stackSize;
|
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) {
|
if (handler != null) {
|
||||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||||
ItemStack slot = handler.getStackInSlot(i);
|
ItemStack slot = handler.getStackInSlot(i);
|
||||||
@@ -110,20 +129,6 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
return took;
|
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
|
@Override
|
||||||
public boolean mayPush(ItemStack stack) {
|
public boolean mayPush(ItemStack stack) {
|
||||||
if (ModeConfigUtils.doesNotViolateMode(inventory, this, compare, 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();
|
IDeepStorageUnit storageUnit = getStorageUnit();
|
||||||
|
|
||||||
if (storageUnit != null) {
|
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();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItemHandler getItemHandler() {
|
public TileEntity getFront() {
|
||||||
return RefinedStorageUtils.getItemHandler(worldObj.getTileEntity(pos.offset(getDirection())), getDirection().getOpposite());
|
return worldObj.getTileEntity(pos.offset(getDirection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDeepStorageUnit getStorageUnit() {
|
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
|
@Override
|
||||||
@@ -173,6 +180,11 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
|
|
||||||
buf.writeInt(priority);
|
buf.writeInt(priority);
|
||||||
|
|
||||||
|
IDeepStorageUnit storageUnit = getStorageUnit();
|
||||||
|
|
||||||
|
if (storageUnit != null) {
|
||||||
|
buf.writeInt(storageUnit.getStoredItemType() == null ? 0 : storageUnit.getStoredItemType().stackSize);
|
||||||
|
} else {
|
||||||
IItemHandler handler = getItemHandler();
|
IItemHandler handler = getItemHandler();
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
@@ -185,11 +197,6 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf.writeInt(amount);
|
buf.writeInt(amount);
|
||||||
} else {
|
|
||||||
IDeepStorageUnit storageUnit = getStorageUnit();
|
|
||||||
|
|
||||||
if (storageUnit != null) {
|
|
||||||
buf.writeInt(storageUnit.getStoredItemType() == null ? 0 : storageUnit.getStoredItemType().stackSize);
|
|
||||||
} else {
|
} else {
|
||||||
buf.writeInt(0);
|
buf.writeInt(0);
|
||||||
}
|
}
|
||||||
@@ -323,15 +330,15 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCapacity() {
|
public int getCapacity() {
|
||||||
IItemHandler handler = getItemHandler();
|
|
||||||
|
|
||||||
if (handler != null) {
|
|
||||||
return handler.getSlots() * 64;
|
|
||||||
} else {
|
|
||||||
IDeepStorageUnit storageUnit = getStorageUnit();
|
IDeepStorageUnit storageUnit = getStorageUnit();
|
||||||
|
|
||||||
if (storageUnit != null) {
|
if (storageUnit != null) {
|
||||||
return storageUnit.getMaxStoredCount();
|
return storageUnit.getMaxStoredCount();
|
||||||
|
} else {
|
||||||
|
IItemHandler handler = getItemHandler();
|
||||||
|
|
||||||
|
if (handler != null) {
|
||||||
|
return handler.getSlots() * 64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user