Attempted to make autocrafting

This commit is contained in:
Henry Mao 2012-12-27 20:05:15 +08:00
parent 91d48f4628
commit c4105e06bf
6 changed files with 208 additions and 38 deletions

View file

@ -1,6 +1,10 @@
# Assembly Line Language Properties
# @author Calclavia
# Gui
assemblyline.gui.crafting=Crafting
# Blocks
tile.crate.name=Crate
tile.conveyorBelt.name=Conveyor Belt

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -28,6 +28,7 @@ public class GuiStamper extends GuiContainer
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRenderer.drawString(TranslationHelper.getLocal("tile.stamper.name"), 68, 6, 4210752);
this.fontRenderer.drawString(TranslationHelper.getLocal("assemblyline.gui.crafting")+":", 25, 55, 4210752);
}
/**

View file

@ -8,26 +8,35 @@ 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 universalelectricity.core.vector.Vector3;
public class ContainerStamper extends Container implements IInventory
{
private ItemStack[] containingItems = new ItemStack[3];
private ItemStack[] containingItems = new ItemStack[5];
private World worldObj;
private Vector3 position;
private InventoryPlayer inventoryPlayer;
public ContainerStamper(InventoryPlayer par1InventoryPlayer, World worldObj, Vector3 position)
public ContainerStamper(InventoryPlayer inventoryPlayer, World worldObj, Vector3 position)
{
this.worldObj = worldObj;
this.position = position;
this.inventoryPlayer = inventoryPlayer;
// Paper Input
this.addSlotToContainer(new SlotFilter(this, 0, 30, 35));
this.addSlotToContainer(new SlotFilter(this, 0, 42, 24));
// Item Stamp
this.addSlotToContainer(new Slot(this, 1, 66, 35));
this.addSlotToContainer(new Slot(this, 1, 78, 24));
// Output Filter
this.addSlotToContainer(new SlotFilterResult(this, 2, 124, 35));
this.addSlotToContainer(new SlotFilterResult(this, 2, 136, 24));
// Crafting Slot
this.addSlotToContainer(new SlotFilter(this, 3, 78, 53));
this.addSlotToContainer(new SlotCraftingResult(this, this, 4, 136, 53));
int var3;
@ -35,13 +44,13 @@ public class ContainerStamper extends Container implements IInventory
{
for (int var4 = 0; var4 < 9; ++var4)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
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(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
this.addSlotToContainer(new Slot(inventoryPlayer, var3, 8 + var3 * 18, 142));
}
}
@ -50,32 +59,6 @@ public class ContainerStamper extends Container implements IInventory
{
super.updateCraftingResults();
if (this.getStackInSlot(0) != null && this.getStackInSlot(1) != null)
{
if (this.getStackInSlot(0).getItem() instanceof ItemFilter)
{
ItemStack outputStack = this.getStackInSlot(0).copy();
outputStack.stackSize = 1;
ArrayList<ItemStack> filters = ItemFilter.getFilters(outputStack);
for (ItemStack filteredStack : filters)
{
if (filteredStack.isItemEqual(this.getStackInSlot(1)))
{
this.setInventorySlotContents(2, null);
return;
}
}
filters.add(this.getStackInSlot(1));
ItemFilter.setFilters(outputStack, filters);
this.setInventorySlotContents(2, outputStack);
return;
}
}
this.setInventorySlotContents(2, null);
}
@Override
@ -98,7 +81,7 @@ public class ContainerStamper extends Container implements IInventory
ItemStack itemStack2 = itemStack.getStack();
itemStack3 = itemStack2.copy();
if (par1 > 2)
if (par1 > 4)
{
if (this.getSlot(0).isItemValid(itemStack2))
{
@ -106,7 +89,7 @@ public class ContainerStamper extends Container implements IInventory
}
else if (!this.mergeItemStack(itemStack2, 1, 2, false)) { return null; }
}
else if (!this.mergeItemStack(itemStack2, 3, 37, false)) { return null; }
else if (!this.mergeItemStack(itemStack2, this.containingItems.length, 37, false)) { return null; }
if (itemStack2.stackSize == 0)
{
@ -200,7 +183,137 @@ public class ContainerStamper extends Container implements IInventory
@Override
public void onInventoryChanged()
{
/**
* Makes the stamping recipe for filters
*/
boolean didStamp = false;
if (this.getStackInSlot(0) != null && this.getStackInSlot(1) != null)
{
if (this.getStackInSlot(0).getItem() instanceof ItemFilter)
{
ItemStack outputStack = this.getStackInSlot(0).copy();
outputStack.stackSize = 1;
ArrayList<ItemStack> filters = ItemFilter.getFilters(outputStack);
boolean failedCheck = false;
for (ItemStack filteredStack : filters)
{
if (filteredStack.isItemEqual(this.getStackInSlot(1)))
{
failedCheck = true;
}
}
if (!failedCheck)
{
filters.add(this.getStackInSlot(1));
ItemFilter.setFilters(outputStack, filters);
this.setInventorySlotContents(2, outputStack);
didStamp = true;
}
}
}
if (!didStamp)
{
this.setInventorySlotContents(2, null);
}
/**
* TODO WORK IN PROGRESS. Make filters able to autocraft into its item based on what is in the player's inventory
boolean didCraft = false;
if (this.getStackInSlot(3) != null)
{
if (this.getStackInSlot(3).getItem() instanceof ItemFilter)
{
ArrayList<ItemStack> filters = ItemFilter.getFilters(this.getStackInSlot(3));
if (filters.size() > 0)
{
ItemStack outputStack = filters.get(0);
if (outputStack != null)
{
if (this.getIdealRecipe(outputStack) != null)
{
this.setInventorySlotContents(4, outputStack);
didCraft = true;
}
}
}
}
}
if (!didCraft)
{
this.setInventorySlotContents(4, null);
} */
}
/**
* Does this player's inventory contain the required resources to craft this item?
*
* @return Required Items
*/
public ItemStack[] getIdealRecipe(ItemStack outputItem)
{
for (Object object : CraftingManager.getInstance().getRecipeList())
{
if (object instanceof IRecipe)
{
if (((IRecipe) object).getRecipeOutput() != null)
{
if (outputItem.isItemEqual(((IRecipe) object).getRecipeOutput()))
{
if (object instanceof ShapedRecipes)
{
if (this.doesMatch(((ShapedRecipes) object).recipeItems, outputItem)) { return ((ShapedRecipes) object).recipeItems; }
}
else if (object instanceof ShapelessRecipes)
{
if (this.doesMatch(((ShapelessRecipes) object).recipeItems.toArray(), outputItem)) { return (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(); }
}
}
}
}
}
return null;
}
private boolean doesMatch(Object[] recipeItems, ItemStack outputItem)
{
int itemMatch = 0;
for (Object obj : recipeItems)
{
if (obj instanceof ItemStack)
{
ItemStack recipeItem = (ItemStack) obj;
if (recipeItem != null)
{
for (int i = 0; i < this.inventoryPlayer.getSizeInventory(); i++)
{
ItemStack checkStack = this.inventoryPlayer.getStackInSlot(i);
if (checkStack != null)
{
if (recipeItem.isItemEqual(checkStack))
{
// TODO Do NBT CHecking
itemMatch++;
}
}
}
}
}
}
return itemMatch >= recipeItems.length;
}
@Override

View file

@ -28,8 +28,6 @@ public class ItemFilter extends Item
if (filterItems.size() > 0)
{
list.add("Filters:");
for (ItemStack filterItem : filterItems)
{
list.add(filterItem.getDisplayName());
@ -50,7 +48,7 @@ public class ItemFilter extends Item
{
itemStack.setTagCompound(new NBTTagCompound());
}
NBTTagList nbt = new NBTTagList();
for (int i = 0; i < filterStacks.size(); ++i)

View file

@ -0,0 +1,54 @@
package assemblyline.common.machine.filter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class SlotCraftingResult extends Slot
{
private ContainerStamper container;
public SlotCraftingResult(ContainerStamper container, IInventory par1iInventory, int par2, int par3, int par4)
{
super(par1iInventory, par2, par3, par4);
this.container = container;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack par2ItemStack)
{
super.onPickupFromSlot(entityPlayer, par2ItemStack);
if (this.getStack() != null)
{
ItemStack[] requiredItems = this.container.getIdealRecipe(this.getStack()).clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < entityPlayer.inventory.getSizeInventory(); i++)
{
ItemStack checkStack = entityPlayer.inventory.getStackInSlot(i);
if (checkStack != null)
{
if (searchStack.isItemEqual(checkStack))
{
entityPlayer.inventory.decrStackSize(i, 1);
break;
}
}
}
}
}
}
}
}