slots have different color on no controller + shift clicking in grid
This commit is contained in:
@@ -3,9 +3,9 @@ package storagecraft.gui;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import storagecraft.inventory.ContainerController;
|
||||
import storagecraft.tile.TileController;
|
||||
|
||||
public class GuiController extends GuiContainer {
|
||||
@@ -13,7 +13,7 @@ public class GuiController extends GuiContainer {
|
||||
|
||||
private TileController controller;
|
||||
|
||||
public GuiController(Container container, TileController controller) {
|
||||
public GuiController(ContainerController container, TileController controller) {
|
||||
super(container);
|
||||
|
||||
this.controller = controller;
|
||||
|
@@ -1,23 +1,28 @@
|
||||
package storagecraft.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import storagecraft.SC;
|
||||
import storagecraft.inventory.ContainerGrid;
|
||||
import storagecraft.network.MessagePushToStorage;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.tile.TileController;
|
||||
import storagecraft.tile.TileGrid;
|
||||
|
||||
public class GuiGrid extends GuiContainer {
|
||||
public static final ResourceLocation GRID_RESOURCE = new ResourceLocation("storagecraft:textures/gui/grid.png");
|
||||
|
||||
private ContainerGrid container;
|
||||
private TileGrid grid;
|
||||
|
||||
public GuiGrid(Container container, TileGrid grid) {
|
||||
public GuiGrid(ContainerGrid container, TileGrid grid) {
|
||||
super(container);
|
||||
|
||||
this.container = container;
|
||||
this.grid = grid;
|
||||
|
||||
this.xSize = 176;
|
||||
@@ -38,36 +43,36 @@ public class GuiGrid extends GuiContainer {
|
||||
fontRendererObj.drawString("Grid", x + 7, y + 7, 4210752);
|
||||
fontRendererObj.drawString("Inventory", x + 7, y + 96, 4210752);
|
||||
|
||||
if (grid.isConnected()) {
|
||||
int xx = getGridXStart();
|
||||
int yy = getGridYStart();
|
||||
int xx = getGridXStart();
|
||||
int yy = getGridYStart();
|
||||
|
||||
for (int i = 0; i < 9 * 4; ++i) {
|
||||
if (i < grid.getController().getStorage().all().size()) {
|
||||
StorageItem item = grid.getController().getStorage().all().get(i);
|
||||
for (int i = 0; i < 9 * 4; ++i) {
|
||||
if (grid.isConnected() && i < grid.getController().getStorage().all().size()) {
|
||||
StorageItem item = grid.getController().getStorage().all().get(i);
|
||||
|
||||
ItemStack stack = new ItemStack(item.getType(), item.getQuantity(), item.getMeta());
|
||||
ItemStack stack = new ItemStack(item.getType(), item.getQuantity(), item.getMeta());
|
||||
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), stack, xx, yy);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack, xx, yy);
|
||||
}
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), stack, xx, yy);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack, xx, yy);
|
||||
}
|
||||
|
||||
if (mouseX > xx && mouseX < xx + 16 && mouseY > yy && mouseY < yy + 16) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glColorMask(true, true, true, false);
|
||||
drawGradientRect(xx, yy, xx + 16, yy + 16, -2130706433, -2130706433);
|
||||
GL11.glColorMask(true, true, true, true);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
}
|
||||
if ((mouseX > xx && mouseX < xx + 16 && mouseY > yy && mouseY < yy + 16) || !grid.isConnected()) {
|
||||
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
|
||||
|
||||
xx += 18;
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glColorMask(true, true, true, false);
|
||||
drawGradientRect(xx, yy, xx + 16, yy + 16, color, color);
|
||||
GL11.glColorMask(true, true, true, true);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
if ((i + 1) % 9 == 0) {
|
||||
xx = getGridXStart();
|
||||
yy += 18;
|
||||
}
|
||||
xx += 18;
|
||||
|
||||
if ((i + 1) % 9 == 0) {
|
||||
xx = getGridXStart();
|
||||
yy += 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,9 +97,21 @@ public class GuiGrid extends GuiContainer {
|
||||
public void mouseClicked(int mouseX, int mouseY, int clickedButton) {
|
||||
super.mouseClicked(mouseX, mouseY, clickedButton);
|
||||
|
||||
if (clickedButton == 0 && grid.isConnected()) {
|
||||
if (grid.isConnected()) {
|
||||
TileController controller = grid.getController();
|
||||
|
||||
if (mouseX > getGridXStart() && mouseX < getGridXEnd() && mouseY > getGridYStart() && mouseY < getGridYEnd()) {
|
||||
SC.NETWORK.sendToServer(new MessagePushToStorage(grid.getController()));
|
||||
if (container.getPlayer().inventory.getItemStack() != null) {
|
||||
SC.NETWORK.sendToServer(new MessagePushToStorage(controller.xCoord, controller.yCoord, controller.zCoord, -1));
|
||||
}
|
||||
} else {
|
||||
for (Object slot : container.inventorySlots) {
|
||||
if (func_146978_c(((Slot) slot).xDisplayPosition, ((Slot) slot).yDisplayPosition, 16, 16, mouseX, mouseY)) {
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
SC.NETWORK.sendToServer(new MessagePushToStorage(controller.xCoord, controller.yCoord, controller.zCoord, ((Slot) slot).slotNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,9 +34,9 @@ public class GuiHandler implements IGuiHandler {
|
||||
|
||||
switch (ID) {
|
||||
case SC.GUI.CONTROLLER:
|
||||
return new GuiController(getContainer(ID, player), (TileController) tile);
|
||||
return new GuiController((ContainerController) getContainer(ID, player), (TileController) tile);
|
||||
case SC.GUI.GRID:
|
||||
return new GuiGrid(getContainer(ID, player), (TileGrid) tile);
|
||||
return new GuiGrid((ContainerGrid) getContainer(ID, player), (TileGrid) tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@@ -12,6 +12,10 @@ public class ContainerSC extends Container {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
protected void addPlayerInventory(int xInventory, int yInventory) {
|
||||
int id = 0;
|
||||
|
||||
|
@@ -10,17 +10,19 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import storagecraft.tile.TileController;
|
||||
|
||||
public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePushToStorage, IMessage> {
|
||||
private TileController controller;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int slot;
|
||||
|
||||
public MessagePushToStorage() {
|
||||
}
|
||||
|
||||
public MessagePushToStorage(TileController controller) {
|
||||
this.controller = controller;
|
||||
public MessagePushToStorage(int x, int y, int z, int slot) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,13 +30,15 @@ public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePu
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
slot = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(controller.xCoord);
|
||||
buf.writeInt(controller.yCoord);
|
||||
buf.writeInt(controller.zCoord);
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,15 +48,19 @@ public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePu
|
||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
|
||||
if (tile instanceof TileController) {
|
||||
controller = (TileController) tile;
|
||||
TileController controller = (TileController) tile;
|
||||
|
||||
ItemStack stack = player.inventory.getItemStack();
|
||||
ItemStack stack = message.slot == -1 ? player.inventory.getItemStack() : player.inventory.getStackInSlot(message.slot);
|
||||
|
||||
if (stack != null) {
|
||||
controller.getStorage().push(stack);
|
||||
|
||||
player.inventory.setItemStack(null);
|
||||
player.updateHeldItem();
|
||||
if (message.slot == -1) {
|
||||
player.inventory.setItemStack(null);
|
||||
player.updateHeldItem();
|
||||
} else {
|
||||
player.inventory.setInventorySlotContents(message.slot, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user