first part of the inventory panel (WIP)

This commit is contained in:
Matthias Mann committed 2015-04-20 02:47:54 +02:00
1 parent 4869fc7b82
commit e4c10a3e4b
12 files changed
+442 -8

No files matched your search

@@ -91,8 +91,10 @@ import crazypants.enderio.machine.farm.FarmersRegistry;
import crazypants.enderio.machine.generator.combustion.BlockCombustionGenerator;
import crazypants.enderio.machine.generator.stirling.BlockStirlingGenerator;
import crazypants.enderio.machine.generator.zombie.BlockZombieGenerator;
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
import crazypants.enderio.machine.hypercube.BlockHyperCube;
import crazypants.enderio.machine.hypercube.HyperCubeRegister;
import crazypants.enderio.machine.invpanel.BlockInventoryPanel;
import crazypants.enderio.machine.killera.BlockKillerJoe;
import crazypants.enderio.machine.light.BlockElectricLight;
import crazypants.enderio.machine.light.BlockLightNode;
@@ -155,7 +157,6 @@ import crazypants.enderio.teleport.telepad.ItemCoordSelector;
import crazypants.enderio.thaumcraft.ThaumcraftCompat;
import crazypants.util.EntityUtil;
import static crazypants.enderio.EnderIO.*;
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
@Mod(modid = MODID, name = MOD_NAME, version = VERSION, dependencies = "required-after:[email protected],);after:MineFactoryReloaded;after:Waila@[1.5.8,);after:Thaumcraft", guiFactory = "crazypants.enderio.config.ConfigFactoryEIO")
public class EnderIO {
@@ -250,6 +251,7 @@ public class EnderIO {
public static BlockInhibitorObelisk blockInhibitorObelisk;
public static BlockTransceiver blockTransceiver;
public static BlockBuffer blockBuffer;
public static BlockInventoryPanel blockInventoryPanel;
public static BlockKillerJoe blockKillerJoe;
@@ -342,6 +344,7 @@ public class EnderIO {
blockTransceiver = BlockTransceiver.create();
blockBuffer = BlockBuffer.create();
blockInventoryPanel = BlockInventoryPanel.create();
blockEnderIo = BlockEnderIO.create();
blockTravelPlatform = BlockTravelAnchor.create();
@@ -55,6 +55,7 @@ public class GuiHandler implements IGuiHandler {
public static final int GUI_ID_TELEPAD = 102;
public static final int GUI_ID_TELEPAD_TRAVEL = 103;
public static final int GUI_ID_INHIBITOR = 104;
public static final int GUI_ID_INVENTORY_PANEL = 105;
public static final int GUI_ID_CAP_BANK = 142; // leave room for more machines
@@ -63,6 +63,7 @@ public enum ModObject {
blockInhibitorObelisk,
blockTransceiver,
blockBuffer,
blockInventoryPanel,
blockPoweredSpawner,
itemBrokenSpawner,
@@ -16,6 +16,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.item.filter.IItemFilter;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.invpanel.TileInventoryPanel;
import crazypants.util.BlockCoord;
import crazypants.util.InventoryWrapper;
import crazypants.util.ItemUtil;
@@ -41,6 +42,9 @@ public class NetworkedInventory {
//Hack for TiC crafting station not working correctly when setting output slot to null
boolean ticHack = false;
//optimization for InventoryPanel
boolean cantInsert = false;
World world;
ItemConduitNetwork network;
@@ -60,6 +64,8 @@ public class NetworkedInventory {
recheckInv = true;
} else if(te instanceof TileEntityChest) {
recheckInv = true;
} else if(te instanceof TileInventoryPanel) {
cantInsert = true;
}
updateInventory();
}
@@ -79,6 +85,9 @@ public class NetworkedInventory {
}
boolean canInsert() {
if(!cantInsert) {
return false;
}
ConnectionMode mode = con.getConnectionMode(conDir);
return mode == ConnectionMode.OUTPUT || mode == ConnectionMode.IN_OUT;
}
@@ -0,0 +1,119 @@
package crazypants.enderio.machine.invpanel;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.ClientProxy;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.machine.AbstractMachineEntity;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockInventoryPanel extends AbstractMachineBlock<TileInventoryPanel> {
public static BlockInventoryPanel create() {
BlockInventoryPanel panel = new BlockInventoryPanel();
panel.init();
return panel;
}
public BlockInventoryPanel() {
super(ModObject.blockInventoryPanel, TileInventoryPanel.class);
}
@Override
@SideOnly(Side.CLIENT)
public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int blockSide) {
int facing = getFacing(world, x, y, z);
return ClientProxy.sideAndFacingToSpriteOffset[blockSide][facing] == 2;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean isBlockNormalCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public void setBlockBoundsForItemRender() {
setBlockBounds(0.0f, 0.0f, 0.4f, 1.0f, 1.0f, 0.6f);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
int facing = getFacing(world, x, y, z);
switch (facing) {
case 2:
setBlockBounds(0.0f, 0.0f, 0.8f, 1.0f, 1.0f, 1.0f);
break;
case 3:
setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.2f);
break;
case 4:
setBlockBounds(0.8f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
break;
case 5:
setBlockBounds(0.0f, 0.0f, 0.0f, 0.2f, 1.0f, 1.0f);
break;
default:
setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
break;
}
}
private int getFacing(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileInventoryPanel) {
return ((TileInventoryPanel)te).getFacing();
}
return 0;
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
}
@Override
protected int getGuiId() {
return GuiHandler.GUI_ID_INVENTORY_PANEL;
}
@Override
protected String getMachineFrontIconKey(boolean active) {
if(active) {
return "enderio:invPanelFrontOn";
}
return "enderio:invPanelFrontOff";
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
// The server needs the container as it manages the adding and removing of
// items, which are then sent to the client for display
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileInventoryPanel) {
return new InventoryPanelContainer(player.inventory, (TileInventoryPanel) te);
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileInventoryPanel te = (TileInventoryPanel) world.getTileEntity(x, y, z);
return new GuiInventoryPanel(te, new InventoryPanelContainer(player.inventory, te));
}
}
@@ -0,0 +1,120 @@
package crazypants.enderio.machine.invpanel;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.machine.gui.GuiMachineBase;
import crazypants.render.RenderUtil;
import java.awt.Rectangle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.inventory.Container;
import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
private static final Rectangle btnScrollUp = new Rectangle(216, 27, 16, 8);
private static final Rectangle btnScrollDown = new Rectangle(216, 109, 16, 8);
private static final Rectangle thumbArea = new Rectangle(216, 35, 16, 74);
private boolean scrollUpPressed;
private boolean scrollDownPressed;
private int scrollPos;
private int scrollMax = 100;
private long scrollLastTime;
public GuiInventoryPanel(TileInventoryPanel te, Container container) {
super(te, container);
redstoneButton.visible = false;
configB.visible = false;
scrollLastTime = Minecraft.getSystemTime();
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderUtil.bindTexture("enderio:textures/gui/inventorypanel.png");
int sx = guiLeft;
int sy = guiTop;
drawTexturedModalRect(sx, sy, 0, 0, xSize, ySize);
long time = Minecraft.getSystemTime();
if((time - scrollLastTime) >= 100) {
scrollLastTime = time;
doScroll();
}
Tessellator tes = Tessellator.instance;
tes.startDrawingQuads();
RenderUtil.bindTexture(IconEIO.TEXTURE);
IconEIO icon;
icon = scrollUpPressed ? IconEIO.UP_ARROW_ON : IconEIO.UP_ARROW_OFF;
icon.renderIcon(sx+btnScrollUp.x, sy+btnScrollUp.y);
icon = scrollDownPressed ? IconEIO.DOWN_ARROW_ON : IconEIO.DOWN_ARROW_OFF;
icon.renderIcon(sx+btnScrollDown.x, sy+btnScrollDown.y);
icon = IconEIO.VSCROLL_THUMB;
icon.renderIcon(sx+thumbArea.x, sy+thumbArea.y + (thumbArea.height - icon.height) * scrollPos / scrollMax);
tes.draw();
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
}
private void doScroll() {
if(scrollUpPressed && scrollPos > 0) {
scrollPos--;
}
if(scrollDownPressed && scrollPos < scrollMax) {
scrollPos++;
}
}
@Override
protected boolean showRecipeButton() {
return false;
}
@Override
public int getXSize() {
return 238;
}
@Override
public int getYSize() {
return 212;
}
@Override
protected void mouseClicked(int x, int y, int button) {
super.mouseClicked(x, y, button);
x -= guiLeft;
y -= guiTop;
scrollUpPressed = btnScrollUp.contains(x, y);
scrollDownPressed = btnScrollDown.contains(x, y);
if(scrollUpPressed || scrollDownPressed) {
scrollLastTime = Minecraft.getSystemTime();
doScroll();
}
}
@Override
protected void mouseMovedOrUp(int x, int y, int button) {
super.mouseMovedOrUp(x, y, button);
scrollUpPressed = false;
scrollDownPressed = false;
}
@Override
protected void mouseClickMove(int x, int y, int button, long time) {
super.mouseClickMove(x, y, button, time);
}
}
@@ -0,0 +1,110 @@
package crazypants.enderio.machine.invpanel;
import cpw.mods.fml.common.FMLCommonHandler;
import crazypants.enderio.machine.gui.AbstractMachineContainer;
import crazypants.util.ItemUtil;
import java.awt.Point;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
public class InventoryPanelContainer extends AbstractMachineContainer {
private static final int CRAFTING_GRID_X = 7;
private static final int CRAFTING_GRID_Y = 16;
private static final int RETURN_INV_X = 7;
private static final int RETURN_INV_Y = 82;
@SuppressWarnings("LeakingThisInConstructor")
public InventoryPanelContainer(InventoryPlayer playerInv, TileInventoryPanel te) {
super(playerInv, te);
te.eventHandler = this;
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
addSlotToContainer(new SlotCrafting(playerInv.player, tileEntity, tileEntity, 9, CRAFTING_GRID_X+59, CRAFTING_GRID_Y+18) {
@Override
public void onPickupFromSlot(EntityPlayer player, ItemStack p_82870_2_) {
FMLCommonHandler.instance().firePlayerCraftingEvent(player, p_82870_2_, tileEntity);
for (int i = 0; i < 9; i++) {
ItemStack itemstack = tileEntity.getStackInSlot(i);
if(itemstack == null)
continue;
tileEntity.decrStackSize(i, 1);
if(!itemstack.getItem().hasContainerItem(itemstack))
continue;
ItemStack containerIS = itemstack.getItem().getContainerItem(itemstack);
if(containerIS != null && containerIS.isItemStackDamageable() && containerIS.getItemDamage() > containerIS.getMaxDamage()) {
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, containerIS));
} else {
if(itemstack.getItem().doesContainerItemLeaveCraftingGrid(itemstack)) {
if(ItemUtil.doInsertItem(tileEntity, 10, 20, itemstack) > 0)
continue;
if(player.inventory.addItemStackToInventory(containerIS))
continue;
}
if(tileEntity.getStackInSlot(i) == null) {
tileEntity.setInventorySlotContents(i, containerIS);
} else {
player.dropPlayerItemWithRandomChoice(containerIS, false);
}
}
}
}
});
for(int y=0,i=0 ; y<3 ; y++) {
for(int x=0 ; x<3 ; x++,i++) {
addSlotToContainer(new Slot(tileEntity, i, CRAFTING_GRID_X+x*18, CRAFTING_GRID_Y+y*18));
}
}
for(int y=0,i=10 ; y<2 ; y++) {
for(int x=0 ; x<5 ; x++,i++) {
addSlotToContainer(new Slot(tileEntity, i, RETURN_INV_X+x*18, RETURN_INV_Y+y*18));
}
}
}
@Override
public Point getPlayerInventoryOffset() {
return new Point(39, 130);
}
@Override
public void onContainerClosed(EntityPlayer player) {
super.onContainerClosed(player);
if(!tileEntity.getWorldObj().isRemote) {
((TileInventoryPanel)tileEntity).eventHandler = null;
}
}
@Override
public void onCraftMatrixChanged(IInventory inv) {
InventoryCrafting tmp = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer ep) {
return false;
}
}, 3, 3);
for(int i=0 ; i<9 ; i++) {
tmp.setInventorySlotContents(i, tileEntity.getStackInSlot(i));
}
tileEntity.setInventorySlotContents(9, CraftingManager.getInstance().findMatchingRecipe(tmp, tileEntity.getWorldObj()));
}
}
@@ -0,0 +1,63 @@
package crazypants.enderio.machine.invpanel;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.SlotDefinition;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
public class TileInventoryPanel extends AbstractMachineEntity {
public Container eventHandler;
public TileInventoryPanel() {
super(new SlotDefinition(0, 8, 10, 19, 20, 19));
}
@Override
public boolean canInsertItem(int slot, ItemStack var2, int side) {
return false;
}
@Override
protected boolean isMachineItemValidForSlot(int i, ItemStack itemstack) {
return true;
}
@Override
public ItemStack decrStackSize(int fromSlot, int amount) {
ItemStack res = super.decrStackSize(fromSlot, amount);
if(res != null && fromSlot < 9 && eventHandler != null) {
eventHandler.onCraftMatrixChanged(this);
}
return res;
}
@Override
public void setInventorySlotContents(int slot, ItemStack contents) {
super.setInventorySlotContents(slot, contents);
if(slot < 9 && eventHandler != null) {
eventHandler.onCraftMatrixChanged(this);
}
}
@Override
public boolean isActive() {
return true;
}
@Override
public void doUpdate() {
}
@Override
protected boolean processTasks(boolean redstoneCheckPassed) {
return false;
}
@Override
public String getMachineName() {
return ModObject.blockInventoryPanel.unlocalisedName;
}
}
+15 -7
View File
@@ -72,6 +72,10 @@ public class ItemUtil {
return startedWith - remaining.stackSize;
}
public static int doInsertItem(IInventory inv, int startSlot, int endSlot, ItemStack item) {
return doInsertItemInv(inv, null, invSlotter.getInstance(startSlot, endSlot), item, ForgeDirection.UNKNOWN);
}
/*
* Insert items into an IInventory or an ISidedInventory.
*/
@@ -86,9 +90,13 @@ public class ItemUtil {
// Note: This is not thread-safe. Change to getInstance() to constructor when needed (1.8++?).
slots = sidedSlotter.getInstance(sidedInv.getAccessibleSlotsFromSide(inventorySide.ordinal()));
} else {
slots = invSlotter.getInstance(inv.getSizeInventory());
slots = invSlotter.getInstance(0, inv.getSizeInventory());
}
return doInsertItemInv(inv, sidedInv, slots, item, inventorySide);
}
private static int doInsertItemInv(IInventory inv, ISidedInventory sidedInv, ISlotIterator slots, ItemStack item, ForgeDirection inventorySide) {
int numInserted = 0;
int numToInsert = item.stackSize;
int firstFreeSlot = -1;
@@ -210,11 +218,11 @@ public class ItemUtil {
private final static class invSlotter implements ISlotIterator {
private static final invSlotter me = new invSlotter();
private int size;
private int end;
private int current;
public final static invSlotter getInstance(int size) {
me.size = size;
me.current = 0;
public final static invSlotter getInstance(int start, int end) {
me.end = end;
me.current = start;
return me;
}
@Override
@@ -223,7 +231,7 @@ public class ItemUtil {
}
@Override
public final boolean hasNext() {
return current < size;
return current < end;
}
}