Worked on encoder more
Also made Disks only show the number of commands on them
This commit is contained in:
parent
e7a0d11263
commit
84c74bc589
7 changed files with 258 additions and 216 deletions
|
@ -6,8 +6,8 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
import assemblyline.client.gui.GuiImprinter;
|
|
||||||
import assemblyline.client.gui.GuiEncoder;
|
import assemblyline.client.gui.GuiEncoder;
|
||||||
|
import assemblyline.client.gui.GuiImprinter;
|
||||||
import assemblyline.client.render.BlockRenderingHandler;
|
import assemblyline.client.render.BlockRenderingHandler;
|
||||||
import assemblyline.client.render.RenderConveyorBelt;
|
import assemblyline.client.render.RenderConveyorBelt;
|
||||||
import assemblyline.client.render.RenderCrate;
|
import assemblyline.client.render.RenderCrate;
|
||||||
|
@ -22,6 +22,7 @@ import assemblyline.common.machine.TileEntityRejector;
|
||||||
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
|
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
|
||||||
import assemblyline.common.machine.detector.TileEntityDetector;
|
import assemblyline.common.machine.detector.TileEntityDetector;
|
||||||
import assemblyline.common.machine.encoder.ContainerEncoder;
|
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.ClientRegistry;
|
||||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||||
|
|
||||||
|
@ -57,7 +58,8 @@ public class ClientProxy extends CommonProxy
|
||||||
case GUI_STAMPER:
|
case GUI_STAMPER:
|
||||||
return new GuiImprinter(player.inventory, world, new Vector3(x, y, z));
|
return new GuiImprinter(player.inventory, world, new Vector3(x, y, z));
|
||||||
case GUI_ENCODER:
|
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;
|
return null;
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package assemblyline.client.gui;
|
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 java.util.ArrayList;
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
@ -12,38 +20,44 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
|
||||||
|
|
||||||
import cpw.mods.fml.client.GuiScrollingList;
|
|
||||||
|
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
import universalelectricity.prefab.TranslationHelper;
|
import universalelectricity.prefab.TranslationHelper;
|
||||||
import assemblyline.common.AssemblyLine;
|
import assemblyline.common.AssemblyLine;
|
||||||
import assemblyline.common.machine.encoder.ContainerEncoder;
|
import assemblyline.common.machine.encoder.ContainerEncoder;
|
||||||
import assemblyline.common.machine.encoder.IInventoryWatcher;
|
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
|
public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
||||||
{
|
{
|
||||||
private int containerWidth;
|
private int containerWidth;
|
||||||
private int containerHeight;
|
private int containerHeight;
|
||||||
private ContainerEncoder encoderContainer;
|
private TileEntityEncoder tileEntity;
|
||||||
|
private int x, y, z;
|
||||||
private ArrayList<String> commands;
|
private ArrayList<String> commands;
|
||||||
|
|
||||||
|
// list stuff
|
||||||
|
private int minCommand;
|
||||||
|
|
||||||
private GuiButton addButton;
|
private GuiButton addButton;
|
||||||
private GuiButton delButton;
|
private GuiButton delButton;
|
||||||
private GuiButton pUpButton;
|
private GuiButton pUpButton;
|
||||||
private GuiButton pDnButton;
|
private GuiButton pDnButton;
|
||||||
private GuiTextField commandField;
|
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.ySize = 256;
|
||||||
this.encoderContainer = encoderContainer;
|
this.tileEntity = tileEntity;
|
||||||
if (encoderContainer != null)
|
if (tileEntity != null)
|
||||||
{
|
{
|
||||||
encoderContainer.setWatcher(this);
|
|
||||||
}
|
}
|
||||||
|
this.x = position.intX();
|
||||||
|
this.y = position.intY();
|
||||||
|
this.z = position.intZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,15 +72,17 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
||||||
|
|
||||||
addButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 148, 18, 20, "+");
|
addButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 148, 18, 20, "+");
|
||||||
delButton = new GuiButton(1, containerWidth + (xSize - 43), 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, "");
|
pDnButton = new GuiButton(3, containerWidth + (xSize - 25), containerHeight + 128, 18, 20, "");
|
||||||
commandField = new GuiTextField(fontRenderer, 8, 149, xSize - 52, 18);
|
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(addButton);
|
||||||
controlList.add(delButton);
|
controlList.add(delButton);
|
||||||
controlList.add(pUpButton);
|
controlList.add(pUpButton);
|
||||||
controlList.add(pDnButton);
|
controlList.add(pDnButton);
|
||||||
|
|
||||||
|
minCommand = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,21 +90,28 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
||||||
{
|
{
|
||||||
switch (button.id)
|
switch (button.id)
|
||||||
{
|
{
|
||||||
case 0: //add
|
case 0: // add
|
||||||
{
|
{
|
||||||
if (encoderContainer != null)
|
if (!commandField.getText().equals(""))
|
||||||
{
|
{
|
||||||
ItemStack disk = encoderContainer.getStackInSlot(0);
|
if (tileEntity != null)
|
||||||
if (disk != 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;
|
break;
|
||||||
}
|
}
|
||||||
case 1: //subtract
|
case 1: // subtract
|
||||||
{
|
{
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -102,10 +125,12 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
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(TranslationHelper.getLocal("tile.encoder.name"), 68, 6, 4210752);
|
||||||
this.fontRenderer.drawString("Disk:", 56, 28, 4210752);
|
this.fontRenderer.drawString("Disk:", 56, 28, 4210752);
|
||||||
|
|
||||||
//render page up and page down buttons
|
// render page up and page down buttons
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(pUpButton.xPosition - containerWidth + 6, pUpButton.yPosition - containerHeight + 7, 0);
|
glTranslatef(pUpButton.xPosition - containerWidth + 6, pUpButton.yPosition - containerHeight + 7, 0);
|
||||||
this.fontRenderer.drawString("^", 1, 1, 0x444444);
|
this.fontRenderer.drawString("^", 1, 1, 0x444444);
|
||||||
|
@ -128,6 +153,14 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawCommands()
|
private void drawCommands()
|
||||||
|
{
|
||||||
|
for (int i = minCommand; i < minCommand + 8; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawCommand(String command, int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -216,7 +249,15 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
||||||
|
|
||||||
private void updateCommands()
|
private void updateCommands()
|
||||||
{
|
{
|
||||||
|
if (tileEntity != null)
|
||||||
|
{
|
||||||
|
ItemStack disk = tileEntity.getStackInSlot(0);
|
||||||
|
if (disk != null)
|
||||||
|
{
|
||||||
|
commands = ItemDisk.getCommands(disk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
minCommand = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,6 +10,7 @@ import assemblyline.common.machine.TileEntityRejector;
|
||||||
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
|
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
|
||||||
import assemblyline.common.machine.detector.TileEntityDetector;
|
import assemblyline.common.machine.detector.TileEntityDetector;
|
||||||
import assemblyline.common.machine.encoder.ContainerEncoder;
|
import assemblyline.common.machine.encoder.ContainerEncoder;
|
||||||
|
import assemblyline.common.machine.encoder.TileEntityEncoder;
|
||||||
import assemblyline.common.machine.imprinter.ContainerImprinter;
|
import assemblyline.common.machine.imprinter.ContainerImprinter;
|
||||||
import cpw.mods.fml.common.network.IGuiHandler;
|
import cpw.mods.fml.common.network.IGuiHandler;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
@ -32,6 +33,7 @@ public class CommonProxy implements IGuiHandler
|
||||||
GameRegistry.registerTileEntity(TileEntityManipulator.class, "ALManipulator");
|
GameRegistry.registerTileEntity(TileEntityManipulator.class, "ALManipulator");
|
||||||
GameRegistry.registerTileEntity(TileEntityCrate.class, "ALCrate");
|
GameRegistry.registerTileEntity(TileEntityCrate.class, "ALCrate");
|
||||||
GameRegistry.registerTileEntity(TileEntityDetector.class, "ALDetector");
|
GameRegistry.registerTileEntity(TileEntityDetector.class, "ALDetector");
|
||||||
|
GameRegistry.registerTileEntity(TileEntityEncoder.class, "ALEncoder");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,7 +46,10 @@ public class CommonProxy implements IGuiHandler
|
||||||
case GUI_STAMPER:
|
case GUI_STAMPER:
|
||||||
return new ContainerImprinter(player.inventory, world, new Vector3(x, y, z));
|
return new ContainerImprinter(player.inventory, world, new Vector3(x, y, z));
|
||||||
case GUI_ENCODER:
|
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;
|
return null;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package assemblyline.common.machine.encoder;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import universalelectricity.prefab.BlockMachine;
|
import universalelectricity.prefab.BlockMachine;
|
||||||
import universalelectricity.prefab.UETab;
|
import universalelectricity.prefab.UETab;
|
||||||
|
@ -51,4 +52,15 @@ public class BlockEncoder extends BlockMachine
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createNewTileEntity(World world)
|
||||||
|
{
|
||||||
|
return createNewTileEntity(world, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity createNewTileEntity(World world, int metadata)
|
||||||
|
{
|
||||||
|
return new TileEntityEncoder();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,22 +18,23 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
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 ItemStack[] containingItems = new ItemStack[1];
|
||||||
private World worldObj;
|
private World worldObj;
|
||||||
private Vector3 position;
|
private Vector3 position;
|
||||||
private InventoryPlayer inventoryPlayer;
|
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.worldObj = worldObj;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.inventoryPlayer = inventoryPlayer;
|
this.inventoryPlayer = inventoryPlayer;
|
||||||
|
this.encoder = encoder;
|
||||||
|
|
||||||
// Disk
|
// Disk
|
||||||
this.addSlotToContainer(new Slot(this, 0, 80, 24));
|
this.addSlotToContainer(new Slot(encoder, 0, 80, 24));
|
||||||
// Output Disk
|
// Output Disk
|
||||||
//this.addSlotToContainer(new SlotDiskResult(this, 2, 136, 24));
|
//this.addSlotToContainer(new SlotDiskResult(this, 2, 136, 24));
|
||||||
|
|
||||||
|
@ -53,16 +54,6 @@ public class ContainerEncoder extends Container implements IInventory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWatcher(IInventoryWatcher watcher)
|
|
||||||
{
|
|
||||||
this.watcher = watcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IInventoryWatcher getWatcher()
|
|
||||||
{
|
|
||||||
return this.watcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCraftingResults()
|
public void updateCraftingResults()
|
||||||
{
|
{
|
||||||
|
@ -72,7 +63,7 @@ public class ContainerEncoder extends Container implements IInventory
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer player)
|
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();
|
ItemStack slotStack = slotObj.getStack();
|
||||||
copyStack = slotStack.copy();
|
copyStack = slotStack.copy();
|
||||||
|
|
||||||
if (slot == 2)
|
if (slot > 1)
|
||||||
{
|
|
||||||
setInventorySlotContents(0, null); // Prevents disk from being duplicated
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slot > 2)
|
|
||||||
{
|
{
|
||||||
if (this.getSlot(0).isItemValid(slotStack))
|
if (this.getSlot(0).isItemValid(slotStack))
|
||||||
{
|
{
|
||||||
if (!this.mergeItemStack(slotStack, 0, 1, false)) { return null; }
|
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; }
|
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);
|
slotObj.onPickupFromSlot(player, slotStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
onInventoryChanged();
|
|
||||||
|
|
||||||
return copyStack;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,7 @@ public class ItemDisk extends Item
|
||||||
|
|
||||||
if (commands.size() > 0)
|
if (commands.size() > 0)
|
||||||
{
|
{
|
||||||
for (String command : commands)
|
list.add(commands.size() + " commands");
|
||||||
{
|
|
||||||
list.add(command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue