diff --git a/resources/assemblyline/language/en_US.properties b/resources/assemblyline/language/en_US.properties index 829a09c1..2b6bf2f4 100644 --- a/resources/assemblyline/language/en_US.properties +++ b/resources/assemblyline/language/en_US.properties @@ -8,6 +8,7 @@ assemblyline.gui.crafting=Crafting tile.crate.name=Crate tile.conveyorBelt.name=Conveyor Belt tile.imprinter.name=Imprinter +tile.programmer.name=Programmer tile.engineerTable.name=Engineer's Table tile.detector.name=Detector tile.armbot.name=Armbot @@ -16,4 +17,5 @@ tile.rejector.name=Rejector # Items item.imprint.name=Imprint +item.disk.name=Disk item.blueprint.name=Blueprint \ No newline at end of file diff --git a/resources/assemblyline/textures/gui_programmer.png b/resources/assemblyline/textures/gui_programmer.png new file mode 100644 index 00000000..ba54dfa4 Binary files /dev/null and b/resources/assemblyline/textures/gui_programmer.png differ diff --git a/src/minecraft/assemblyline/client/ClientProxy.java b/src/minecraft/assemblyline/client/ClientProxy.java index 5711d0d4..713d8ac8 100644 --- a/src/minecraft/assemblyline/client/ClientProxy.java +++ b/src/minecraft/assemblyline/client/ClientProxy.java @@ -7,6 +7,7 @@ import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import universalelectricity.core.vector.Vector3; import assemblyline.client.gui.GuiImprinter; +import assemblyline.client.gui.GuiProgrammer; import assemblyline.client.render.BlockRenderingHandler; import assemblyline.client.render.RenderConveyorBelt; import assemblyline.client.render.RenderCrate; @@ -54,6 +55,8 @@ public class ClientProxy extends CommonProxy { case GUI_STAMPER: return new GuiImprinter(player.inventory, world, new Vector3(x, y, z)); + case GUI_PROGRAMMER: + return new GuiProgrammer(player.inventory, world, new Vector3(x, y, z)); } return null; diff --git a/src/minecraft/assemblyline/client/gui/GuiProgrammer.java b/src/minecraft/assemblyline/client/gui/GuiProgrammer.java new file mode 100644 index 00000000..0827fbc4 --- /dev/null +++ b/src/minecraft/assemblyline/client/gui/GuiProgrammer.java @@ -0,0 +1,46 @@ +package assemblyline.client.gui; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; + +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.TranslationHelper; +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.programmer.ContainerProgrammer; + +public class GuiProgrammer extends GuiContainer +{ + private int containerWidth; + private int containerHeight; + + public GuiProgrammer(InventoryPlayer par1InventoryPlayer, World worldObj, Vector3 position) + { + super(new ContainerProgrammer(par1InventoryPlayer, worldObj, position)); + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items) + */ + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) + { + this.fontRenderer.drawString(TranslationHelper.getLocal("tile.programmer.name"), 68, 6, 4210752); + } + + /** + * Draw the background layer for the GuiContainer (everything behind the items) + */ + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) + { + int var4 = this.mc.renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "gui_programmer.png"); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.renderEngine.bindTexture(var4); + containerWidth = (this.width - this.xSize) / 2; + containerHeight = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize); + } +} diff --git a/src/minecraft/assemblyline/common/AssemblyLine.java b/src/minecraft/assemblyline/common/AssemblyLine.java index 72df6fd5..d80b011c 100644 --- a/src/minecraft/assemblyline/common/AssemblyLine.java +++ b/src/minecraft/assemblyline/common/AssemblyLine.java @@ -22,6 +22,8 @@ import assemblyline.common.machine.detector.BlockDetector; import assemblyline.common.machine.imprinter.BlockImprinter; import assemblyline.common.machine.imprinter.ItemImprinter; import assemblyline.common.machine.machine.BlockRejector; +import assemblyline.common.machine.programmer.BlockProgrammer; +import assemblyline.common.machine.programmer.ItemDisk; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; @@ -67,11 +69,13 @@ public class AssemblyLine public static Block blockEncoder; public static Block blockCrate; public static Block blockImprinter; + public static Block blockProgrammer; public static Block blockDetector; public static Block blockRejector; public static final int ITEM_ID_PREFIX = 3030; public static Item itemImprint; + public static Item itemDisk; @PreInit public void preInit(FMLPreInitializationEvent event) @@ -87,8 +91,10 @@ public class AssemblyLine blockImprinter = new BlockImprinter(CONFIGURATION.getBlock("Imprinter", BLOCK_ID_PREFIX + 4).getInt(), 0); blockDetector = new BlockDetector(CONFIGURATION.getBlock("Detector", BLOCK_ID_PREFIX + 5).getInt(), 1); blockRejector = new BlockRejector(CONFIGURATION.getBlock("Rejector", BLOCK_ID_PREFIX + 6).getInt()); + blockProgrammer = new BlockProgrammer(CONFIGURATION.getBlock("Programmer", BLOCK_ID_PREFIX + 7).getInt(), 0); itemImprint = new ItemImprinter(CONFIGURATION.getBlock("Imprint", ITEM_ID_PREFIX).getInt()); + itemDisk = new ItemDisk(CONFIGURATION.getBlock("Disk", ITEM_ID_PREFIX + 1).getInt()); CONFIGURATION.save(); NetworkRegistry.instance().registerGuiHandler(this, this.proxy); @@ -97,6 +103,7 @@ public class AssemblyLine GameRegistry.registerBlock(blockManipulator, "Manipulator"); // GameRegistry.registerBlock(blockEncoder, "Encoder"); GameRegistry.registerBlock(blockImprinter, "Imprinter"); + GameRegistry.registerBlock(blockProgrammer, "Programmer"); GameRegistry.registerBlock(blockDetector, "Detector"); GameRegistry.registerBlock(blockRejector, "Rejector"); diff --git a/src/minecraft/assemblyline/common/CommonProxy.java b/src/minecraft/assemblyline/common/CommonProxy.java index 01f09d41..79019efe 100644 --- a/src/minecraft/assemblyline/common/CommonProxy.java +++ b/src/minecraft/assemblyline/common/CommonProxy.java @@ -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.imprinter.ContainerImprinter; +import assemblyline.common.machine.programmer.ContainerProgrammer; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.registry.GameRegistry; @@ -17,6 +18,7 @@ public class CommonProxy implements IGuiHandler { public static final int GUI_STAMPER = 1; public static final int GUI_ARCHITECHT_TABLE = 2; + public static final int GUI_PROGRAMMER = 3; public void preInit() { @@ -41,6 +43,8 @@ public class CommonProxy implements IGuiHandler { case GUI_STAMPER: return new ContainerImprinter(player.inventory, world, new Vector3(x, y, z)); + case GUI_PROGRAMMER: + return new ContainerProgrammer(player.inventory, world, new Vector3(x, y, z)); } return null; diff --git a/src/minecraft/assemblyline/common/machine/programmer/BlockProgrammer.java b/src/minecraft/assemblyline/common/machine/programmer/BlockProgrammer.java new file mode 100644 index 00000000..bd160415 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/programmer/BlockProgrammer.java @@ -0,0 +1,54 @@ +package assemblyline.common.machine.programmer; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import universalelectricity.prefab.BlockMachine; +import universalelectricity.prefab.UETab; +import assemblyline.common.AssemblyLine; +import assemblyline.common.CommonProxy; + +public class BlockProgrammer extends BlockMachine +{ + public BlockProgrammer(int id, int texture) + { + super(id, Material.wood); + this.blockIndexInTexture = 4; + this.setBlockName("programmer"); + this.setCreativeTab(UETab.INSTANCE); + this.setTextureFile(AssemblyLine.BLOCK_TEXTURE_PATH); + } + + /** + * Returns the block texture based on the side being looked at. Args: side + */ + public int getBlockTextureFromSide(int side) + { + if (side == 0) + { + return this.blockIndexInTexture; + + } + else if (side == 1) { return this.blockIndexInTexture + 1; + + } + + return this.blockIndexInTexture + 2; + } + + /** + * Called upon block activation (right click on the block.) + */ + @Override + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) + { + if (!world.isRemote) + { + entityPlayer.openGui(AssemblyLine.instance, CommonProxy.GUI_PROGRAMMER, world, x, y, z); + } + + return true; + + } + +} diff --git a/src/minecraft/assemblyline/common/machine/programmer/ContainerProgrammer.java b/src/minecraft/assemblyline/common/machine/programmer/ContainerProgrammer.java new file mode 100644 index 00000000..b839f194 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/programmer/ContainerProgrammer.java @@ -0,0 +1,262 @@ +package assemblyline.common.machine.programmer; + +import java.util.ArrayList; + +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.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraft.world.World; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; +import universalelectricity.core.vector.Vector3; +import cpw.mods.fml.relauncher.ReflectionHelper; + +public class ContainerProgrammer extends Container implements IInventory +{ + private ItemStack[] containingItems = new ItemStack[3]; + private World worldObj; + private Vector3 position; + private InventoryPlayer inventoryPlayer; + + public ContainerProgrammer(InventoryPlayer inventoryPlayer, World worldObj, Vector3 position) + { + this.worldObj = worldObj; + this.position = position; + this.inventoryPlayer = inventoryPlayer; + + // Paper Input + this.addSlotToContainer(new SlotDisk(this, 0, 42, 24)); + // Item Stamp + this.addSlotToContainer(new Slot(this, 1, 78, 24)); + // Output Filter + this.addSlotToContainer(new SlotDiskResult(this, 2, 136, 24)); + + int var3; + + for (var3 = 0; var3 < 3; ++var3) + { + for (int var4 = 0; var4 < 9; ++var4) + { + this.addSlotToContainer(new Slot(inventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } + + for (var3 = 0; var3 < 9; ++var3) + { + this.addSlotToContainer(new Slot(inventoryPlayer, var3, 8 + var3 * 18, 142)); + } + } + + @Override + public void updateCraftingResults() + { + super.updateCraftingResults(); + } + + @Override + public boolean canInteractWith(EntityPlayer player) + { + return this.isUseableByPlayer(player); + } + + /** + * Called to transfer a stack from one inventory to the other eg. when shift clicking. + */ + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slot) + { + ItemStack copyStack = null; + Slot slotObj = (Slot) this.inventorySlots.get(slot); + + if (slotObj != null && slotObj.getHasStack()) + { + ItemStack slotStack = slotObj.getStack(); + copyStack = slotStack.copy(); + + if (slot == 2) + { + setInventorySlotContents(0, null); // Prevents disk from being duplicated + } + + if (slot > 2) + { + 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; } + + if (slotStack.stackSize == 0) + { + slotObj.putStack((ItemStack) null); + } + else + { + slotObj.onSlotChanged(); + } + + if (slotStack.stackSize == copyStack.stackSize) { return null; } + + 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 "Programmer"; + } + + @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 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); + } + } + } + } +} diff --git a/src/minecraft/assemblyline/common/machine/programmer/ItemDisk.java b/src/minecraft/assemblyline/common/machine/programmer/ItemDisk.java new file mode 100644 index 00000000..1e5dbff1 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/programmer/ItemDisk.java @@ -0,0 +1,90 @@ +package assemblyline.common.machine.programmer; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import universalelectricity.prefab.UETab; +import assemblyline.common.AssemblyLine; + +public class ItemDisk extends Item +{ + public ItemDisk(int id) + { + super(id); + this.setItemName("disk"); + this.setIconIndex(1); + this.setCreativeTab(UETab.INSTANCE); + this.setHasSubtypes(true); + this.setTextureFile(AssemblyLine.ITEM_TEXTURE_PATH); + } + + @Override + public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) + { + List commands = getCommands(itemStack); + + if (commands.size() > 0) + { + for (String command : commands) + { + list.add(command); + } + } + else + { + list.add("No commands"); + } + } + + /** + * Saves the list of items to filter out inside. + */ + public static void setCommands(ItemStack itemStack, ArrayList commands) + { + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + NBTTagList nbt = new NBTTagList(); + + for (int i = 0; i < commands.size(); ++i) + { + if (commands.get(i) != null) + { + NBTTagCompound newCompound = new NBTTagCompound(); + newCompound.setString("command", commands.get(i)); + nbt.appendTag(newCompound); + } + } + + itemStack.getTagCompound().setTag("Commands", nbt); + } + + public static ArrayList getCommands(ItemStack itemStack) + { + ArrayList commands = new ArrayList(); + + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound nbt = itemStack.getTagCompound(); + NBTTagList tagList = nbt.getTagList("Commands"); + + for (int i = 0; i < tagList.tagCount(); ++i) + { + NBTTagCompound curTag = (NBTTagCompound) tagList.tagAt(i); + String cmd = curTag.getString("command"); + commands.add(cmd); + } + + return commands; + } +} diff --git a/src/minecraft/assemblyline/common/machine/programmer/SlotDisk.java b/src/minecraft/assemblyline/common/machine/programmer/SlotDisk.java new file mode 100644 index 00000000..9e3a8c41 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/programmer/SlotDisk.java @@ -0,0 +1,21 @@ +package assemblyline.common.machine.programmer; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import assemblyline.common.AssemblyLine; + +public class SlotDisk extends Slot +{ + + public SlotDisk(IInventory par1iInventory, int par2, int par3, int par4) + { + super(par1iInventory, par2, par3, par4); + } + + public boolean isItemValid(ItemStack itemStack) + { + return itemStack.itemID == AssemblyLine.itemDisk.shiftedIndex; + } + +} diff --git a/src/minecraft/assemblyline/common/machine/programmer/SlotDiskResult.java b/src/minecraft/assemblyline/common/machine/programmer/SlotDiskResult.java new file mode 100644 index 00000000..6d1516f0 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/programmer/SlotDiskResult.java @@ -0,0 +1,42 @@ +package assemblyline.common.machine.programmer; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotDiskResult extends Slot +{ + + public SlotDiskResult(IInventory par1iInventory, int par2, int par3, int par4) + { + super(par1iInventory, par2, par3, par4); + } + + @Override + public boolean isItemValid(ItemStack par1ItemStack) + { + return false; + } + + @Override + public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) + { + super.onPickupFromSlot(par1EntityPlayer, par2ItemStack); + + if (this.inventory.getStackInSlot(0) != null) + { + this.inventory.getStackInSlot(0).stackSize--; + if (this.inventory.getStackInSlot(0).stackSize <= 0) + { + this.inventory.setInventorySlotContents(0, null); + } + } + /* + * if (this.inventory.getStackInSlot(1) != null) { + * this.inventory.getStackInSlot(1).stackSize--; if + * (this.inventory.getStackInSlot(1).stackSize <= 1) { + * this.inventory.setInventorySlotContents(1, null); } } + */ + } +}