basic crafting grid gui stuff (no functionality yet)

This commit is contained in:
Raoul Van den Berge
2015-12-22 13:31:00 +01:00
parent 2c65adaaee
commit 7a99d963b0
9 changed files with 107 additions and 8 deletions

View File

@@ -1,8 +1,12 @@
package storagecraft.block;
import java.util.List;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
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.IIcon;
import net.minecraft.world.IBlockAccess;
@@ -27,6 +31,15 @@ public class BlockGrid extends BlockBase implements ITileEntityProvider
return new TileGrid();
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List subItems)
{
for (int i = 0; i < 2; i++)
{
subItems.add(new ItemStack(item, 1, i));
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{

View File

@@ -1,13 +1,36 @@
package storagecraft.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import storagecraft.tile.TileGrid;
public class ContainerGrid extends ContainerBase
{
public ContainerGrid(EntityPlayer player)
public ContainerGrid(EntityPlayer player, TileGrid grid)
{
super(player);
addPlayerInventory(8, 108);
if (grid.isCrafting())
{
int x = 44;
int y = 106;
for (int i = 0; i < 9; ++i)
{
addSlotToContainer(new Slot(grid.getCraftingInventory(), i, x, y));
x += 18;
if ((i + 1) % 3 == 0)
{
y += 18;
x = 44;
}
}
addSlotToContainer(new Slot(grid.getCraftingInventory(), 9, 125, 124));
}
addPlayerInventory(8, grid.isCrafting() ? 174 : 108);
}
}

View File

@@ -42,7 +42,7 @@ public class GuiGrid extends GuiBase
public GuiGrid(ContainerGrid container, TileGrid grid)
{
super(container, 176, 190);
super(container, 176, grid.isCrafting() ? 256 : 190);
this.container = container;
this.grid = grid;
@@ -116,8 +116,15 @@ public class GuiGrid extends GuiBase
@Override
public void drawBackground(int x, int y, int mouseX, int mouseY)
{
if (grid.isCrafting())
{
bindTexture("gui/craftingGrid.png");
}
else
{
bindTexture("gui/grid.png");
}
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
@@ -128,7 +135,13 @@ public class GuiGrid extends GuiBase
public void drawForeground(int mouseX, int mouseY)
{
drawString(7, 7, t("gui.storagecraft:grid"));
drawString(7, 96, t("container.inventory"));
if (grid.isCrafting())
{
drawString(7, 94, t("container.crafting"));
}
drawString(7, grid.isCrafting() ? 163 : 96, t("container.inventory"));
int x = 8;
int y = 20;

View File

@@ -30,7 +30,7 @@ public class GuiHandler implements IGuiHandler
case StorageCraft.GUI.CONTROLLER:
return new ContainerController(player);
case StorageCraft.GUI.GRID:
return new ContainerGrid(player);
return new ContainerGrid(player, (TileGrid) tile);
case StorageCraft.GUI.DRIVE:
return new ContainerDrive(player, (TileDrive) tile);
case StorageCraft.GUI.STORAGE_PROXY:

View File

@@ -0,0 +1,11 @@
package storagecraft.item;
import net.minecraft.block.Block;
public class ItemBlockGrid extends ItemBlockBase
{
public ItemBlockGrid(Block block)
{
super(block);
}
}

View File

@@ -11,6 +11,7 @@ import storagecraft.StorageCraftBlocks;
import storagecraft.StorageCraftItems;
import storagecraft.gui.GuiHandler;
import storagecraft.item.ItemBlockCable;
import storagecraft.item.ItemBlockGrid;
import storagecraft.network.MessageCompareUpdate;
import storagecraft.network.MessageDetectorAmountUpdate;
import storagecraft.network.MessageDetectorModeUpdate;
@@ -54,7 +55,7 @@ public class CommonProxy
GameRegistry.registerBlock(StorageCraftBlocks.CONTROLLER, "controller");
GameRegistry.registerBlock(StorageCraftBlocks.CABLE, ItemBlockCable.class, "cable");
GameRegistry.registerBlock(StorageCraftBlocks.GRID, "grid");
GameRegistry.registerBlock(StorageCraftBlocks.GRID, ItemBlockGrid.class, "grid");
GameRegistry.registerBlock(StorageCraftBlocks.DRIVE, "drive");
GameRegistry.registerBlock(StorageCraftBlocks.STORAGE_PROXY, "storageProxy");
GameRegistry.registerBlock(StorageCraftBlocks.IMPORTER, "importer");

View File

@@ -1,7 +1,13 @@
package storagecraft.tile;
import net.minecraft.nbt.NBTTagCompound;
import storagecraft.inventory.InventorySimple;
import storagecraft.util.InventoryUtils;
public class TileGrid extends TileMachine
{
private InventorySimple craftingInventory = new InventorySimple("crafting", 10);
@Override
public int getEnergyUsage()
{
@@ -12,4 +18,35 @@ public class TileGrid extends TileMachine
public void updateMachine()
{
}
public int getType()
{
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
}
public boolean isCrafting()
{
return getType() == 1;
}
public InventorySimple getCraftingInventory()
{
return craftingInventory;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(craftingInventory, nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(craftingInventory, nbt);
}
}

View File

@@ -45,7 +45,8 @@ misc.storagecraft:no=No
block.storagecraft:controller.name=Controller
block.storagecraft:cable.0.name=Cable
block.storagecraft:cable.1.name=Sensitive Cable
block.storagecraft:grid.name=Grid
block.storagecraft:grid.0.name=Grid
block.storagecraft:grid.1.name=Crafting Grid
block.storagecraft:drive.name=Drive
block.storagecraft:storageProxy.name=Storage Proxy
block.storagecraft:importer.name=Importer

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB