make the storage gui an interface
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
package storagecraft.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import storagecraft.container.slot.SlotSpecimen;
|
||||
import storagecraft.tile.TileStorage;
|
||||
|
||||
public class ContainerStorage extends ContainerBase
|
||||
{
|
||||
public ContainerStorage(EntityPlayer player, TileStorage storage)
|
||||
public ContainerStorage(EntityPlayer player, IInventory inventory)
|
||||
{
|
||||
super(player);
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
addSlotToContainer(new SlotSpecimen(storage, i, 8 + (18 * i), 20));
|
||||
addSlotToContainer(new SlotSpecimen(inventory, i, 8 + (18 * i), 20));
|
||||
}
|
||||
|
||||
addPlayerInventory(8, 129);
|
||||
|
@@ -9,6 +9,7 @@ import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import storagecraft.StorageCraftGUI;
|
||||
import storagecraft.container.*;
|
||||
import storagecraft.tile.*;
|
||||
import storagecraft.storage.IStorageGui;
|
||||
|
||||
public class GuiHandler implements IGuiHandler
|
||||
{
|
||||
@@ -39,7 +40,7 @@ public class GuiHandler implements IGuiHandler
|
||||
case StorageCraftGUI.CONSTRUCTOR:
|
||||
return new ContainerConstructor(player, (TileConstructor) tile);
|
||||
case StorageCraftGUI.STORAGE:
|
||||
return new ContainerStorage(player, (TileStorage) tile);
|
||||
return new ContainerStorage(player, ((IStorageGui) tile).getInventory());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class GuiHandler implements IGuiHandler
|
||||
case StorageCraftGUI.CONSTRUCTOR:
|
||||
return new GuiConstructor((ContainerConstructor) getContainer(ID, player, tile), (TileConstructor) tile);
|
||||
case StorageCraftGUI.STORAGE:
|
||||
return new GuiStorage((ContainerStorage) getContainer(ID, player, tile), (TileStorage) tile);
|
||||
return new GuiStorage((ContainerStorage) getContainer(ID, player, tile), (IStorageGui) tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@@ -3,16 +3,13 @@ package storagecraft.gui;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.block.EnumStorageType;
|
||||
import storagecraft.container.ContainerStorage;
|
||||
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import storagecraft.network.MessageStoragePriorityUpdate;
|
||||
import storagecraft.tile.TileStorage;
|
||||
import storagecraft.storage.IStorageGui;
|
||||
|
||||
public class GuiStorage extends GuiBase
|
||||
{
|
||||
private TileStorage storage;
|
||||
private IStorageGui gui;
|
||||
|
||||
private GuiTextField priorityField;
|
||||
|
||||
@@ -21,20 +18,23 @@ public class GuiStorage extends GuiBase
|
||||
private int barWidth = 16;
|
||||
private int barHeight = 58;
|
||||
|
||||
public GuiStorage(ContainerStorage container, TileStorage storage)
|
||||
public GuiStorage(ContainerStorage container, IStorageGui gui)
|
||||
{
|
||||
super(container, 176, 211);
|
||||
|
||||
this.storage = storage;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int x, int y)
|
||||
{
|
||||
addSideButton(new SideButtonRedstoneMode(storage));
|
||||
if (gui.getRedstoneModeSetting() != null)
|
||||
{
|
||||
addSideButton(new SideButtonRedstoneMode(gui.getRedstoneModeSetting()));
|
||||
}
|
||||
|
||||
priorityField = new GuiTextField(0, fontRendererObj, x + 116 + 1, y + 54 + 1, 25, fontRendererObj.FONT_HEIGHT);
|
||||
priorityField.setText(String.valueOf(storage.getPriority()));
|
||||
priorityField.setText(String.valueOf(gui.getStorage().getPriority()));
|
||||
priorityField.setEnableBackgroundDrawing(false);
|
||||
priorityField.setVisible(true);
|
||||
priorityField.setTextColor(16777215);
|
||||
@@ -54,7 +54,7 @@ public class GuiStorage extends GuiBase
|
||||
|
||||
drawTexture(x, y, 0, 0, xSize, ySize);
|
||||
|
||||
int barHeightNew = storage.getStoredScaled(barHeight);
|
||||
int barHeightNew = (int) ((float) gui.getStored() / (float) gui.getCapacity() * (float) barHeight);
|
||||
|
||||
drawTexture(x + barX, y + barY + barHeight - barHeightNew, 179, 0 + (barHeight - barHeightNew), barWidth, barHeightNew);
|
||||
|
||||
@@ -64,21 +64,21 @@ public class GuiStorage extends GuiBase
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY)
|
||||
{
|
||||
drawString(7, 7, t("block.storagecraft:storage." + storage.getType().getId() + ".name"));
|
||||
drawString(7, 7, t(gui.getName()));
|
||||
drawString(7, 42, t("misc.storagecraft:storage"));
|
||||
drawString(115, 42, t("misc.storagecraft:priority"));
|
||||
drawString(7, 117, t("container.inventory"));
|
||||
|
||||
drawString(30, 54, t("misc.storagecraft:storage.stored", storage.getStored()));
|
||||
drawString(30, 54, t("misc.storagecraft:storage.stored", gui.getStored()));
|
||||
|
||||
if (storage.getType() != EnumStorageType.TYPE_CREATIVE)
|
||||
if (gui.getCapacity() != -1)
|
||||
{
|
||||
drawString(30, 64, t("misc.storagecraft:storage.capacity", storage.getType().getCapacity()));
|
||||
drawString(30, 64, t("misc.storagecraft:storage.capacity", gui.getCapacity()));
|
||||
}
|
||||
|
||||
if (inBounds(barX, barY, barWidth, barHeight, mouseX, mouseY))
|
||||
{
|
||||
drawTooltip(mouseX, mouseY, t("misc.storagecraft:storage.full", storage.getStoredScaled(100)));
|
||||
drawTooltip(mouseX, mouseY, t("misc.storagecraft:storage.full", (int) ((float) gui.getStored() / (float) gui.getCapacity() * 100f)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class GuiStorage extends GuiBase
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePriorityUpdate(storage, result));
|
||||
gui.getPriorityHandler().onPriorityChanged(result);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -18,11 +18,11 @@ public class MessageStoragePriorityUpdate extends MessageHandlerPlayerToServer<M
|
||||
{
|
||||
}
|
||||
|
||||
public MessageStoragePriorityUpdate(TileStorage storage, int priority)
|
||||
public MessageStoragePriorityUpdate(BlockPos pos, int priority)
|
||||
{
|
||||
this.x = storage.getPos().getX();
|
||||
this.y = storage.getPos().getY();
|
||||
this.z = storage.getPos().getZ();
|
||||
this.x = pos.getX();
|
||||
this.y = pos.getY();
|
||||
this.z = pos.getZ();
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
|
26
src/main/java/storagecraft/storage/IStorageGui.java
Normal file
26
src/main/java/storagecraft/storage/IStorageGui.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package storagecraft.storage;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import storagecraft.tile.IRedstoneModeSetting;
|
||||
|
||||
public interface IStorageGui
|
||||
{
|
||||
public interface IPriorityHandler
|
||||
{
|
||||
public void onPriorityChanged(int priority);
|
||||
}
|
||||
|
||||
public String getName();
|
||||
|
||||
public IStorage getStorage();
|
||||
|
||||
public IInventory getInventory();
|
||||
|
||||
public IRedstoneModeSetting getRedstoneModeSetting();
|
||||
|
||||
public int getStored();
|
||||
|
||||
public int getCapacity();
|
||||
|
||||
public IPriorityHandler getPriorityHandler();
|
||||
}
|
@@ -2,25 +2,24 @@ package storagecraft.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.block.BlockStorage;
|
||||
import storagecraft.block.EnumStorageType;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.network.MessageStoragePriorityUpdate;
|
||||
import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageGui;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.NBTStorage;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileStorage extends TileMachine implements IStorageProvider, IStorage, IInventory, ISidedInventory
|
||||
public class TileStorage extends TileMachine implements IStorageProvider, IStorage, IStorageGui
|
||||
{
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
public static final String NBT_PRIORITY = "Priority";
|
||||
@@ -56,7 +55,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
InventoryUtils.restoreInventory(this, nbt);
|
||||
InventoryUtils.restoreInventory(inventory, nbt);
|
||||
|
||||
if (nbt.hasKey(NBT_STORAGE))
|
||||
{
|
||||
@@ -80,41 +79,11 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
nbt.setInteger(NBT_PRIORITY, priority);
|
||||
}
|
||||
|
||||
public NBTStorage getStorage()
|
||||
{
|
||||
return new NBTStorage(tag, getType().getCapacity(), priority);
|
||||
}
|
||||
|
||||
public EnumStorageType getType()
|
||||
{
|
||||
return ((EnumStorageType) worldObj.getBlockState(pos).getValue(BlockStorage.TYPE));
|
||||
}
|
||||
|
||||
public int getStored()
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
public int getStoredScaled(int scale)
|
||||
{
|
||||
if (getType() == EnumStorageType.TYPE_CREATIVE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) ((float) getStored() / (float) getType().getCapacity() * (float) scale);
|
||||
}
|
||||
|
||||
public int getPriority()
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority)
|
||||
{
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
@@ -165,125 +134,73 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
return getStorage().canPush(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int count)
|
||||
{
|
||||
return inventory.decrStackSize(slot, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot)
|
||||
{
|
||||
return inventory.removeStackFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player)
|
||||
{
|
||||
inventory.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player)
|
||||
{
|
||||
inventory.closeInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id)
|
||||
{
|
||||
return inventory.getField(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value)
|
||||
{
|
||||
inventory.setField(id, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return inventory.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return inventory.getName();
|
||||
return "block.storagecraft:storage." + getType().getId() + ".name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
public IInventory getInventory()
|
||||
{
|
||||
return inventory.hasCustomName();
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatComponent getDisplayName()
|
||||
public IRedstoneModeSetting getRedstoneModeSetting()
|
||||
{
|
||||
return inventory.getDisplayName();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSlotsForFace(EnumFacing side)
|
||||
public IPriorityHandler getPriorityHandler()
|
||||
{
|
||||
return new int[]
|
||||
return new IPriorityHandler()
|
||||
{
|
||||
@Override
|
||||
public void onPriorityChanged(int priority)
|
||||
{
|
||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePriorityUpdate(pos, priority));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing direction)
|
||||
public NBTStorage getStorage()
|
||||
{
|
||||
return false;
|
||||
return new NBTStorage(tag, getCapacity(), priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
|
||||
public int getPriority()
|
||||
{
|
||||
return false;
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority)
|
||||
{
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored()
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
public int getStoredScaled(int scale)
|
||||
{
|
||||
if (getType() == EnumStorageType.TYPE_CREATIVE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) ((float) getStored() / (float) getCapacity() * (float) scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
return getType().getCapacity();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user