Pretty sure this commit was to fix crates not obeying ISided, but I'm not quite sure...

This commit is contained in:
Brian Ricketts 2013-01-03 22:06:36 -06:00
parent 84c74bc589
commit 8323cee352
5 changed files with 271 additions and 269 deletions

View file

@ -1,114 +1,114 @@
package assemblyline.client.gui;
import java.util.ArrayList;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import cpw.mods.fml.client.GuiScrollingList;
public class GuiCommandList extends GuiScrollingList
{
private ArrayList<String> commands;
private int selIndex;
private Minecraft mc;
public GuiCommandList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight)
{
super(client, width, height, top, bottom, left, entryHeight);
commands = new ArrayList<String>();
selIndex = -1;
this.mc = client;
}
public void setCommands(ArrayList<String> commands)
{
this.commands = (ArrayList<String>) commands.clone();
}
@Override
protected int getSize()
{
return commands.size();
}
@Override
protected void elementClicked(int index, boolean doubleClick)
{
selIndex = index;
}
@Override
protected boolean isSelected(int index)
{
return selIndex == index;
}
@Override
protected void drawBackground()
{
drawOutlineRect(this.left, this.left + this.listWidth, this.top, this.top + this.listHeight, 0, 0, 0, 0.5f, 0.5f, 0.5f);
}
public static void drawOutlineRect(int x1, int y1, int x2, int y2, float rR, float rG, float rB, float lR, float lG, float lB)
{
Tessellator tesselator = Tessellator.instance;
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(rR, rG, rB, 1f);
if (rR > 0 && rG > 0 && rB > 0)
{
// background
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y1, 0.0D);
tesselator.addVertex((double) x1, (double) y1, 0.0D);
tesselator.draw();
}
// outline
GL11.glColor4f(lR, lG, lB, 1f);
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y1, 0.0D);
tesselator.addVertex((double) x1, (double) y2, 0.0D);
tesselator.addVertex((double) x1 + 1, (double) y2, 0.0D);
tesselator.addVertex((double) x1 + 1, (double) y1, 0.0D);
tesselator.draw();
tesselator.startDrawingQuads();
tesselator.addVertex((double) x2 - 1, (double) y1, 0.0D);
tesselator.addVertex((double) x2 - 1, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y1, 0.0D);
tesselator.draw();
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y1, 0.0D);
tesselator.addVertex((double) x1, (double) y1 + 1, 0.0D);
tesselator.addVertex((double) x2, (double) y1 + 1, 0.0D);
tesselator.addVertex((double) x2, (double) y1, 0.0D);
tesselator.draw();
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y2 - 1, 0.0D);
tesselator.addVertex((double) x1, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2 - 1, 0.0D);
tesselator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
@Override
protected void drawSlot(int slotID, int width, int slotY, int slotHeight, Tessellator tessellator)
{
if (slotID < commands.size())
{
String command = commands.get(slotID);
if (isSelected(slotID))
drawOutlineRect(this.left, this.left + width, this.top + slotY, this.top + slotY + slotHeight, -1, -1, -1, 0.5f, 0.5f, 0.5f);
this.mc.fontRenderer.drawString(command, this.left + 4, slotY + 4, 0xAAAAAA, false);
}
}
}
package assemblyline.client.gui;
import java.util.ArrayList;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import cpw.mods.fml.client.GuiScrollingList;
public class GuiCommandList extends GuiScrollingList
{
private ArrayList<String> commands;
private int selIndex;
private Minecraft mc;
public GuiCommandList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight)
{
super(client, width, height, top, bottom, left, entryHeight);
commands = new ArrayList<String>();
selIndex = -1;
this.mc = client;
}
public void setCommands(ArrayList<String> commands)
{
this.commands = (ArrayList<String>) commands.clone();
}
@Override
protected int getSize()
{
return commands.size();
}
@Override
protected void elementClicked(int index, boolean doubleClick)
{
selIndex = index;
}
@Override
protected boolean isSelected(int index)
{
return selIndex == index;
}
@Override
protected void drawBackground()
{
drawOutlineRect(this.left, this.left + this.listWidth, this.top, this.top + this.listHeight, 0, 0, 0, 0.5f, 0.5f, 0.5f);
}
public static void drawOutlineRect(int x1, int y1, int x2, int y2, float rR, float rG, float rB, float lR, float lG, float lB)
{
Tessellator tesselator = Tessellator.instance;
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(rR, rG, rB, 1f);
if (rR > 0 && rG > 0 && rB > 0)
{
// background
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y1, 0.0D);
tesselator.addVertex((double) x1, (double) y1, 0.0D);
tesselator.draw();
}
// outline
GL11.glColor4f(lR, lG, lB, 1f);
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y1, 0.0D);
tesselator.addVertex((double) x1, (double) y2, 0.0D);
tesselator.addVertex((double) x1 + 1, (double) y2, 0.0D);
tesselator.addVertex((double) x1 + 1, (double) y1, 0.0D);
tesselator.draw();
tesselator.startDrawingQuads();
tesselator.addVertex((double) x2 - 1, (double) y1, 0.0D);
tesselator.addVertex((double) x2 - 1, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y1, 0.0D);
tesselator.draw();
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y1, 0.0D);
tesselator.addVertex((double) x1, (double) y1 + 1, 0.0D);
tesselator.addVertex((double) x2, (double) y1 + 1, 0.0D);
tesselator.addVertex((double) x2, (double) y1, 0.0D);
tesselator.draw();
tesselator.startDrawingQuads();
tesselator.addVertex((double) x1, (double) y2 - 1, 0.0D);
tesselator.addVertex((double) x1, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2, 0.0D);
tesselator.addVertex((double) x2, (double) y2 - 1, 0.0D);
tesselator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
@Override
protected void drawSlot(int slotID, int width, int slotY, int slotHeight, Tessellator tessellator)
{
if (slotID < commands.size())
{
String command = commands.get(slotID);
if (isSelected(slotID))
drawOutlineRect(this.left, this.left + width, this.top + slotY, this.top + slotY + slotHeight, -1, -1, -1, 0.5f, 0.5f, 0.5f);
this.mc.fontRenderer.drawString(command, this.left + 4, slotY + 4, 0xAAAAAA, false);
}
}
}

View file

@ -40,6 +40,8 @@ public class CommonProxy implements IGuiHandler
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
//System.out.println("Server GUI request for ID " + ID);
switch (ID)
{

View file

@ -71,7 +71,7 @@ public class TileEntityCrate extends TileEntityImprintable implements ISidedInve
{
return this.containingItems[par1];
}
@Override
public ItemStack decrStackSize(int par1, int par2)
{

View file

@ -1,6 +1,6 @@
package assemblyline.common.machine.encoder;
public interface IInventoryWatcher
{
public void inventoryChanged();
}
package assemblyline.common.machine.encoder;
public interface IInventoryWatcher
{
public void inventoryChanged();
}

View file

@ -1,148 +1,148 @@
package assemblyline.common.machine.encoder;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import universalelectricity.prefab.tile.TileEntityAdvanced;
public class TileEntityEncoder extends TileEntityAdvanced implements ISidedInventory
{
private ItemStack disk;
private IInventoryWatcher watcher;
public TileEntityEncoder()
{
super();
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
if (slot == 0)
return disk;
return null;
}
@Override
public ItemStack decrStackSize(int slot, int amount)
{
if (slot == 0)
{
if (amount >= 1)
{
ItemStack ret = disk.copy();
disk = null;
return ret;
}
}
watcher.inventoryChanged();
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
if (slot == 0)
{
if (stack != null)
{
if (stack.stackSize > 1)
{
stack.stackSize = 1;
}
}
disk = stack;
}
if (watcher != null)
watcher.inventoryChanged();
}
@Override
public String getInvName()
{
return "Encoder";
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
public void setWatcher(IInventoryWatcher watcher)
{
this.watcher = watcher;
}
public IInventoryWatcher getWatcher()
{
return this.watcher;
}
@Override
public int getStartInventorySide(ForgeDirection side)
{
return 0;
}
@Override
public int getSizeInventorySide(ForgeDirection side)
{
return (side == ForgeDirection.UP) ? 1 : 0;
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
NBTTagCompound diskNBT = new NBTTagCompound();
disk.writeToNBT(diskNBT);
nbt.setCompoundTag("disk", diskNBT);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
if (diskNBT != null)
{
disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
}
}
package assemblyline.common.machine.encoder;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import universalelectricity.prefab.tile.TileEntityAdvanced;
public class TileEntityEncoder extends TileEntityAdvanced implements ISidedInventory
{
private ItemStack disk;
private IInventoryWatcher watcher;
public TileEntityEncoder()
{
super();
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
if (slot == 0)
return disk;
return null;
}
@Override
public ItemStack decrStackSize(int slot, int amount)
{
if (slot == 0)
{
if (amount >= 1)
{
ItemStack ret = disk.copy();
disk = null;
return ret;
}
}
watcher.inventoryChanged();
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
if (slot == 0)
{
if (stack != null)
{
if (stack.stackSize > 1)
{
stack.stackSize = 1;
}
}
disk = stack;
}
if (watcher != null)
watcher.inventoryChanged();
}
@Override
public String getInvName()
{
return "Encoder";
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
public void setWatcher(IInventoryWatcher watcher)
{
this.watcher = watcher;
}
public IInventoryWatcher getWatcher()
{
return this.watcher;
}
@Override
public int getStartInventorySide(ForgeDirection side)
{
return 0;
}
@Override
public int getSizeInventorySide(ForgeDirection side)
{
return (side == ForgeDirection.UP) ? 1 : 0;
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
NBTTagCompound diskNBT = new NBTTagCompound();
disk.writeToNBT(diskNBT);
nbt.setCompoundTag("disk", diskNBT);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
if (diskNBT != null)
{
disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
}
}