More work on imprinter

This commit is contained in:
Henry Mao 2013-02-02 16:57:49 +08:00
parent f9eb91bbbe
commit f544a3d99b
4 changed files with 105 additions and 76 deletions

View file

@ -150,8 +150,8 @@ public class AssemblyLine
// Imprint // Imprint
GameRegistry.addRecipe(new ShapedOreRecipe(itemImprint, new Object[] { "R", "P", "I", 'P', Item.paper, 'R', Item.redstone, 'I', new ItemStack(Item.dyePowder, 1, 0) })); GameRegistry.addRecipe(new ShapedOreRecipe(itemImprint, new Object[] { "R", "P", "I", 'P', Item.paper, 'R', Item.redstone, 'I', new ItemStack(Item.dyePowder, 1, 0) }));
// Imprinter // Imprinter (VANILLA COMPATIBLE)
GameRegistry.addRecipe(new ShapedOreRecipe(blockImprinter, new Object[] { "SIS", "SPS", "WCW", 'S', "ingotSteel", 'C', Block.chest, 'W', Block.workbench, 'P', Block.pistonStickyBase, 'I', new ItemStack(Item.dyePowder, 1, 0) })); GameRegistry.addRecipe(new ShapedOreRecipe(blockImprinter, new Object[] { "SIS", "SPS", "WCW", 'S', "ingotIron", 'C', Block.chest, 'W', Block.workbench, 'P', Block.pistonStickyBase, 'I', new ItemStack(Item.dyePowder, 1, 0) }));
// Detector // Detector
GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, new Object[] { "SES", "SCS", "SPS", 'S', "ingotSteel", 'C', "basicCircuit", 'E', Item.eyeOfEnder })); GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, new Object[] { "SES", "SCS", "SPS", 'S', "ingotSteel", 'C', "basicCircuit", 'E', Item.eyeOfEnder }));
@ -163,7 +163,7 @@ public class AssemblyLine
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 10), new Object[] { "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" })); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 10), new Object[] { "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" }));
// Rejector // Rejector
GameRegistry.addRecipe(new ShapedOreRecipe(blockRejector, new Object[] { "WPW", "@R@", '@', "plateSteel", 'R', Item.redstone, 'P', Block.pistonBase, 'C', "basicCircuit", 'W', "copperWire" })); GameRegistry.addRecipe(new ShapedOreRecipe(blockRejector, new Object[] { "WPW", "@R@", '@', "ingotSteel", 'R', Item.redstone, 'P', Block.pistonBase, 'C', "basicCircuit", 'W', "copperWire" }));
// Manipulator // Manipulator
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockManipulator, 2), new Object[] { Block.dispenser, "basicCircuit" })); GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockManipulator, 2), new Object[] { Block.dispenser, "basicCircuit" }));

View file

@ -16,6 +16,7 @@ public class ContainerImprinter extends Container implements ISlotWatcher
public ContainerImprinter(InventoryPlayer inventoryPlayer, TileEntityImprinter tileEntity) public ContainerImprinter(InventoryPlayer inventoryPlayer, TileEntityImprinter tileEntity)
{ {
this.tileEntity = tileEntity; this.tileEntity = tileEntity;
this.tileEntity.container = this;
this.inventoryPlayer = inventoryPlayer; this.inventoryPlayer = inventoryPlayer;
/** /**

View file

@ -24,49 +24,22 @@ public class SlotCraftingResult extends Slot
@Override @Override
public boolean canTakeStack(EntityPlayer player) public boolean canTakeStack(EntityPlayer player)
{ {
return this.getStack() == null ? false : this.container.tileEntity.getIdealRecipe(this.getStack()) != null; return true;
// this.getStack() == null ? false : this.container.tileEntity.getIdealRecipe(this.getStack()) != null;
} }
@Override @Override
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack par2ItemStack) public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
{ {
super.onPickupFromSlot(entityPlayer, par2ItemStack); super.onPickupFromSlot(entityPlayer, itemStack);
if (this.getStack() != null) this.container.tileEntity.onPickUpFromResult(entityPlayer, itemStack);
{
ItemStack[] requiredItems = this.container.tileEntity.getIdealRecipe(this.getStack()).getValue().clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.container.tileEntity.getSizeInventory(); i++)
{
ItemStack checkStack = this.container.tileEntity.getStackInSlot(i);
if (checkStack != null)
{
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0))
{
this.container.tileEntity.decrStackSize(i, 1);
break;
}
}
}
}
}
}
} }
/* /*
* private boolean playerHasRequiredIngredients(EntityPlayer player, ItemStack desiredItem) { if * private boolean playerHasRequiredIngredients(EntityPlayer player, ItemStack desiredItem) { if (this.getStack() != null) { ItemStack[] idealRecipe = this.container.tileEntity.getIdealRecipe(this.getStack()).getValue(); if (idealRecipe != null) { ItemStack[] requiredItems = idealRecipe.clone(); int foundItems = 0;
* (this.getStack() != null) { ItemStack[] idealRecipe =
* this.container.tileEntity.getIdealRecipe(this.getStack()).getValue(); if (idealRecipe !=
* null) { ItemStack[] requiredItems = idealRecipe.clone(); int foundItems = 0;
* *
* if (requiredItems != null) { for (ItemStack searchStack : requiredItems) { for (int i = 0; i * if (requiredItems != null) { for (ItemStack searchStack : requiredItems) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack checkStack = player.inventory.getStackInSlot(i);
* < player.inventory.getSizeInventory(); i++) { ItemStack checkStack =
* player.inventory.getStackInSlot(i);
* *
* if (checkStack != null) { if (searchStack.isItemEqual(checkStack)) { foundItems++; } } } } } * if (checkStack != null) { if (searchStack.isItemEqual(checkStack)) { foundItems++; } } } } }
* *

View file

@ -6,6 +6,7 @@ import java.util.List;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
@ -43,6 +44,8 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
*/ */
public ItemStack[] containingItems = new ItemStack[18]; public ItemStack[] containingItems = new ItemStack[18];
public ContainerImprinter container;
@Override @Override
public boolean canUpdate() public boolean canUpdate()
{ {
@ -150,7 +153,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
@Override @Override
public ItemStack getStackInSlotOnClosing(int slot) public ItemStack getStackInSlotOnClosing(int slot)
{ {
if (this.getStackInSlot(slot) != null && slot != 2) if (this.getStackInSlot(slot) != null)
{ {
ItemStack var2 = this.getStackInSlot(slot); ItemStack var2 = this.getStackInSlot(slot);
this.setInventorySlotContents(slot, null); this.setInventorySlotContents(slot, null);
@ -201,18 +204,18 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
*/ */
boolean didStamp = false; boolean didStamp = false;
if (this.getStackInSlot(0) != null && this.getStackInSlot(1) != null) if (this.imprinterMatrix[0] != null && this.imprinterMatrix[1] != null)
{ {
if (this.getStackInSlot(0).getItem() instanceof ItemImprinter) if (this.imprinterMatrix[0].getItem() instanceof ItemImprinter)
{ {
ItemStack outputStack = this.getStackInSlot(0).copy(); ItemStack outputStack = this.imprinterMatrix[0].copy();
outputStack.stackSize = 1; outputStack.stackSize = 1;
ArrayList<ItemStack> filters = ItemImprinter.getFilters(outputStack); ArrayList<ItemStack> filters = ItemImprinter.getFilters(outputStack);
boolean filteringItemExists = false; boolean filteringItemExists = false;
for (ItemStack filteredStack : filters) for (ItemStack filteredStack : filters)
{ {
if (filteredStack.isItemEqual(this.getStackInSlot(1))) if (filteredStack.isItemEqual(this.imprinterMatrix[1]))
{ {
filters.remove(filteredStack); filters.remove(filteredStack);
filteringItemExists = true; filteringItemExists = true;
@ -222,43 +225,100 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
if (!filteringItemExists) if (!filteringItemExists)
{ {
filters.add(this.getStackInSlot(1)); filters.add(this.imprinterMatrix[1]);
} }
ItemImprinter.setFilters(outputStack, filters); ItemImprinter.setFilters(outputStack, filters);
this.setInventorySlotContents(2, outputStack); this.imprinterMatrix[2] = outputStack;
didStamp = true; didStamp = true;
} }
} }
if (!didStamp) if (!didStamp)
{ {
this.setInventorySlotContents(2, null); this.imprinterMatrix[2] = null;
}
// CRAFTING /**
boolean didCraft = false; * Try to craft from crafting grid. If not possible, then craft from imprint.
*/
boolean didCraft = false;
if (this.getStackInSlot(3) != null) /**
{ * Simulate an Inventory Crafting Instance
if (this.getStackInSlot(3).getItem() instanceof ItemImprinter) */
if (this.container != null)
{ {
ArrayList<ItemStack> filters = ItemImprinter.getFilters(this.getStackInSlot(3)); InventoryCrafting inventoryCrafting = new InventoryCrafting(this.container, 3, 3);
for (ItemStack outputStack : filters) for (int i = 0; i < this.craftingMatrix.length; i++)
{ {
if (outputStack != null) inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix[i]);
}
ItemStack matrixOutput = CraftingManager.getInstance().findMatchingRecipe(inventoryCrafting, this.worldObj);
if (matrixOutput != null)
{
this.imprinterMatrix[2] = matrixOutput;
didCraft = true;
}
}
if (this.imprinterMatrix[0] != null && !didCraft)
{
if (this.imprinterMatrix[0].getItem() instanceof ItemImprinter)
{
ArrayList<ItemStack> filters = ItemImprinter.getFilters(this.imprinterMatrix[0]);
for (ItemStack outputStack : filters)
{ {
Pair<ItemStack, ItemStack[]> idealRecipe = this.getIdealRecipe(outputStack); if (outputStack != null)
if (idealRecipe != null)
{ {
ItemStack recipeOutput = idealRecipe.getKey(); Pair<ItemStack, ItemStack[]> idealRecipe = this.getIdealRecipe(outputStack);
if (recipeOutput != null & recipeOutput.stackSize > 0) if (idealRecipe != null)
{ {
this.setInventorySlotContents(4, recipeOutput); ItemStack recipeOutput = idealRecipe.getKey();
didCraft = true;
if (recipeOutput != null & recipeOutput.stackSize > 0)
{
this.imprinterMatrix[2] = null;
didCraft = true;
break;
}
}
}
}
}
}
if (!didCraft)
{
this.imprinterMatrix[2] = null;
}
}
}
public void onPickUpFromResult(EntityPlayer entityPlayer, ItemStack itemStack)
{
if (itemStack != null)
{
ItemStack[] requiredItems = this.getIdealRecipe(itemStack).getValue().clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null)
{
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0))
{
this.decrStackSize(i, 1);
break; break;
} }
} }
@ -266,11 +326,6 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
} }
} }
} }
if (!didCraft)
{
this.setInventorySlotContents(4, null);
}
} }
/** /**
@ -334,10 +389,10 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
/** /**
* Simulate an imprinter. * Simulate an imprinter.
*/ */
TileEntityImprinter test = new TileEntityImprinter(); TileEntityImprinter dummyImprinter = new TileEntityImprinter();
NBTTagCompound cloneData = new NBTTagCompound(); NBTTagCompound cloneData = new NBTTagCompound();
this.writeToNBT(cloneData); this.writeToNBT(cloneData);
test.readFromNBT(cloneData); dummyImprinter.readFromNBT(cloneData);
/** /**
* The actual amount of resource required. Each ItemStack will only have stacksize of 1. * The actual amount of resource required. Each ItemStack will only have stacksize of 1.
@ -354,16 +409,16 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
if (recipeItem != null) if (recipeItem != null)
{ {
for (int i = imprinterMatrix.length; i < test.getSizeInventory(); i++) for (int i = this.containingItems.length; i < this.containingItems.length; i++)
{ {
ItemStack checkStack = test.getStackInSlot(i); ItemStack checkStack = this.containingItems[i];
if (checkStack != null) if (checkStack != null)
{ {
if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0)) if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0))
{ {
// TODO Do NBT Checking // TODO Do NBT Checking
test.decrStackSize(i, 1); dummyImprinter.decrStackSize(i, 1);
itemMatch++; itemMatch++;
break; break;
} }
@ -386,16 +441,16 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
if (recipeItem != null) if (recipeItem != null)
{ {
for (int i = imprinterMatrix.length; i < test.getSizeInventory(); i++) for (int i = this.containingItems.length; i < this.containingItems.length; i++)
{ {
ItemStack checkStack = test.getStackInSlot(i); ItemStack checkStack = this.containingItems[i];
if (checkStack != null) if (checkStack != null)
{ {
if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0)) if (recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.getItemDamage() < 0))
{ {
// TODO Do NBT CHecking // TODO Do NBT CHecking
test.decrStackSize(i, 1); dummyImprinter.decrStackSize(i, 1);
itemMatch++; itemMatch++;
break optionsLoop; break optionsLoop;
} }
@ -510,7 +565,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
{ {
if (searchStack.isItemEqual(checkStack)) if (searchStack.isItemEqual(checkStack))
{ {
this.decrStackSize(i, 1); this.decrStackSize(i + INVENTORY_START, 1);
break; break;
} }
} }
@ -553,7 +608,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
{ {
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0)) if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0))
{ {
this.decrStackSize(i, 1); this.decrStackSize(i + INVENTORY_START, 1);
break; break;
} }
} }