Do I have the rights to help you in this thread since we became a team? lol
Yes, actually anyone who has an answer to any problem on the thread can answer as it helps me and you and everyone faster instead of relying on the OP to post a reply.
You can get the image from my mod, here, or create your own...quite easy just use the original 3x3 as a base as I did...please, if you use my texture, recolor it.....
Searching back just one page would have yielded the answer.....
Yeah, I found that, lol.
New problem, when I try to craft something in my crafting table, it doesn't work. When I craft a vanilla recipe in my crafting table, it works. The crafting table I've made seems to be just using all recipes from the regular crafting table.
It hasnt been released, since I am working with microjunk on another mod! This one is open source though, adds lots of blocks, crafting tables, furnaces, and a lot of stuff. (Coolest things were made by me, hope micro doesnt read this hihi :P) By the way you can find it on GitHub (I am going to release it later): https://github.com/frost-mods/ Ok i am releasing it right now: https://github.com/frost-mods/MechaniCraft I remade almost everything, even if it's still a work in progress mod... i am developing it by myself right now, since micro is already busy with other mods. I love working by myself
Yeah it still doesn't work...
Code is on github, as always
You are going to have to review my code on the main post again as I am not spotting the problem at all. I could get your source and try to work it out in my own eclipse set up, but I just started a new job and dont have the time this week. Honestly you would probably figure it out before I got time to do so... Just go back and double check everything...also are you using 1.6.2 or 1.6.4? I plan to update the tutorial this weekend to 1.6.4 and will hopefully explain things better this time around and may even do a video as well...
Hey,
I am not actually here for your code, I am just here to ask if let's say I've got 7x7, or 5x10 crafting grid (with their own CraftingManager) and when I add recipe that is 3x3 to it - how can I make it be craftable in any position on grid, not just from top left corner?
Anyone have solution to this? Let's say I am using microjunk/vanilli classes (through I am not, but I need a hint on that).
Okay, from my own testing with larger grids...as long as they keep a uniform shape....2x2, 3x3, 5x5 and so on....they should be moveable without any limitations so long as the recipe is correctly done....if say you have a 5x5 table and want a 3x3 recipe to be done anywhere in the grid....
this.addRecipe(new ItemStack(brick, 1), new Object[] {"sss", "sss", "sss", Character.valueOf('S'), Block.stone});
You basically set it up so it reflects a 3x3 recipe and it should work anywhere in the grid so long as it is in a 3x3 pattern...as for the 5x10 grid, it should also work so long as it is in the 5x5 portion of the grid, so top left or bottom right....(I may be wrong on the last part)
I was thinking the same, but it didn't work. Turns out I've made mistake in numbers lol (My crafting uses non-square grid, and I put wrong slot ID in one of the slots... Wrote my problem here just to make sure vanillia comparator works on every grid).
Thanks for quick answer btw.
No problem....It worked for me the way I explained in my 5x5 table so I dont know. I will test it to see if anything changed in that way for 1.6.4 before updating my guides for this...
Does the 5x5 table support regular 3x3 recipes as well as custom 5x5 recipes?or to phrase it differently:
Can I have the vanilla 3x3 recipes in the 5x5 table as well as adding my own 5x5 recipes?
It would be pretty sweet if that is possible.
public class GuiHandlerMergingTable implements IGuiHandler
{
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0:
return id == 0 && world.getBlockId(x, y, z) == MP_Blocks.mergingTable.blockID ? new GuiMergingTable(player.inventory, world, x, y, z) : null;
}
return null;
}
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0:
return id == 0 && world.getBlockId(x, y, z) == MP_Blocks.mergingTable.blockID ? new ContainerMergingTable(player.inventory, world, x, y, z) : null;
}
@SideOnly(Side.CLIENT)
public class GuiMergingTable extends GuiContainer
{
private static final ResourceLocation guiTexture = new ResourceLocation(MP_Info.modid + "textures/gui/mergingTable.png");
public GuiMergingTable(InventoryPlayer playerInventory, World world, int x, int y, int z)
{
super(new ContainerMergingTable(playerInventory, world, x, y, z));
}
public class SlotMergingTable extends Slot
{
private final IInventory craftMatrix;
private EntityPlayer player;
private int amountCrafted;
public SlotMergingTable(EntityPlayer funcPlayer, IInventory funcCraftMatrix, IInventory inventory, int par4, int par5, int par6)
{
super(inventory, par4, par5, par6);
player = funcPlayer;
craftMatrix = funcCraftMatrix;
}
public boolean isItemValid(ItemStack itemstack)
{
return false;
}
public class CraftingManagerMergingTable
{
private static final CraftingManagerMergingTable instance = new CraftingManagerMergingTable();
private List recipes = new ArrayList();
public static final CraftingManagerMergingTable getInstance()
{
return instance;
}
private CraftingManagerMergingTable()
{
recipes = new ArrayList();
//recipes here
Collections.sort(this.recipes, new RecipeSorterMergingTable(this));
}
public MergingShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (par2ArrayOfObj[i] instanceof String[])
{
String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 4)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if (par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if (par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
public class ContainerMergingTable extends Container
{
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 4, 4);
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;
private int posX;
private int posY;
private int posZ;
public ContainerMergingTable(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
this.worldObj = par2World;
this.posX = par3;
this.posY = par4;
this.posZ = par5;
this.addSlotToContainer(new SlotCrafting(par1InventoryPlayer.player, this.craftMatrix, this.craftResult, 0, 124, 35));
int l;
int i1;
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 3; ++i1)
{
this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
}
}
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
}
}
for (l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, l, 8 + l * 18, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
public void onCraftMatrixChanged(IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
super.onContainerClosed(par1EntityPlayer);
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 16; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
par1EntityPlayer.dropPlayerItem(itemstack);
}
}
}
}
public class MergingShapedRecipes implements IRecipe
{
public final int recipeWidth;
public final int recipeHeight;
public final ItemStack[] recipeItems;
private ItemStack recipeOutput;
public final int recipeOutputItemID;
private boolean field_92101_f = false;
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 4 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 4 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 4; ++k)
{
for (int l = 0; l < 4; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
Yes, actually anyone who has an answer to any problem on the thread can answer as it helps me and you and everyone faster instead of relying on the OP to post a reply.
Find out how I generate....coolAlias...world structure generation and rotation tool...
I downloaded your source code, but I can't test it without the texture.
Find out how I generate....coolAlias...world structure generation and rotation tool...
When I attempt to open the gui, the gui blinks open and then immediately closes.
Any suggestions?
Will post .java files when requested.
Searching back just one page would have yielded the answer.....
Find out how I generate....coolAlias...world structure generation and rotation tool...
Yeah, I found that, lol.
New problem, when I try to craft something in my crafting table, it doesn't work. When I craft a vanilla recipe in my crafting table, it works. The crafting table I've made seems to be just using all recipes from the regular crafting table.
Help!
CraftingManager becomes [block]CraftingManager (in my case, DecoCraftingManager)
Oh reallly.....
I will be looking tonight to see if I can find the issue...
Find out how I generate....coolAlias...world structure generation and rotation tool...
You are going to have to review my code on the main post again as I am not spotting the problem at all. I could get your source and try to work it out in my own eclipse set up, but I just started a new job and dont have the time this week. Honestly you would probably figure it out before I got time to do so... Just go back and double check everything...also are you using 1.6.2 or 1.6.4? I plan to update the tutorial this weekend to 1.6.4 and will hopefully explain things better this time around and may even do a video as well...
Okay, from my own testing with larger grids...as long as they keep a uniform shape....2x2, 3x3, 5x5 and so on....they should be moveable without any limitations so long as the recipe is correctly done....if say you have a 5x5 table and want a 3x3 recipe to be done anywhere in the grid....
You basically set it up so it reflects a 3x3 recipe and it should work anywhere in the grid so long as it is in a 3x3 pattern...as for the 5x10 grid, it should also work so long as it is in the 5x5 portion of the grid, so top left or bottom right....(I may be wrong on the last part)
Find out how I generate....coolAlias...world structure generation and rotation tool...
No problem....It worked for me the way I explained in my 5x5 table so I dont know. I will test it to see if anything changed in that way for 1.6.4 before updating my guides for this...
Find out how I generate....coolAlias...world structure generation and rotation tool...
I know...was just giving you a hard time...
Find out how I generate....coolAlias...world structure generation and rotation tool...
Find out how I generate....coolAlias...world structure generation and rotation tool...
the above needs to look like this
Find out how I generate....coolAlias...world structure generation and rotation tool...
Heads up: The func_110434_K() and func_110577_a have been changed to getTextureManager() and bindTexture() in 1.6.4.
Can I have the vanilla 3x3 recipes in the 5x5 table as well as adding my own 5x5 recipes?
It would be pretty sweet if that is possible.
Saying that the method is undefined.
package CsFreakable.MiningPlus.handler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import CsFreakable.MiningPlus.block.container.ContainerMergingTable;
import CsFreakable.MiningPlus.block.gui.GuiMergingTable;
import CsFreakable.MiningPlus.core.MP_Blocks;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandlerMergingTable implements IGuiHandler
{
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0:
return id == 0 && world.getBlockId(x, y, z) == MP_Blocks.mergingTable.blockID ? new GuiMergingTable(player.inventory, world, x, y, z) : null;
}
return null;
}
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0:
return id == 0 && world.getBlockId(x, y, z) == MP_Blocks.mergingTable.blockID ? new ContainerMergingTable(player.inventory, world, x, y, z) : null;
}
return null;
}
}
package CsFreakable.MiningPlus.block.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import CsFreakable.MiningPlus.block.container.ContainerMergingTable;
import CsFreakable.MiningPlus.core.MP_Info;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiMergingTable extends GuiContainer
{
private static final ResourceLocation guiTexture = new ResourceLocation(MP_Info.modid + "textures/gui/mergingTable.png");
public GuiMergingTable(InventoryPlayer playerInventory, World world, int x, int y, int z)
{
super(new ContainerMergingTable(playerInventory, world, x, y, z));
}
protected void drawGuiContainerForegrounLayer(int par1, int par2)
{
this.fontRenderer.drawString(I18n.getString("container.crafting"), 28, 6, 4210752);
this.fontRenderer.drawString(I18n.getString("container.inventory"), 8, this.ySize - 96 + 2, 421072);
}
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(guiTexture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
}
package CsFreakable.MiningPlus.block.gui.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import cpw.mods.fml.common.registry.GameRegistry;
public class SlotMergingTable extends Slot
{
private final IInventory craftMatrix;
private EntityPlayer player;
private int amountCrafted;
public SlotMergingTable(EntityPlayer funcPlayer, IInventory funcCraftMatrix, IInventory inventory, int par4, int par5, int par6)
{
super(inventory, par4, par5, par6);
player = funcPlayer;
craftMatrix = funcCraftMatrix;
}
public boolean isItemValid(ItemStack itemstack)
{
return false;
}
public ItemStack dectStackSize(int par1)
{
if(getHasStack())
{
amountCrafted += Math.min(par1, getStack().stackSize);
}
return super.decrStackSize(par1);
}
protected void onCrafting(ItemStack itemstack, int par1)
{
amountCrafted += par1;
}
public void onPickupFromSlot(EntityPlayer funcPlayer, ItemStack itemstack)
{
GameRegistry.onItemCrafted(funcPlayer, itemstack, craftMatrix);
for(int i = 0; i < craftMatrix.getSizeInventory(); ++i)
{
ItemStack fieldItemstack = craftMatrix.getStackInSlot(i);
if(fieldItemstack != null)
{
craftMatrix.decrStackSize(i, 1);
if(fieldItemstack.getItem().hasContainerItem())
{
ItemStack fieldItemstack2 = fieldItemstack.getItem().getContainerItemStack(fieldItemstack);
if(fieldItemstack2.isItemStackDamageable() && fieldItemstack2.getItemDamage() > fieldItemstack2.getMaxDamage())
{
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, fieldItemstack2));
fieldItemstack2 = null;
}
if(fieldItemstack2 != null && (!fieldItemstack.getItem().doesContainerItemLeaveCraftingGrid(fieldItemstack) || !player.inventory.addItemStackToInventory(fieldItemstack2)))
{
if(craftMatrix.getStackInSlot(i) == null)
{
craftMatrix.setInventorySlotContents(i, fieldItemstack2);
}
else
{
player.dropPlayerItem(fieldItemstack2);
}
}
}
}
}
}
}
package CsFreakable.MiningPlus.crafting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class CraftingManagerMergingTable
{
private static final CraftingManagerMergingTable instance = new CraftingManagerMergingTable();
private List recipes = new ArrayList();
public static final CraftingManagerMergingTable getInstance()
{
return instance;
}
private CraftingManagerMergingTable()
{
recipes = new ArrayList();
//recipes here
Collections.sort(this.recipes, new RecipeSorterMergingTable(this));
}
public MergingShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (par2ArrayOfObj[i] instanceof String[])
{
String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 4)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if (par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if (par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
}
hashmap.put(character, itemstack1);
}
ItemStack[] aitemstack = new ItemStack[j * k];
for (int i1 = 0; i1 < j * k; ++i1)
{
char c0 = s.charAt(i1);
if (hashmap.containsKey(Character.valueOf(c0)))
{
aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();
}
else
{
aitemstack[i1] = null;
}
}
MergingShapedRecipes shapedrecipes = new MergingShapedRecipes(j, k, aitemstack, par1ItemStack);
this.recipes.add(shapedrecipes);
return shapedrecipes;
}
public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
ArrayList arraylist = new ArrayList();
Object[] aobject = par2ArrayOfObj;
int i = par2ArrayOfObj.length;
for (int j = 0; j < i; ++j)
{
Object object1 = aobject[j];
if (object1 instanceof ItemStack)
{
arraylist.add(((ItemStack)object1).copy());
}
else if (object1 instanceof Item)
{
arraylist.add(new ItemStack((Item)object1));
}
else
{
if (!(object1 instanceof Block))
{
throw new RuntimeException("Invalid shapeless recipe!");
}
arraylist.add(new ItemStack((Block)object1));
}
}
this.recipes.add(new MergingShapelessRecipes(par1ItemStack, arraylist));
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
for (j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
{
ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(j);
if (itemstack2 != null)
{
if (i == 0)
{
itemstack = itemstack2;
}
if (i == 1)
{
itemstack1 = itemstack2;
}
++i;
}
}
if (i == 4 && itemstack.itemID == itemstack1.itemID && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && Item.itemsList[itemstack.itemID].isRepairable())
{
Item item = Item.itemsList[itemstack.itemID];
int k = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
int l = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
int i1 = k + l + item.getMaxDamage() * 5 / 100;
int j1 = item.getMaxDamage() - i1;
if (j1 < 0)
{
j1 = 0;
}
return new ItemStack(itemstack.itemID, 1, j1);
}
else
{
for (j = 0; j < this.recipes.size(); ++j)
{
IRecipe irecipe = (IRecipe)this.recipes.get(j);
if (irecipe.matches(par1InventoryCrafting, par2World))
{
return irecipe.getCraftingResult(par1InventoryCrafting);
}
}
return null;
}
}
public List getRecipeList()
{
return this.recipes;
}
}
package CsFreakable.MiningPlus.crafting;
import java.util.Comparator;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
public class RecipeSorterMergingTable implements Comparator
{
final CraftingManagerMergingTable craftingManager;
public RecipeSorterMergingTable(CraftingManagerMergingTable funcCraftingManager)
{
craftingManager = funcCraftingManager;
}
public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe)
{
return par1IRecipe instanceof MergingShapelessRecipes && par2IRecipe instanceof MergingShapedRecipes ? 1 : (par2IRecipe instanceof MergingShapelessRecipes && par1IRecipe instanceof MergingShapedRecipes ? -1 : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize() ? -1 : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0)));
}
public int compare(Object par1Obj, Object par2Obj)
{
return this.compareRecipes((IRecipe)par1Obj, (IRecipe)par2Obj);
}
}
package CsFreakable.MiningPlus.block.container;
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.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
import CsFreakable.MiningPlus.core.MP_Blocks;
public class ContainerMergingTable extends Container
{
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 4, 4);
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;
private int posX;
private int posY;
private int posZ;
public ContainerMergingTable(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
this.worldObj = par2World;
this.posX = par3;
this.posY = par4;
this.posZ = par5;
this.addSlotToContainer(new SlotCrafting(par1InventoryPlayer.player, this.craftMatrix, this.craftResult, 0, 124, 35));
int l;
int i1;
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 3; ++i1)
{
this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
}
}
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
}
}
for (l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, l, 8 + l * 18, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
public void onCraftMatrixChanged(IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
super.onContainerClosed(par1EntityPlayer);
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 16; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
par1EntityPlayer.dropPlayerItem(itemstack);
}
}
}
}
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != MP_Blocks.mergingTable.blockID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
}
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par2 == 0)
{
if (!this.mergeItemStack(itemstack1, 10, 46, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (par2 >= 10 && par2 < 37)
{
if (!this.mergeItemStack(itemstack1, 37, 46, false))
{
return null;
}
}
else if (par2 >= 37 && par2 < 46)
{
if (!this.mergeItemStack(itemstack1, 10, 37, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
}
return itemstack;
}
public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot)
{
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
}
}
package CsFreakable.MiningPlus.crafting;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class MergingShapedRecipes implements IRecipe
{
public final int recipeWidth;
public final int recipeHeight;
public final ItemStack[] recipeItems;
private ItemStack recipeOutput;
public final int recipeOutputItemID;
private boolean field_92101_f = false;
public MergingShapedRecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
{
this.recipeOutputItemID = par4ItemStack.itemID;
this.recipeWidth = par1;
this.recipeHeight = par2;
this.recipeItems = par3ArrayOfItemStack;
this.recipeOutput = par4ItemStack;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 4 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 4 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 4; ++k)
{
for (int l = 0; l < 4; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight)
{
if (par4)
{
itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth];
}
else
{
itemstack = this.recipeItems[i1 + j1 * this.recipeWidth];
}
}
ItemStack itemstack1 = par1InventoryCrafting.getStackInRowAndColumn(k, l);
if (itemstack1 != null || itemstack != null)
{
if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null)
{
return false;
}
if (itemstack.itemID != itemstack1.itemID)
{
return false;
}
if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage())
{
return false;
}
}
}
}
return true;
}
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
if (itemstack1 != null && itemstack1.hasTagCompound())
{
itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy());
}
}
}
return itemstack;
}
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
public MergingShapedRecipes func_92100_c()
{
this.field_92101_f = true;
return this;
}
}
package CsFreakable.MiningPlus.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class MergingShapelessRecipes implements IRecipe
{
private final ItemStack recipeOutput;
public final List recipeItems;
public MergingShapelessRecipes(ItemStack par1ItemStack, List par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
ArrayList arraylist = new ArrayList(this.recipeItems);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i);
if (itemstack != null)
{
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext())
{
ItemStack itemstack1 = (ItemStack)iterator.next();
if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))
{
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag)
{
return false;
}
}
}
}
return arraylist.isEmpty();
}
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
public int getRecipeSize()
{
return this.recipeItems.size();
}
}