slots have different color on no controller + shift clicking in grid

This commit is contained in:
Raoul Van den Berge
2015-12-12 15:56:16 +01:00
parent 003e87bd4d
commit d518eb4f31
5 changed files with 72 additions and 43 deletions

View File

@@ -3,9 +3,9 @@ package storagecraft.gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import storagecraft.inventory.ContainerController;
import storagecraft.tile.TileController; import storagecraft.tile.TileController;
public class GuiController extends GuiContainer { public class GuiController extends GuiContainer {
@@ -13,7 +13,7 @@ public class GuiController extends GuiContainer {
private TileController controller; private TileController controller;
public GuiController(Container container, TileController controller) { public GuiController(ContainerController container, TileController controller) {
super(container); super(container);
this.controller = controller; this.controller = controller;

View File

@@ -1,23 +1,28 @@
package storagecraft.gui; package storagecraft.gui;
import net.minecraft.client.gui.inventory.GuiContainer; 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.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import storagecraft.SC; import storagecraft.SC;
import storagecraft.inventory.ContainerGrid;
import storagecraft.network.MessagePushToStorage; import storagecraft.network.MessagePushToStorage;
import storagecraft.storage.StorageItem; import storagecraft.storage.StorageItem;
import storagecraft.tile.TileController;
import storagecraft.tile.TileGrid; import storagecraft.tile.TileGrid;
public class GuiGrid extends GuiContainer { public class GuiGrid extends GuiContainer {
public static final ResourceLocation GRID_RESOURCE = new ResourceLocation("storagecraft:textures/gui/grid.png"); public static final ResourceLocation GRID_RESOURCE = new ResourceLocation("storagecraft:textures/gui/grid.png");
private ContainerGrid container;
private TileGrid grid; private TileGrid grid;
public GuiGrid(Container container, TileGrid grid) { public GuiGrid(ContainerGrid container, TileGrid grid) {
super(container); super(container);
this.container = container;
this.grid = grid; this.grid = grid;
this.xSize = 176; this.xSize = 176;
@@ -38,12 +43,11 @@ public class GuiGrid extends GuiContainer {
fontRendererObj.drawString("Grid", x + 7, y + 7, 4210752); fontRendererObj.drawString("Grid", x + 7, y + 7, 4210752);
fontRendererObj.drawString("Inventory", x + 7, y + 96, 4210752); fontRendererObj.drawString("Inventory", x + 7, y + 96, 4210752);
if (grid.isConnected()) {
int xx = getGridXStart(); int xx = getGridXStart();
int yy = getGridYStart(); int yy = getGridYStart();
for (int i = 0; i < 9 * 4; ++i) { for (int i = 0; i < 9 * 4; ++i) {
if (i < grid.getController().getStorage().all().size()) { if (grid.isConnected() && i < grid.getController().getStorage().all().size()) {
StorageItem item = grid.getController().getStorage().all().get(i); 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());
@@ -52,11 +56,13 @@ public class GuiGrid extends GuiContainer {
itemRender.renderItemOverlayIntoGUI(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) { if ((mouseX > xx && mouseX < xx + 16 && mouseY > yy && mouseY < yy + 16) || !grid.isConnected()) {
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glColorMask(true, true, true, false); GL11.glColorMask(true, true, true, false);
drawGradientRect(xx, yy, xx + 16, yy + 16, -2130706433, -2130706433); drawGradientRect(xx, yy, xx + 16, yy + 16, color, color);
GL11.glColorMask(true, true, true, true); GL11.glColorMask(true, true, true, true);
GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_DEPTH_TEST);
@@ -70,7 +76,6 @@ public class GuiGrid extends GuiContainer {
} }
} }
} }
}
private int getGridXStart() { private int getGridXStart() {
return ((this.width - xSize) / 2) + 8; return ((this.width - xSize) / 2) + 8;
@@ -92,9 +97,21 @@ public class GuiGrid extends GuiContainer {
public void mouseClicked(int mouseX, int mouseY, int clickedButton) { public void mouseClicked(int mouseX, int mouseY, int clickedButton) {
super.mouseClicked(mouseX, mouseY, 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()) { 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));
}
}
}
} }
} }
} }

View File

@@ -34,9 +34,9 @@ public class GuiHandler implements IGuiHandler {
switch (ID) { switch (ID) {
case SC.GUI.CONTROLLER: 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: case SC.GUI.GRID:
return new GuiGrid(getContainer(ID, player), (TileGrid) tile); return new GuiGrid((ContainerGrid) getContainer(ID, player), (TileGrid) tile);
default: default:
return null; return null;
} }

View File

@@ -12,6 +12,10 @@ public class ContainerSC extends Container {
this.player = player; this.player = player;
} }
public EntityPlayer getPlayer() {
return player;
}
protected void addPlayerInventory(int xInventory, int yInventory) { protected void addPlayerInventory(int xInventory, int yInventory) {
int id = 0; int id = 0;

View File

@@ -10,17 +10,19 @@ import net.minecraft.tileentity.TileEntity;
import storagecraft.tile.TileController; import storagecraft.tile.TileController;
public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePushToStorage, IMessage> { public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePushToStorage, IMessage> {
private TileController controller;
private int x; private int x;
private int y; private int y;
private int z; private int z;
private int slot;
public MessagePushToStorage() { public MessagePushToStorage() {
} }
public MessagePushToStorage(TileController controller) { public MessagePushToStorage(int x, int y, int z, int slot) {
this.controller = controller; this.x = x;
this.y = y;
this.z = z;
this.slot = slot;
} }
@Override @Override
@@ -28,13 +30,15 @@ public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePu
x = buf.readInt(); x = buf.readInt();
y = buf.readInt(); y = buf.readInt();
z = buf.readInt(); z = buf.readInt();
slot = buf.readInt();
} }
@Override @Override
public void toBytes(ByteBuf buf) { public void toBytes(ByteBuf buf) {
buf.writeInt(controller.xCoord); buf.writeInt(x);
buf.writeInt(controller.yCoord); buf.writeInt(y);
buf.writeInt(controller.zCoord); buf.writeInt(z);
buf.writeInt(slot);
} }
@Override @Override
@@ -44,15 +48,19 @@ public class MessagePushToStorage implements IMessage, IMessageHandler<MessagePu
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z); TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
if (tile instanceof TileController) { 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) { if (stack != null) {
controller.getStorage().push(stack); controller.getStorage().push(stack);
if (message.slot == -1) {
player.inventory.setItemStack(null); player.inventory.setItemStack(null);
player.updateHeldItem(); player.updateHeldItem();
} else {
player.inventory.setInventorySlotContents(message.slot, null);
}
} }
} }