mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-25 22:44:34 +00:00
rewrote crafter GUI to use ghost slots
This commit is contained in:
1 parent
fcf78ed23b
commit
f6d70cbb9c
7 files changed
+115
-57
No files matched your search
@@ -390,7 +390,7 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putStack(ItemStack stack) {
|
||||
public void putStack(ItemStack stack) {
|
||||
if(stack != null) {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
@@ -400,7 +400,7 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getStack() {
|
||||
public ItemStack getStack() {
|
||||
return items[slot];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package crazypants.enderio.machine.crafter;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
|
||||
public class BlockCrafter extends AbstractMachineBlock<TileCrafter> {
|
||||
|
||||
public static BlockCrafter create() {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketCrafter.class,PacketCrafter.class,PacketHandler.nextID(), Side.SERVER);
|
||||
BlockCrafter res = new BlockCrafter();
|
||||
res.init();
|
||||
return res;
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
package crazypants.enderio.machine.crafter;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.machine.gui.AbstractMachineContainer;
|
||||
import crazypants.gui.TemplateSlot;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GhostSlot;
|
||||
|
||||
public class ContainerCrafter extends AbstractMachineContainer {
|
||||
|
||||
private TileCrafter crafter;
|
||||
private DummyCraftingGrid craftingGrid;
|
||||
private final TileCrafter crafter;
|
||||
|
||||
public ContainerCrafter(InventoryPlayer playerInv, TileCrafter te) {
|
||||
super(playerInv, te);
|
||||
addCrafterSlots();
|
||||
crafter = (TileCrafter) tileEntity;
|
||||
}
|
||||
|
||||
private void addCrafterSlots() {
|
||||
crafter = (TileCrafter) tileEntity;
|
||||
craftingGrid = crafter.craftingGrid;
|
||||
|
||||
public void addCrafterSlots(List<GhostSlot> ghostSlots) {
|
||||
int topY = 16;
|
||||
int leftX = 31;
|
||||
int index = 0;
|
||||
@@ -32,12 +29,12 @@ public class ContainerCrafter extends AbstractMachineContainer {
|
||||
for (int col = 0; col < 3; ++col) {
|
||||
int x = leftX + col * 18;
|
||||
int y = topY + row * 18;
|
||||
addSlotToContainer(new DummySlot(craftingGrid, index, x, y));
|
||||
ghostSlots.add(new DummySlot(index, x, y));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
addSlotToContainer(new DummySlot(craftingGrid, 9, 90, 34));
|
||||
|
||||
ghostSlots.add(new DummySlot(9, 90, 34));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,19 +42,17 @@ public class ContainerCrafter extends AbstractMachineContainer {
|
||||
return new Point(30, 84);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getUpgradeOffset() {
|
||||
return new Point(6, 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addMachineSlots(InventoryPlayer playerInv) {
|
||||
|
||||
int topY = 16;
|
||||
int leftX = 31;
|
||||
int leftX = 113;
|
||||
int index = 0;
|
||||
|
||||
leftX = 113;
|
||||
index = 0;
|
||||
for (int row = 0; row < 3; ++row) {
|
||||
for (int col = 0; col < 3; ++col) {
|
||||
int x = leftX + col * 18;
|
||||
@@ -73,18 +68,6 @@ public class ContainerCrafter extends AbstractMachineContainer {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int par1, int par2, int par3,
|
||||
EntityPlayer par4EntityPlayer) {
|
||||
if(par1 >= 0 && par1 < inventorySlots.size()) {
|
||||
Slot slot = getSlot(par1);
|
||||
if(slot.getHasStack() && slot instanceof DummySlot) {
|
||||
slot.putStack(null);
|
||||
}
|
||||
}
|
||||
return super.slotClick(par1, par2, par3, par4EntityPlayer);
|
||||
}
|
||||
|
||||
private class InputSlot extends Slot {
|
||||
|
||||
@@ -103,35 +86,30 @@ public class ContainerCrafter extends AbstractMachineContainer {
|
||||
}
|
||||
}
|
||||
|
||||
private class DummySlot extends TemplateSlot {
|
||||
private class DummySlot extends GhostSlot {
|
||||
private final int slotIndex;
|
||||
|
||||
public DummySlot(IInventory inventory, int slotIndex, int x, int y) {
|
||||
super(inventory, slotIndex, x, y);
|
||||
public DummySlot(int slotIndex, int x, int y) {
|
||||
this.slotIndex = slotIndex;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return true;
|
||||
public ItemStack getStack() {
|
||||
return crafter.craftingGrid.getStackInSlot(slotIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack par1ItemStack) {
|
||||
if(par1ItemStack != null) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
public void putStack(ItemStack stack) {
|
||||
if(slotIndex >= 9) {
|
||||
return;
|
||||
}
|
||||
inventory.setInventorySlotContents(slotIndex, par1ItemStack);
|
||||
onSlotChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
super.onSlotChanged();
|
||||
crafter.updateCraftingOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
return false;
|
||||
if(stack != null) {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
}
|
||||
PacketHandler.INSTANCE.sendToServer(PacketCrafter.setSlot(crafter, slotIndex, stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,19 @@ import org.lwjgl.opengl.GL11;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.machine.IItemBuffer;
|
||||
import crazypants.enderio.machine.PacketItemBuffer;
|
||||
import crazypants.enderio.machine.gui.GuiPoweredMachineBase;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GhostSlot;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GuiCrafter extends GuiPoweredMachineBase<TileCrafter> {
|
||||
|
||||
private ToggleButtonEIO bufferSizeB;
|
||||
private final ToggleButtonEIO bufferSizeB;
|
||||
|
||||
public GuiCrafter(InventoryPlayer par1InventoryPlayer, TileCrafter te) {
|
||||
super(te, new ContainerCrafter(par1InventoryPlayer, te));
|
||||
@@ -38,6 +40,22 @@ public class GuiCrafter extends GuiPoweredMachineBase<TileCrafter> {
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
bufferSizeB.onGuiInit();
|
||||
((ContainerCrafter) inventorySlots).addCrafterSlots(ghostSlots);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int button, long par4) {
|
||||
if(!ghostSlots.isEmpty()) {
|
||||
GhostSlot slot = getGhostSlot(mouseX, mouseY);
|
||||
if(slot != null) {
|
||||
ItemStack st = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
// don't replace already set slots while dragging an item
|
||||
if(st == null || slot.getStack() == null) {
|
||||
slot.putStack(st);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, button, par4);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +73,7 @@ public class GuiCrafter extends GuiPoweredMachineBase<TileCrafter> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXSize() {
|
||||
public final int getXSize() {
|
||||
return 219;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package crazypants.enderio.machine.crafter;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PacketCrafter extends MessageTileEntity<TileCrafter> implements IMessageHandler<PacketCrafter, IMessage> {
|
||||
|
||||
private int slot;
|
||||
private ItemStack stack;
|
||||
|
||||
public PacketCrafter() {
|
||||
}
|
||||
|
||||
private PacketCrafter(TileCrafter tile) {
|
||||
super(tile);
|
||||
}
|
||||
|
||||
public static PacketCrafter setSlot(TileCrafter te, int slot, ItemStack stack) {
|
||||
PacketCrafter msg = new PacketCrafter(te);
|
||||
msg.slot = slot;
|
||||
msg.stack = stack;
|
||||
msg.execute(te);
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
slot = buf.readShort();
|
||||
stack = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeShort(slot);
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCrafter msg, MessageContext ctx) {
|
||||
TileCrafter te = msg.getTileEntity(ctx.getServerHandler().playerEntity.worldObj);
|
||||
if(te != null) {
|
||||
msg.execute(te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void execute(TileCrafter te) {
|
||||
te.craftingGrid.setInventorySlotContents(slot, stack);
|
||||
te.updateCraftingOutput();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -209,12 +209,12 @@ public class GuiVacuumChest extends GuiContainerBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putStack(ItemStack stack) {
|
||||
public void putStack(ItemStack stack) {
|
||||
PacketHandler.INSTANCE.sendToServer(PacketVaccumChest.setFilterSlot(te, slot, stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getStack() {
|
||||
public ItemStack getStack() {
|
||||
ItemFilter itemFilter = te.getItemFilter();
|
||||
if(itemFilter != null) {
|
||||
return itemFilter.getStackInSlot(slot);
|
||||
|
||||
@@ -17,10 +17,10 @@ public class GhostSlot {
|
||||
return visible;
|
||||
}
|
||||
|
||||
protected ItemStack getStack() {
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void putStack(ItemStack stack) {
|
||||
public void putStack(ItemStack stack) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user