Worked on encoder more

Also made Disks only show the number of commands on them
This commit is contained in:
Brian Ricketts 2013-01-02 14:12:27 -06:00
parent e7a0d11263
commit 84c74bc589
7 changed files with 258 additions and 216 deletions

View file

@ -6,8 +6,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import universalelectricity.core.vector.Vector3;
import assemblyline.client.gui.GuiImprinter;
import assemblyline.client.gui.GuiEncoder;
import assemblyline.client.gui.GuiImprinter;
import assemblyline.client.render.BlockRenderingHandler;
import assemblyline.client.render.RenderConveyorBelt;
import assemblyline.client.render.RenderCrate;
@ -22,6 +22,7 @@ import assemblyline.common.machine.TileEntityRejector;
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
import assemblyline.common.machine.detector.TileEntityDetector;
import assemblyline.common.machine.encoder.ContainerEncoder;
import assemblyline.common.machine.encoder.TileEntityEncoder;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
@ -57,7 +58,8 @@ public class ClientProxy extends CommonProxy
case GUI_STAMPER:
return new GuiImprinter(player.inventory, world, new Vector3(x, y, z));
case GUI_ENCODER:
return new GuiEncoder(player.inventory, world, new Vector3(x, y, z), (ContainerEncoder) getServerGuiElement(ID, player, world, x, y, z));
if (tileEntity != null && tileEntity instanceof TileEntityEncoder)
return new GuiEncoder(player.inventory, world, new Vector3(x, y, z), (TileEntityEncoder) tileEntity);
}
return null;

View file

@ -1,5 +1,13 @@
package assemblyline.client.gui;
import static org.lwjgl.opengl.GL11.GL_LIGHTING;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.ArrayList;
import net.minecraft.client.gui.GuiButton;
@ -12,85 +20,100 @@ import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import cpw.mods.fml.client.GuiScrollingList;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.TranslationHelper;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.encoder.ContainerEncoder;
import assemblyline.common.machine.encoder.IInventoryWatcher;
import assemblyline.common.machine.encoder.ItemDisk;
import assemblyline.common.machine.encoder.TileEntityEncoder;
public class GuiEncoder extends GuiContainer implements IInventoryWatcher
{
private int containerWidth;
private int containerHeight;
private ContainerEncoder encoderContainer;
private TileEntityEncoder tileEntity;
private int x, y, z;
private ArrayList<String> commands;
// list stuff
private int minCommand;
private GuiButton addButton;
private GuiButton delButton;
private GuiButton pUpButton;
private GuiButton pDnButton;
private GuiTextField commandField;
public GuiEncoder(InventoryPlayer par1InventoryPlayer, World worldObj, Vector3 position, ContainerEncoder encoderContainer)
public GuiEncoder(InventoryPlayer par1InventoryPlayer, World worldObj, Vector3 position, TileEntityEncoder tileEntity)
{
super(new ContainerEncoder(par1InventoryPlayer, worldObj, position));
super(new ContainerEncoder(par1InventoryPlayer, worldObj, position, tileEntity));
this.ySize = 256;
this.encoderContainer = encoderContainer;
if (encoderContainer != null)
this.tileEntity = tileEntity;
if (tileEntity != null)
{
encoderContainer.setWatcher(this);
}
this.x = position.intX();
this.y = position.intY();
this.z = position.intZ();
}
@Override
public void initGui()
{
super.initGui();
this.allowUserInput = true;
containerWidth = (this.width - this.xSize) / 2;
containerHeight = (this.height - this.ySize) / 2;
addButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 148, 18, 20, "+");
delButton = new GuiButton(1, containerWidth + (xSize - 43), containerHeight + 148, 18, 20, "-");
pUpButton = new GuiButton(2, containerWidth + (xSize - 25), containerHeight + 48 , 18, 20, "");
pUpButton = new GuiButton(2, containerWidth + (xSize - 25), containerHeight + 48, 18, 20, "");
pDnButton = new GuiButton(3, containerWidth + (xSize - 25), containerHeight + 128, 18, 20, "");
commandField = new GuiTextField(fontRenderer, 8, 149, xSize - 52, 18);
//commandList = new GuiCommandList(mc, xSize - 7, 128, 7, 120, 170, 20);
// commandList = new GuiCommandList(mc, xSize - 7, 128, 7, 120, 170, 20);
controlList.add(addButton);
controlList.add(delButton);
controlList.add(pUpButton);
controlList.add(pDnButton);
minCommand = 0;
}
@Override
protected void actionPerformed(GuiButton button)
{
switch (button.id)
{
case 0: //add
case 0: // add
{
if (encoderContainer != null)
if (!commandField.getText().equals(""))
{
ItemStack disk = encoderContainer.getStackInSlot(0);
if (disk != null)
if (tileEntity != null)
{
ItemStack disk = tileEntity.getStackInSlot(0);
if (disk != null)
{
ArrayList<String> tempCmds = ItemDisk.getCommands(disk);
tempCmds.add(commandField.getText());
ItemDisk.setCommands(disk, tempCmds);
tileEntity.setInventorySlotContents(0, disk);
//TODO: Make the client send the server the new command to be added
}
}
commandField.setText("");
}
commandField.setText("");
break;
}
case 1: //subtract
case 1: // subtract
{
break;
}
}
@ -102,10 +125,12 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
glColor4f(1, 1, 1, 1);
glDisable(GL_LIGHTING);
this.fontRenderer.drawString(TranslationHelper.getLocal("tile.encoder.name"), 68, 6, 4210752);
this.fontRenderer.drawString("Disk:", 56, 28, 4210752);
//render page up and page down buttons
// render page up and page down buttons
glPushMatrix();
glTranslatef(pUpButton.xPosition - containerWidth + 6, pUpButton.yPosition - containerHeight + 7, 0);
this.fontRenderer.drawString("^", 1, 1, 0x444444);
@ -118,27 +143,35 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
this.fontRenderer.drawString("^", -1, -1, 0x444444);
this.fontRenderer.drawString("^", 0, 0, 0xFFFFFF);
glPopMatrix();
if (commands != null)
{
drawCommands();
}
commandField.drawTextBox();
}
private void drawCommands()
{
for (int i = minCommand; i < minCommand + 8; i++)
{
}
}
private void drawCommand(String command, int x, int y)
{
}
@Override
protected void mouseClicked(int x, int y, int button)
{
super.mouseClicked(x, y, button);
commandField.mouseClicked(x - containerWidth, y - containerHeight, button);
}
@Override
protected void keyTyped(char character, int keycode)
{
@ -161,11 +194,11 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
int var4 = this.mc.renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "gui_encoder.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(var4);
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
drawOutlineRect(containerWidth + 7, containerHeight + 48, containerWidth + (xSize - 25), containerHeight + 48 + 100, 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;
@ -216,9 +249,17 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
private void updateCommands()
{
if (tileEntity != null)
{
ItemStack disk = tileEntity.getStackInSlot(0);
if (disk != null)
{
commands = ItemDisk.getCommands(disk);
}
}
minCommand = 0;
}
@Override
public void inventoryChanged()
{

View file

@ -10,6 +10,7 @@ import assemblyline.common.machine.TileEntityRejector;
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
import assemblyline.common.machine.detector.TileEntityDetector;
import assemblyline.common.machine.encoder.ContainerEncoder;
import assemblyline.common.machine.encoder.TileEntityEncoder;
import assemblyline.common.machine.imprinter.ContainerImprinter;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.registry.GameRegistry;
@ -32,6 +33,7 @@ public class CommonProxy implements IGuiHandler
GameRegistry.registerTileEntity(TileEntityManipulator.class, "ALManipulator");
GameRegistry.registerTileEntity(TileEntityCrate.class, "ALCrate");
GameRegistry.registerTileEntity(TileEntityDetector.class, "ALDetector");
GameRegistry.registerTileEntity(TileEntityEncoder.class, "ALEncoder");
}
@Override
@ -44,7 +46,10 @@ public class CommonProxy implements IGuiHandler
case GUI_STAMPER:
return new ContainerImprinter(player.inventory, world, new Vector3(x, y, z));
case GUI_ENCODER:
return new ContainerEncoder(player.inventory, world, new Vector3(x, y, z));
{
if (tileEntity != null && tileEntity instanceof TileEntityEncoder)
return new ContainerEncoder(player.inventory, world, new Vector3(x, y, z), (TileEntityEncoder) tileEntity);
}
}
return null;

View file

@ -2,6 +2,7 @@ package assemblyline.common.machine.encoder;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.prefab.BlockMachine;
import universalelectricity.prefab.UETab;
@ -50,5 +51,16 @@ public class BlockEncoder extends BlockMachine
return true;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return createNewTileEntity(world, 0);
}
@Override
public TileEntity createNewTileEntity(World world, int metadata)
{
return new TileEntityEncoder();
}
}

View file

@ -18,22 +18,23 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.ReflectionHelper;
public class ContainerEncoder extends Container implements IInventory
public class ContainerEncoder extends Container
{
private ItemStack[] containingItems = new ItemStack[1];
private World worldObj;
private Vector3 position;
private InventoryPlayer inventoryPlayer;
private IInventoryWatcher watcher;
private TileEntityEncoder encoder;
public ContainerEncoder(InventoryPlayer inventoryPlayer, World worldObj, Vector3 position)
public ContainerEncoder(InventoryPlayer inventoryPlayer, World worldObj, Vector3 position, TileEntityEncoder encoder)
{
this.worldObj = worldObj;
this.position = position;
this.inventoryPlayer = inventoryPlayer;
this.encoder = encoder;
// Disk
this.addSlotToContainer(new Slot(this, 0, 80, 24));
this.addSlotToContainer(new Slot(encoder, 0, 80, 24));
// Output Disk
//this.addSlotToContainer(new SlotDiskResult(this, 2, 136, 24));
@ -52,16 +53,6 @@ public class ContainerEncoder extends Container implements IInventory
this.addSlotToContainer(new Slot(inventoryPlayer, var3, 8 + var3 * 18, 228));
}
}
public void setWatcher(IInventoryWatcher watcher)
{
this.watcher = watcher;
}
public IInventoryWatcher getWatcher()
{
return this.watcher;
}
@Override
public void updateCraftingResults()
@ -72,7 +63,7 @@ public class ContainerEncoder extends Container implements IInventory
@Override
public boolean canInteractWith(EntityPlayer player)
{
return this.isUseableByPlayer(player);
return encoder.isUseableByPlayer(player);
}
/**
@ -89,18 +80,12 @@ public class ContainerEncoder extends Container implements IInventory
ItemStack slotStack = slotObj.getStack();
copyStack = slotStack.copy();
if (slot == 2)
{
setInventorySlotContents(0, null); // Prevents disk from being duplicated
}
if (slot > 2)
if (slot > 1)
{
if (this.getSlot(0).isItemValid(slotStack))
{
if (!this.mergeItemStack(slotStack, 0, 1, false)) { return null; }
}
else if (!this.mergeItemStack(slotStack, 1, 2, false)) { return null; }
}
else if (!this.mergeItemStack(slotStack, this.containingItems.length, 37, false)) { return null; }
@ -118,154 +103,6 @@ public class ContainerEncoder extends Container implements IInventory
slotObj.onPickupFromSlot(player, slotStack);
}
onInventoryChanged();
return copyStack;
}
@Override
public int getSizeInventory()
{
return this.containingItems.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return this.containingItems[slot];
}
/**
* Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a new stack.
*/
@Override
public ItemStack decrStackSize(int slot, int amount)
{
if (this.containingItems[slot] != null)
{
ItemStack var3 = this.containingItems[slot];
this.containingItems[slot] = null;
return var3;
}
else
{
return null;
}
}
/**
* When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - like when you close a workbench GUI.
*/
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
if (this.containingItems[slot] != null && slot != 2)
{
ItemStack var2 = this.containingItems[slot];
this.containingItems[slot] = null;
return var2;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
@Override
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
if (par1 < this.containingItems.length)
{
this.containingItems[par1] = par2ItemStack;
}
}
@Override
public String getInvName()
{
return "Encoder";
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void onInventoryChanged()
{
/**
* Makes the stamping recipe for disks
*/
boolean didStamp = false;
if (this.getStackInSlot(0) != null && this.getStackInSlot(1) != null)
{
if (this.getStackInSlot(0).getItem() instanceof ItemDisk)
{
ItemStack outputStack = this.getStackInSlot(0).copy();
outputStack.stackSize = 1;
ArrayList<String> commands = ItemDisk.getCommands(outputStack);
boolean filteringItemExists = false;
for (String command : commands)
{
// remove commands
}
if (!filteringItemExists)
{
// add commands
}
ItemDisk.setCommands(outputStack, commands);
this.setInventorySlotContents(2, outputStack);
didStamp = true;
}
}
if (!didStamp)
{
this.setInventorySlotContents(2, null);
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return true;
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
@Override
public void onCraftGuiClosed(EntityPlayer player)
{
super.onCraftGuiClosed(player);
if (!this.worldObj.isRemote)
{
for (int slot = 0; slot < this.getSizeInventory(); ++slot)
{
ItemStack itemStack = this.getStackInSlotOnClosing(slot);
if (itemStack != null && slot != 4)
{
player.dropPlayerItem(itemStack);
}
}
}
}
}

View file

@ -36,10 +36,7 @@ public class ItemDisk extends Item
if (commands.size() > 0)
{
for (String command : commands)
{
list.add(command);
}
list.add(commands.size() + " commands");
}
else
{

View file

@ -0,0 +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);
}
}
}