storage block GUI

This commit is contained in:
Raoul Van den Berge
2016-01-31 12:50:15 +01:00
parent e54c062bc3
commit f7a5b533e5
10 changed files with 301 additions and 12 deletions

View File

@@ -13,4 +13,5 @@ public final class StorageCraftGUI
public static final int WIRELESS_TRANSMITTER = 8;
public static final int DESTRUCTOR = 9;
public static final int CONSTRUCTOR = 10;
public static final int STORAGE = 11;
}

View File

@@ -6,10 +6,15 @@ import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import storagecraft.StorageCraft;
import storagecraft.StorageCraftGUI;
import storagecraft.tile.TileStorage;
public class BlockStorage extends BlockMachine
@@ -58,4 +63,15 @@ public class BlockStorage extends BlockMachine
{
return new TileStorage();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
player.openGui(StorageCraft.INSTANCE, StorageCraftGUI.STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
}

View File

@@ -0,0 +1,20 @@
package storagecraft.container;
import net.minecraft.entity.player.EntityPlayer;
import storagecraft.container.slot.SlotSpecimen;
import storagecraft.tile.TileStorage;
public class ContainerStorage extends ContainerBase
{
public ContainerStorage(EntityPlayer player, TileStorage storage)
{
super(player);
for (int i = 0; i < 9; ++i)
{
addSlotToContainer(new SlotSpecimen(storage, i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 129);
}
}

View File

@@ -38,6 +38,8 @@ public class GuiHandler implements IGuiHandler
return new ContainerDestructor(player);
case StorageCraftGUI.CONSTRUCTOR:
return new ContainerConstructor(player, (TileConstructor) tile);
case StorageCraftGUI.STORAGE:
return new ContainerStorage(player, (TileStorage) tile);
default:
return null;
}
@@ -78,6 +80,8 @@ public class GuiHandler implements IGuiHandler
return new GuiDestructor((ContainerDestructor) getContainer(ID, player, tile), (TileDestructor) tile);
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);
default:
return null;
}

View File

@@ -0,0 +1,67 @@
package storagecraft.gui;
import storagecraft.block.EnumStorageType;
import storagecraft.container.ContainerStorage;
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
import storagecraft.tile.TileStorage;
public class GuiStorage extends GuiBase
{
private TileStorage storage;
private int barX = 8;
private int barY = 54;
private int barWidth = 16;
private int barHeight = 58;
public GuiStorage(ContainerStorage container, TileStorage storage)
{
super(container, 176, 211);
this.storage = storage;
}
@Override
public void init(int x, int y)
{
addSideButton(new SideButtonRedstoneMode(storage));
}
@Override
public void update(int x, int y)
{
}
@Override
public void drawBackground(int x, int y, int mouseX, int mouseY)
{
bindTexture("gui/storage.png");
drawTexture(x, y, 0, 0, xSize, ySize);
int barHeightNew = storage.getStoredScaled(barHeight);
drawTexture(x + barX, y + barY + barHeight - barHeightNew, 179, 0 + (barHeight - barHeightNew), barWidth, barHeightNew);
}
@Override
public void drawForeground(int mouseX, int mouseY)
{
drawString(7, 7, t("block.storagecraft:storage." + storage.getType().getId() + ".name"));
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()));
if (storage.getType() != EnumStorageType.TYPE_CREATIVE)
{
drawString(30, 64, t("misc.storagecraft:storage.capacity", storage.getType().getCapacity()));
}
if (inBounds(barX, barY, barWidth, barHeight, mouseX, mouseY))
{
drawTooltip(mouseX, mouseY, t("misc.storagecraft:storage.full", storage.getStoredScaled(100)));
}
}
}

View File

@@ -41,11 +41,11 @@ public class ItemStorageCell extends ItemBase
{
if (CellStorage.getCapacity(cell) == -1)
{
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storage_cell_stored"), NBTStorage.getStored(cell.getTagCompound())));
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storage.stored"), NBTStorage.getStored(cell.getTagCompound())));
}
else
{
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storage_cell_stored_capacity"), NBTStorage.getStored(cell.getTagCompound()), CellStorage.getCapacity(cell)));
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storage.stored_capacity"), NBTStorage.getStored(cell.getTagCompound()), CellStorage.getCapacity(cell)));
}
}

View File

@@ -326,8 +326,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
public int[] getSlotsForFace(EnumFacing side)
{
return new int[]
{
};
{
};
}
@Override

View File

@@ -1,21 +1,36 @@
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.block.BlockStorage;
import storagecraft.block.EnumStorageType;
import storagecraft.inventory.InventorySimple;
import storagecraft.storage.IStorage;
import storagecraft.storage.IStorageProvider;
import storagecraft.storage.NBTStorage;
import storagecraft.storage.StorageItem;
import storagecraft.util.InventoryUtils;
public class TileStorage extends TileMachine implements IStorageProvider, IStorage
public class TileStorage extends TileMachine implements IStorageProvider, IStorage, IInventory, ISidedInventory
{
public static final String STORAGE_NBT = "Storage";
private InventorySimple inventory = new InventorySimple("storage", 9);
private NBTTagCompound tag = NBTStorage.getBaseNBT();
@SideOnly(Side.CLIENT)
private int stored;
@Override
public int getEnergyUsage()
{
@@ -38,25 +53,65 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(this, nbt);
if (nbt.hasKey(STORAGE_NBT))
{
tag = nbt.getCompoundTag(STORAGE_NBT);
}
}
public NBTStorage getStorage()
{
return new NBTStorage(tag, ((EnumStorageType) worldObj.getBlockState(pos).getValue(BlockStorage.TYPE)).getCapacity());
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(inventory, nbt);
nbt.setTag(STORAGE_NBT, tag);
}
public NBTStorage getStorage()
{
return new NBTStorage(tag, getType().getCapacity());
}
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);
}
@Override
public void toBytes(ByteBuf buf)
{
super.toBytes(buf);
buf.writeInt(NBTStorage.getStored(tag));
}
@Override
public void fromBytes(ByteBuf buf)
{
super.fromBytes(buf);
stored = buf.readInt();
}
@Override
public void addItems(List<StorageItem> items)
{
@@ -88,4 +143,126 @@ 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();
}
@Override
public boolean hasCustomName()
{
return inventory.hasCustomName();
}
@Override
public IChatComponent getDisplayName()
{
return inventory.getDisplayName();
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return new int[]
{
};
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing direction)
{
return false;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{
return false;
}
}

View File

@@ -16,8 +16,11 @@ gui.storagecraft:constructor=Constructor
misc.storagecraft:energy_stored=%d / %d RF
misc.storagecraft:energy_usage=Usage: %d RF/t
misc.storagecraft:storage_cell_stored=Stored: %d
misc.storagecraft:storage_cell_stored_capacity=Stored: %d / %d
misc.storagecraft:storage=Storage
misc.storagecraft:storage.stored=Stored: %d
misc.storagecraft:storage.stored_capacity=Stored: %d / %d
misc.storagecraft:storage.capacity=Capacity: %d
misc.storagecraft:storage.full=%d%% full
misc.storagecraft:wireless_grid.tooltip=Bound to %d, %d, %d.
misc.storagecraft:wireless_grid.not_working=The Wireless Transmitter is disabled or out of fuel.
@@ -31,6 +34,7 @@ misc.storagecraft:wireless_grid.no_grid.1=There is no Crafting Grid found in the
misc.storagecraft:yes=Yes
misc.storagecraft:no=No
misc.storagecraft:clear=Clear
misc.storagecraft:priority=Priority
sidebutton.storagecraft:compare.1=Compare Damage
sidebutton.storagecraft:compare.2=Compare NBT

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB