Jump to content

[1.7.10]Custom Crafting not working


megabitus

Recommended Posts

Hi! I've made a custom crafting for my Machine and when I place the items It doesn't craft, I get no error, can you help me?

This is my ContainerMachine:

 

 

package com.mega.bir.client.interfaces.machine;

import com.mega.bir.block.tileentity.TileEntityInterChest;

import com.mega.bir.block.tileentity.TileEntityMachine;

import com.mega.bir.helping.ItemHelper;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.*;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

/**

* Created by Megabitus on 8/13/2014 and hour 19.

*/

public class ContainerMachine extends Container{

private TileEntityMachine machine;

public InventoryCrafting craftMatrix = new InventoryCrafting(this, TileEntityMachine.INVENTORY_SIZE, 1);

public IInventory craftResult = new InventoryCraftResult();

private World worldObj;

public ContainerMachine(InventoryPlayer invPlayer, TileEntityMachine machine, World world){

this.worldObj = world;

this.machine = machine;

for(int x = 0; x < 9; x++){

addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142));

}

for(int y = 0; y < 3; y++){

for(int x = 0; x < 9; x++){

addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18));

}

}

this.addSlotToContainer(new SlotCrafting(invPlayer.player, this.craftMatrix, this.craftResult, 0, 79, 41));

this.addSlotToContainer(new Slot(craftMatrix, 1, 48, 59));

this.addSlotToContainer(new Slot(craftMatrix, 2, 79, 5));

this.addSlotToContainer(new Slot(craftMatrix, 3, 112, 59));

onCraftMatrixChanged(craftMatrix);

}

@Override

public boolean canInteractWith(EntityPlayer entityplayer){

return machine.isUseableByPlayer(entityplayer);

}

@Override

protected boolean mergeItemStack(ItemStack itemStack, int slotMin, int slotMax, boolean ascending)

{

boolean slotFound = false;

int currentSlotIndex = ascending ? slotMax - 1 : slotMin;

Slot slot;

ItemStack stackInSlot;

if (itemStack.isStackable())

{

while (itemStack.stackSize > 0 && (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin))

{

slot = (Slot) this.inventorySlots.get(currentSlotIndex);

stackInSlot = slot.getStack();

if (slot.isItemValid(itemStack) && ItemHelper.equalsIgnoreStackSize(itemStack, stackInSlot))

{

int combinedStackSize = stackInSlot.stackSize + itemStack.stackSize;

int slotStackSizeLimit = Math.min(stackInSlot.getMaxStackSize(), slot.getSlotStackLimit());

if (combinedStackSize <= slotStackSizeLimit)

{

itemStack.stackSize = 0;

stackInSlot.stackSize = combinedStackSize;

slot.onSlotChanged();

slotFound = true;

}

else if (stackInSlot.stackSize < slotStackSizeLimit)

{

itemStack.stackSize -= slotStackSizeLimit - stackInSlot.stackSize;

stackInSlot.stackSize = slotStackSizeLimit;

slot.onSlotChanged();

slotFound = true;

}

}

currentSlotIndex += ascending ? -1 : 1;

}

}

if (itemStack.stackSize > 0)

{

currentSlotIndex = ascending ? slotMax - 1 : slotMin;

while (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin)

{

slot = (Slot) this.inventorySlots.get(currentSlotIndex);

stackInSlot = slot.getStack();

if (slot.isItemValid(itemStack) && stackInSlot == null)

{

slot.putStack(ItemHelper.cloneItemStack(itemStack, Math.min(itemStack.stackSize, slot.getSlotStackLimit())));

slot.onSlotChanged();

if (slot.getStack() != null)

{

itemStack.stackSize -= slot.getStack().stackSize;

slotFound = true;

}

break;

}

currentSlotIndex += ascending ? -1 : 1;

}

}

return slotFound;

}

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex){

ItemStack itemStack = null;

Slot slot = (Slot) inventorySlots.get(slotIndex);

if (slot != null && slot.getHasStack())

{

ItemStack slotItemStack = slot.getStack();

itemStack = slotItemStack.copy();

if (slotIndex < TileEntityInterChest.INVENTORY_SIZE - 1)

{

if (!this.mergeItemStack(slotItemStack, 1, inventorySlots.size(), true))

{

return null;

}

}

else

{

if (!this.mergeItemStack(slotItemStack, 0, TileEntityInterChest.INVENTORY_SIZE - 1, false))

{

return null;

}

}

if (slotItemStack.stackSize == 0)

{

slot.putStack(null);

}

else

{

slot.onSlotChanged();

}

}

return itemStack;

}

@Override

public void onContainerClosed(EntityPlayer player)

{

super.onContainerClosed(player);

if (!this.worldObj.isRemote)

{

for (int i = 0; i < TileEntityMachine.INVENTORY_SIZE; ++i)

{

ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);

if (itemstack != null)

{

player.dropPlayerItemWithRandomChoice(itemstack, false);

}

}

}

}

@Override

public void onCraftMatrixChanged(IInventory p_75130_1_) {

this.craftResult.setInventorySlotContents(0, MachineCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));

}

}

 

 

This is my GuiMachine:

 

 

package com.mega.bir.client.interfaces.machine;

import com.mega.bir.block.tileentity.TileEntityMachine;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

/**

* Created by Megabitus on 8/13/2014 and hour 19.

*/

@SideOnly(Side.CLIENT)

public class GuiMachine extends GuiContainer{

private static final ResourceLocation texture = new ResourceLocation("bir", "textures/gui/machine.png");

public GuiMachine(InventoryPlayer invPlayer, TileEntityMachine machine, World world){

super(new ContainerMachine(invPlayer, machine, world));

xSize = 176;

ySize = 166;

}

@Override

protected void drawGuiContainerBackgroundLayer(float f, int x, int y){

GL11.glColor4f(1, 1, 1, 1);

Minecraft.getMinecraft().getTextureManager().bindTexture(texture);

drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

}

@Override

protected void drawGuiContainerForegroundLayer(int x, int y) {

fontRendererObj.drawString("Machine", 7, 6, 0x404040);

fontRendererObj.drawString("Inventory", 7, 74, 0x404040);

}

}

 

 

This is my MachineComparator:

 

 

package com.mega.bir.client.interfaces.machine;

import net.minecraft.item.crafting.IRecipe;

import java.util.Comparator;

/**

* Created by Megabitus on 8/20/2014.

*/

public class MachineComparator implements Comparator {

final MachineCraftingManager machineCraftingManager;

public MachineComparator(MachineCraftingManager par1MachineCraftingManager)

{

this.machineCraftingManager = par1MachineCraftingManager;

}

public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe)

{

return par1IRecipe instanceof MachineShapelessRecipes && par2IRecipe instanceof MachineShapedRecipes ? 1 : (par2IRecipe instanceof MachineShapelessRecipes && par1IRecipe instanceof MachineShapedRecipes ? -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);

}

}

 

 

This is my MachineCraftingManager:

 

 

package com.mega.bir.client.interfaces.machine;

import com.mega.bir.helping.LogHelper;

import com.mega.bir.item.ItemsManager;

import net.minecraft.block.Block;

import net.minecraft.init.Items;

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;

import java.util.*;

/**

* Created by Megabitus on 8/20/2014.

*/

public class MachineCraftingManager {

private static final MachineCraftingManager instance = new MachineCraftingManager();

private List recipes = new ArrayList();

public static final MachineCraftingManager getInstance() {

return instance;

}

private MachineCraftingManager() {

/** Recipes!!! */

this.addMachineShapelessRecipe(new ItemStack(Items.ender_pearl, 1), new ItemStack(ItemsManager.eye));

Collections.sort(this.recipes, new MachineComparator(this));

LogHelper.info(this.getRecipeList().size() + " recipes!");

}

public MachineShapedRecipes func_92051_a(ItemStack par1ItemStack, Object ... par2ArrayOfObj)

{

String var3 = "";

int var4 = 0;

int var5 = 0;

int var6 = 0;

if (par2ArrayOfObj[var4] instanceof String[])

{

String[] var7 = (String[])((String[])par2ArrayOfObj[var4++]);

for (int var8 = 0; var8 < var7.length; ++var8)

{

String var9 = var7[var8];

++var6;

var5 = var9.length();

var3 = var3 + var9;

}

}

else

{

while (par2ArrayOfObj[var4] instanceof String)

{

String var11 = (String)par2ArrayOfObj[var4++];

++var6;

var5 = var11.length();

var3 = var3 + var11;

}

}

HashMap var12;

for (var12 = new HashMap(); var4 < par2ArrayOfObj.length; var4 += 2)

{

Character var13 = (Character)par2ArrayOfObj[var4];

ItemStack var14 = null;

if (par2ArrayOfObj[var4 + 1] instanceof Item)

{

var14 = new ItemStack((Item)par2ArrayOfObj[var4 + 1]);

}

else if (par2ArrayOfObj[var4 + 1] instanceof Block)

{

var14 = new ItemStack((Block)par2ArrayOfObj[var4 + 1], 1, -1);

}

else if (par2ArrayOfObj[var4 + 1] instanceof ItemStack)

{

var14 = (ItemStack)par2ArrayOfObj[var4 + 1];

}

var12.put(var13, var14);

}

ItemStack[] var15 = new ItemStack[var5 * var6];

for (int var16 = 0; var16 < var5 * var6; ++var16)

{

char var10 = var3.charAt(var16);

if (var12.containsKey(Character.valueOf(var10)))

{

var15[var16] = ((ItemStack)var12.get(Character.valueOf(var10))).copy();

}

else

{

var15[var16] = null;

}

}

MachineShapedRecipes var17 = new MachineShapedRecipes(var5, var6, var15, par1ItemStack);

this.recipes.add(var17);

return var17;

}

public void addMachineShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)

{

ArrayList var3 = new ArrayList();

Object[] var4 = par2ArrayOfObj;

int var5 = par2ArrayOfObj.length;

for (int var6 = 0; var6 < var5; ++var6)

{

Object var7 = var4[var6];

if (var7 instanceof ItemStack)

{

var3.add(((ItemStack)var7).copy());

}

else if (var7 instanceof Item)

{

var3.add(new ItemStack((Item)var7));

}

else

{

if (!(var7 instanceof Block))

{

throw new RuntimeException("Invalid shapeless recipy!");

}

var3.add(new ItemStack((Block)var7));

}

}

this.recipes.add(new MachineShapelessRecipes(par1ItemStack, var3));

}

public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_) {

int i = 0;

ItemStack itemstack = null;

ItemStack itemstack1 = null;

int j;

for (j = 0; j < p_82787_1_.getSizeInventory(); ++j) {

ItemStack itemstack2 = p_82787_1_.getStackInSlot(j);

if (itemstack2 != null) {

if (i == 0) {

itemstack = itemstack2;

}

if (i == 1) {

itemstack1 = itemstack2;

}

++i;

}

}

if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) {

Item item = itemstack.getItem();

int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay();

int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();

int l = j1 + k + item.getMaxDamage() * 5 / 100;

int i1 = item.getMaxDamage() - l;

if (i1 < 0) {

i1 = 0;

}

return new ItemStack(itemstack.getItem(), 1, i1);

} else {

for (j = 0; j < this.recipes.size(); ++j) {

IRecipe irecipe = (IRecipe) this.recipes.get(j);

if (irecipe.matches(p_82787_1_, p_82787_2_)) {

return irecipe.getCraftingResult(p_82787_1_);

}

}

return null;

}

}

/**

* returns the List<> of all recipes

*/

public List getRecipeList() {

return this.recipes;

}

}

 

 

This is my MachineShapedRecipes:

 

 

package com.mega.bir.client.interfaces.machine;

import com.mega.bir.block.tileentity.TileEntityMachine;

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;

/**

* Created by Nitu on 8/20/2014.

*/

public class MachineShapedRecipes implements IRecipe{

/** How many horizontal slots this recipe is wide. */

public final int recipeWidth;

/** How many vertical slots this recipe uses. */

public final int recipeHeight;

/** Is a array of ItemStack that composes the recipe. */

public final ItemStack[] recipeItems;

/** Is the ItemStack that you get when craft the recipe. */

private ItemStack recipeOutput;

/** Is the itemID of the output item that you get when craft the recipe. */

public final int recipeOutputItemID;

private boolean field_92101_f = false;

public MachineShapedRecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)

{

this.recipeOutputItemID = par4ItemStack.getItemDamage();

this.recipeWidth = par1;

this.recipeHeight = par2;

this.recipeItems = par3ArrayOfItemStack;

this.recipeOutput = par4ItemStack;

}

public ItemStack getRecipeOutput()

{

return this.recipeOutput;

}

/**

* Used to check if a recipe matches current crafting inventory

*/

public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)

{

for (int i = 0; i <= TileEntityMachine.INVENTORY_SIZE - this.recipeWidth; ++i)

{

for (int j = 0; j <= 1 - this.recipeHeight; ++j)

{

if (this.checkMatch(par1InventoryCrafting, i, j, true))

{

return true;

}

if (this.checkMatch(par1InventoryCrafting, i, j, false))

{

return true;

}

}

}

return false;

}

/**

* Checks if the region of a crafting inventory is match for the recipe.

*/

private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)

{

for (int k = 0; k < TileEntityMachine.INVENTORY_SIZE; ++k)

{

for (int l = 0; l < 1; ++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 (itemstack1.getItem() != itemstack.getItem())

{

return false;

}

if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage())

{

return false;

}

}

}

}

return true;

}

/**

* Returns an Item that is the result of this recipe

*/

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;

}

/**

* Returns the size of the recipe area

*/

public int getRecipeSize()

{

return this.recipeWidth * this.recipeHeight;

}

public MachineShapedRecipes func_92100_c()

{

this.field_92101_f = true;

return this;

}

}

 

 

This my MachineShapelessRecipes:

 

 

package com.mega.bir.client.interfaces.machine;

import com.mega.bir.block.tileentity.TileEntityMachine;

import net.minecraft.inventory.InventoryCrafting;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.IRecipe;

import net.minecraft.world.World;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

/**

* Created by Megabitus on 8/20/2014.

*/

public class MachineShapelessRecipes implements IRecipe{

private final ItemStack recipeOutput;

public final List recipeItems;

public MachineShapelessRecipes(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 < TileEntityMachine.INVENTORY_SIZE; ++i)

{

for (int j = 0; j < 1; ++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.getItem() == itemstack1.getItem() && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))

{

flag = true;

arraylist.remove(itemstack1);

break;

}

}

if (!flag)

{

return false;

}

}

}

}

return arraylist.isEmpty();

}

/**

* Returns an Item that is the result of this recipe

*/

public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)

{

return this.recipeOutput.copy();

}

/**

* Returns the size of the recipe area

*/

public int getRecipeSize()

{

return this.recipeItems.size();

}

}

 

 

And here is my Github with the last commit: https://github.com/megabitus98/Blocks-Items-Revolution

Woking at my first mod, Blocks & Items Revolution : https://github.com/megabitus98/Blocks-Items-Revolution

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • My friends and I are modding to survive But recently I want to use cmd to open the server instead of making the single player game public But when I used two methods to start the server, I encountered two problems first A I used forge to install the server files Created using the original server jar The server was installed successfully and the mod was also loaded successfully. But after I replaced the world file with my survival map, I found that the mod items inside disappeared but could be taken from creation again. So I tried to install the server using forge first B I have studied forge for a long time but successfully installed it. But when I put in mods it crashed But mods can be installed on the server   我和我的朋友們正在mod為了生存 但是最近我想用cmd打開伺服器而不是把單人遊戲公開 但是當我使用兩種方法啟動伺服器時,我遇到了兩個問題 首先AI使用forge安裝伺服器檔案使用原始伺服器jar 建立伺服器已成功安裝,mod 也已成功載入。但是當我用我的生存地圖替換世界文件後,我發現裡面的mod物品消失了,但可以再次從創建中取出。所以我嘗試先使用forge安裝伺服器,BI研究了forge很久但成功安裝了它。但是當我安裝 mods 時它崩潰了但是 mods 可以安裝在伺服器上 我和我的朋友正在mod生存 但最近我想使用cmd開啟伺服器而不是單人遊戲公開   但是當我使用了兩種方法開啟伺服器時遇到了兩種問題   第1個A 我使用了forge安裝伺服器文件 在使用原版伺服器jar建立    伺服器安裝成功 mod也順利加載  但是我將我的生存地圖替換世界文件後發現裡面的mod物品消失了但可以再次從創造拿取  所以我嘗試使用forge安裝伺服器   第2個B forge我研究了很久但也成功安裝了 但是當我放入 mods 之後發生了崩潰 但是mods在1A伺服器上是可以安裝的 Ps 我用谷歌翻譯 so    
    • That’s probably not it because as I stated I’ve done it before. I did it like deadass 10 - 20 times when trying to learn to make this mod pack because I kept wanting to reset my profiles and such. So it definitely works, it looks like maybe the creephosting files were the things that couldn’t be reached I tried reading the crash log
    • I don't know if this is the right place or not, but I have put together a custom modpack and I am in need of others to help me. It's a questing modpack with a lore book i'm currently writing out through Patchouli, and i am in need of somebody who will assist me in making the quests for the pack. It's a Zombie apocalypse modpack inspired by Deceasedcraft  with a tinge of magic and RPG mechanics via Mine and slash. Is there anybody willing to assist me as i'm one person building a modpack I could also use help with optimizations since that's not really my strong suite. 
    • File a report to SPYRECOVERY36 @ gmail com he can legitimately assist in proper review and recovery of all your assets that was stolen. Endeavor to submit your request for a refund to his mail . He also spy and hack any device remotely without any trace. Contact via spyrecovery36 @ gm ail com  
    • Hello, is it possible to upgrade from server 1.16.5 forge to 1.20.1 forge without losing a thing? and how do I do it? You need to change "forge-1.16.5-36.2.35.jar, minecraft_server.1.16.5.jar" and other modes.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.