external storage has nice storage GUI now too
This commit is contained in:
@@ -5,7 +5,6 @@ public final class StorageCraftGUI
|
||||
public static final int CONTROLLER = 0;
|
||||
public static final int GRID = 1;
|
||||
public static final int DRIVE = 2;
|
||||
public static final int EXTERNAL_STORAGE = 3;
|
||||
public static final int IMPORTER = 4;
|
||||
public static final int EXPORTER = 5;
|
||||
public static final int DETECTOR = 6;
|
||||
|
@@ -28,7 +28,7 @@ public class BlockExternalStorage extends BlockMachine
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
player.openGui(StorageCraft.INSTANCE, StorageCraftGUI.EXTERNAL_STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
|
||||
player.openGui(StorageCraft.INSTANCE, StorageCraftGUI.STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -1,13 +0,0 @@
|
||||
package storagecraft.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class ContainerExternalStorage extends ContainerBase
|
||||
{
|
||||
public ContainerExternalStorage(EntityPlayer player)
|
||||
{
|
||||
super(player);
|
||||
|
||||
addPlayerInventory(8, 50);
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package storagecraft.gui;
|
||||
|
||||
import storagecraft.container.ContainerExternalStorage;
|
||||
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import storagecraft.tile.TileExternalStorage;
|
||||
|
||||
public class GuiExternalStorage extends GuiBase
|
||||
{
|
||||
private TileExternalStorage externalStorage;
|
||||
|
||||
public GuiExternalStorage(ContainerExternalStorage container, TileExternalStorage externalStorage)
|
||||
{
|
||||
super(container, 176, 131);
|
||||
|
||||
this.externalStorage = externalStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int x, int y)
|
||||
{
|
||||
addSideButton(new SideButtonRedstoneMode(externalStorage));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||
{
|
||||
bindTexture("gui/external_storage.png");
|
||||
|
||||
drawTexture(x, y, 0, 0, xSize, ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
drawString(7, 7, t("gui.storagecraft:external_storage"));
|
||||
drawString(7, 39, t("container.inventory"));
|
||||
}
|
||||
}
|
@@ -8,8 +8,8 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import storagecraft.StorageCraftGUI;
|
||||
import storagecraft.container.*;
|
||||
import storagecraft.tile.*;
|
||||
import storagecraft.storage.IStorageGui;
|
||||
import storagecraft.tile.*;
|
||||
|
||||
public class GuiHandler implements IGuiHandler
|
||||
{
|
||||
@@ -23,8 +23,6 @@ public class GuiHandler implements IGuiHandler
|
||||
return new ContainerGrid(player, (TileGrid) tile);
|
||||
case StorageCraftGUI.DRIVE:
|
||||
return new ContainerDrive(player, (TileDrive) tile);
|
||||
case StorageCraftGUI.EXTERNAL_STORAGE:
|
||||
return new ContainerExternalStorage(player);
|
||||
case StorageCraftGUI.IMPORTER:
|
||||
return new ContainerImporter(player, (TileImporter) tile);
|
||||
case StorageCraftGUI.EXPORTER:
|
||||
@@ -65,8 +63,6 @@ public class GuiHandler implements IGuiHandler
|
||||
return new GuiGrid((ContainerGrid) getContainer(ID, player, tile), (TileGrid) tile);
|
||||
case StorageCraftGUI.DRIVE:
|
||||
return new GuiDrive((ContainerDrive) getContainer(ID, player, tile), (TileDrive) tile);
|
||||
case StorageCraftGUI.EXTERNAL_STORAGE:
|
||||
return new GuiExternalStorage((ContainerExternalStorage) getContainer(ID, player, tile), (TileExternalStorage) tile);
|
||||
case StorageCraftGUI.IMPORTER:
|
||||
return new GuiImporter((ContainerImporter) getContainer(ID, player, tile), (TileImporter) tile);
|
||||
case StorageCraftGUI.EXPORTER:
|
||||
|
@@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import storagecraft.tile.TileExternalStorage;
|
||||
import storagecraft.tile.TileStorage;
|
||||
|
||||
public class MessageStoragePriorityUpdate extends MessageHandlerPlayerToServer<MessageStoragePriorityUpdate> implements IMessage
|
||||
@@ -53,5 +54,9 @@ public class MessageStoragePriorityUpdate extends MessageHandlerPlayerToServer<M
|
||||
{
|
||||
((TileStorage) tile).setPriority(message.priority);
|
||||
}
|
||||
else if (tile instanceof TileExternalStorage)
|
||||
{
|
||||
((TileExternalStorage) tile).setPriority(message.priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +1,32 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.List;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.network.MessageStoragePriorityUpdate;
|
||||
import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageGui;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileExternalStorage extends TileMachine implements IStorageProvider, IStorage
|
||||
public class TileExternalStorage extends TileMachine implements IStorageProvider, IStorage, IStorageGui
|
||||
{
|
||||
public IInventory getInventory()
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(pos.offset(getDirection()));
|
||||
public static final String NBT_PRIORITY = "Priority";
|
||||
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
return (IInventory) tile;
|
||||
}
|
||||
private InventorySimple inventory = new InventorySimple("external_storage", 9);
|
||||
|
||||
return null;
|
||||
}
|
||||
private int priority = 0;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private int stored = 0;
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage()
|
||||
@@ -37,15 +42,15 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
@Override
|
||||
public void addItems(List<StorageItem> items)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
IInventory connectedInventory = getConnectedInventory();
|
||||
|
||||
if (inventory != null)
|
||||
if (connectedInventory != null)
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
for (int i = 0; i < connectedInventory.getSizeInventory(); ++i)
|
||||
{
|
||||
if (inventory.getStackInSlot(i) != null)
|
||||
if (connectedInventory.getStackInSlot(i) != null)
|
||||
{
|
||||
items.add(new StorageItem(inventory.getStackInSlot(i)));
|
||||
items.add(new StorageItem(connectedInventory.getStackInSlot(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,31 +59,31 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
@Override
|
||||
public void push(ItemStack stack)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
IInventory connectedInventory = getConnectedInventory();
|
||||
|
||||
if (inventory == null)
|
||||
if (connectedInventory == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryUtils.pushToInventory(inventory, stack);
|
||||
InventoryUtils.pushToInventory(connectedInventory, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack take(ItemStack stack, int flags)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
IInventory connectedInventory = getConnectedInventory();
|
||||
|
||||
if (inventory == null)
|
||||
if (connectedInventory == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int quantity = stack.stackSize;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
for (int i = 0; i < connectedInventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
ItemStack slot = connectedInventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null && InventoryUtils.compareStack(slot, stack, flags))
|
||||
{
|
||||
@@ -91,7 +96,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
|
||||
if (slot.stackSize == 0)
|
||||
{
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
connectedInventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
ItemStack newItem = slot.copy();
|
||||
@@ -108,21 +113,78 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
@Override
|
||||
public boolean canPush(ItemStack stack)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
IInventory connectedInventory = getConnectedInventory();
|
||||
|
||||
if (inventory == null)
|
||||
if (connectedInventory == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return InventoryUtils.canPushToInventory(inventory, stack);
|
||||
return InventoryUtils.canPushToInventory(connectedInventory, stack);
|
||||
}
|
||||
|
||||
public IInventory getConnectedInventory()
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(pos.offset(getDirection()));
|
||||
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
return (IInventory) tile;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
super.toBytes(buf);
|
||||
|
||||
buf.writeInt(priority);
|
||||
buf.writeInt(getConnectedInventory() == null ? 0 : InventoryUtils.getInventoryItems(getConnectedInventory()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
super.fromBytes(buf);
|
||||
|
||||
priority = buf.readInt();
|
||||
stored = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
InventoryUtils.restoreInventory(inventory, nbt);
|
||||
|
||||
if (nbt.hasKey(NBT_PRIORITY))
|
||||
{
|
||||
priority = nbt.getInteger(NBT_PRIORITY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
InventoryUtils.saveInventory(inventory, nbt);
|
||||
|
||||
nbt.setInteger(NBT_PRIORITY, priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
// @TODO: Priority on this stuff
|
||||
return 0;
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority)
|
||||
{
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,4 +192,58 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
{
|
||||
storages.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "gui.storagecraft:external_storage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorage getStorage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRedstoneModeSetting getRedstoneModeSetting()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored()
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
if (getConnectedInventory() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getConnectedInventory().getSizeInventory() * 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPriorityHandler getPriorityHandler()
|
||||
{
|
||||
return new IPriorityHandler()
|
||||
{
|
||||
@Override
|
||||
public void onPriorityChanged(int priority)
|
||||
{
|
||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePriorityUpdate(pos, priority));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventory()
|
||||
{
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
|
@@ -199,6 +199,23 @@ public class InventoryUtils
|
||||
return toGo == 0;
|
||||
}
|
||||
|
||||
public static int getInventoryItems(IInventory inventory)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null)
|
||||
{
|
||||
size += slot.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public static boolean compareStack(ItemStack first, ItemStack second)
|
||||
{
|
||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user