Posted August 27, 20187 yr Hi modders, I want to put a particular custom workbench in my mod, a workbench with "holes" in the GUI. GUI: Spoiler Now, in the container I successfully added the slots in the right way, but when I try to interact with it the ShapedRecipe give me problems. The InventoryCrafting is a 5x5, so I created a custom class to set the SizeInventory to 17 (instead of 25). Custom InventoryCraft: Spoiler package com.WLLC.mysticWeapons.crafting.crystalInfuser; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; public class WLLC_myWE_CrystalInfuserInventoryCrafting extends InventoryCrafting { public WLLC_myWE_CrystalInfuserInventoryCrafting(Container p_i1807_1_) { super(p_i1807_1_, 5, 5); } @Override public int getSizeInventory() { return 17; } @Override public String getInventoryName() { return "container.crystalInfuser"; } @Override public boolean hasCustomInventoryName() { return true; } @Override public ItemStack getStackInRowAndColumn(int row, int column) { if (row == 0 || row == 4) { return vanillaGetStackInRowAndColumnOperation(row, column); } else if (row == 1 || row == 3){ if (column == 0 || column == 4) { return vanillaGetStackInRowAndColumnOperation(row, column); } else { return null; } } else if (row == 2) { if (column != 1 && column != 3) { return vanillaGetStackInRowAndColumnOperation(row, column); } else { return null; } } else { return null; } } public ItemStack vanillaGetStackInRowAndColumnOperation(int row, int column) { return super.getStackInSlot(row + column * 5); } } The problem is in the checkMatch() method of the ShapedRecipe class, where the class do some strange operation (lines form 98 to 106). This kind of satanic farmulas work fine if I have a 25 elements array, but I have a 17 one and I don't know how to arrange them to correctly scan the array from 0 to 16. Custom ShapedRecipe: Spoiler package com.WLLC.mysticWeapons.crafting.crystalInfuser; 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 WLLC_myWE_CrystalInfuserShapedRecipes implements IRecipe { public final int recipeWidth; public final int recipeHeight; public final ItemStack[] recipeItems; private ItemStack recipeOutput; private boolean field_92101_f; private static final String __OBFID = "CL_00000093"; public WLLC_myWE_CrystalInfuserShapedRecipes(int p_i1917_1_, int p_i1917_2_, ItemStack[] ingredients, ItemStack result) { this.recipeWidth = p_i1917_1_; this.recipeHeight = p_i1917_2_; this.recipeItems = ingredients; this.recipeOutput = result; } public ItemStack getRecipeOutput() { return this.recipeOutput; } public boolean customMatches(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting, World world) { for (int row = 0; row <= 5 - this.recipeWidth; ++row) { for (int column = 0; column <= 5 - this.recipeHeight; ++column) { if (row == 0 || row == 4) { return vanillaMatchesProcess(invCrafting, world, row, column); } else if (row == 1 || row == 3){ if (column == 0 || column == 4) { return vanillaMatchesProcess(invCrafting, world, row, column); } } else if (row == 2) { if (column != 1 && column != 3) { return vanillaMatchesProcess(invCrafting, world, row, column); } } } } return false; } public boolean vanillaMatchesProcess(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting, World world, int row, int column) { if (this.checkMatch(invCrafting, row, column, true)) { return true; } if (this.checkMatch(invCrafting, row, column, false)) { return true; } return false; } private boolean checkMatch(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting, int row0, int column0, boolean p_77573_4_) { for (int row = 0; row < 5; ++row) { for (int column = 0; column < 5; ++column) { int row1 = row - row0; int column1 = column - column0; ItemStack itemstack = null; if (row1 >= 0 && column1 >= 0 && row1 < this.recipeWidth && column1 < this.recipeHeight) { if (p_77573_4_) { itemstack = this.recipeItems[this.recipeWidth - row1 - 1 + column1 * this.recipeWidth]; } else { itemstack = this.recipeItems[row1 + column1 * this.recipeWidth]; } } ItemStack itemstack1 = invCrafting.getStackInRowAndColumn(row, column); if (itemstack1 != null || itemstack != null) { if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) { return false; } if (itemstack.getItem() != itemstack1.getItem()) { return false; } if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage()) { return false; } } } } return true; } public ItemStack customGetCraftingResult(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting) { ItemStack itemstack = this.getRecipeOutput().copy(); if (this.field_92101_f) { for (int i = 0; i < invCrafting.getSizeInventory(); ++i) { ItemStack itemstack1 = invCrafting.getStackInSlot(i); if (itemstack1 != null && itemstack1.hasTagCompound()) { itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy()); } } } return itemstack; } public int getRecipeSize() { return this.recipeWidth * this.recipeHeight; } public WLLC_myWE_CrystalInfuserShapedRecipes func_92100_c() { this.field_92101_f = true; return this; } @Override public boolean matches(InventoryCrafting invCrafting, World world) { return this.customMatches((WLLC_myWE_CrystalInfuserInventoryCrafting) invCrafting, world); } @Override public ItemStack getCraftingResult(InventoryCrafting invCrafting) { return this.customGetCraftingResult((WLLC_myWE_CrystalInfuserInventoryCrafting) invCrafting); } } How can I resolve this? Or I'm doing this terribly wrong? Thanks in advice
August 27, 20187 yr 3 hours ago, IlTosaerba said: Hi modders, I want to put a particular custom workbench in my mod, a workbench with "holes" in the GUI. GUI: Hide contents Now, in the container I successfully added the slots in the right way, but when I try to interact with it the ShapedRecipe give me problems. The InventoryCrafting is a 5x5, so I created a custom class to set the SizeInventory to 17 (instead of 25). Custom InventoryCraft: Hide contents package com.WLLC.mysticWeapons.crafting.crystalInfuser; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; public class WLLC_myWE_CrystalInfuserInventoryCrafting extends InventoryCrafting { public WLLC_myWE_CrystalInfuserInventoryCrafting(Container p_i1807_1_) { super(p_i1807_1_, 5, 5); } @Override public int getSizeInventory() { return 17; } @Override public String getInventoryName() { return "container.crystalInfuser"; } @Override public boolean hasCustomInventoryName() { return true; } @Override public ItemStack getStackInRowAndColumn(int row, int column) { if (row == 0 || row == 4) { return vanillaGetStackInRowAndColumnOperation(row, column); } else if (row == 1 || row == 3){ if (column == 0 || column == 4) { return vanillaGetStackInRowAndColumnOperation(row, column); } else { return null; } } else if (row == 2) { if (column != 1 && column != 3) { return vanillaGetStackInRowAndColumnOperation(row, column); } else { return null; } } else { return null; } } public ItemStack vanillaGetStackInRowAndColumnOperation(int row, int column) { return super.getStackInSlot(row + column * 5); } } The problem is in the checkMatch() method of the ShapedRecipe class, where the class do some strange operation (lines form 98 to 106). This kind of satanic farmulas work fine if I have a 25 elements array, but I have a 17 one and I don't know how to arrange them to correctly scan the array from 0 to 16. Custom ShapedRecipe: Reveal hidden contents package com.WLLC.mysticWeapons.crafting.crystalInfuser; 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 WLLC_myWE_CrystalInfuserShapedRecipes implements IRecipe { public final int recipeWidth; public final int recipeHeight; public final ItemStack[] recipeItems; private ItemStack recipeOutput; private boolean field_92101_f; private static final String __OBFID = "CL_00000093"; public WLLC_myWE_CrystalInfuserShapedRecipes(int p_i1917_1_, int p_i1917_2_, ItemStack[] ingredients, ItemStack result) { this.recipeWidth = p_i1917_1_; this.recipeHeight = p_i1917_2_; this.recipeItems = ingredients; this.recipeOutput = result; } public ItemStack getRecipeOutput() { return this.recipeOutput; } public boolean customMatches(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting, World world) { for (int row = 0; row <= 5 - this.recipeWidth; ++row) { for (int column = 0; column <= 5 - this.recipeHeight; ++column) { if (row == 0 || row == 4) { return vanillaMatchesProcess(invCrafting, world, row, column); } else if (row == 1 || row == 3){ if (column == 0 || column == 4) { return vanillaMatchesProcess(invCrafting, world, row, column); } } else if (row == 2) { if (column != 1 && column != 3) { return vanillaMatchesProcess(invCrafting, world, row, column); } } } } return false; } public boolean vanillaMatchesProcess(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting, World world, int row, int column) { if (this.checkMatch(invCrafting, row, column, true)) { return true; } if (this.checkMatch(invCrafting, row, column, false)) { return true; } return false; } private boolean checkMatch(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting, int row0, int column0, boolean p_77573_4_) { for (int row = 0; row < 5; ++row) { for (int column = 0; column < 5; ++column) { int row1 = row - row0; int column1 = column - column0; ItemStack itemstack = null; if (row1 >= 0 && column1 >= 0 && row1 < this.recipeWidth && column1 < this.recipeHeight) { if (p_77573_4_) { itemstack = this.recipeItems[this.recipeWidth - row1 - 1 + column1 * this.recipeWidth]; } else { itemstack = this.recipeItems[row1 + column1 * this.recipeWidth]; } } ItemStack itemstack1 = invCrafting.getStackInRowAndColumn(row, column); if (itemstack1 != null || itemstack != null) { if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) { return false; } if (itemstack.getItem() != itemstack1.getItem()) { return false; } if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage()) { return false; } } } } return true; } public ItemStack customGetCraftingResult(WLLC_myWE_CrystalInfuserInventoryCrafting invCrafting) { ItemStack itemstack = this.getRecipeOutput().copy(); if (this.field_92101_f) { for (int i = 0; i < invCrafting.getSizeInventory(); ++i) { ItemStack itemstack1 = invCrafting.getStackInSlot(i); if (itemstack1 != null && itemstack1.hasTagCompound()) { itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy()); } } } return itemstack; } public int getRecipeSize() { return this.recipeWidth * this.recipeHeight; } public WLLC_myWE_CrystalInfuserShapedRecipes func_92100_c() { this.field_92101_f = true; return this; } @Override public boolean matches(InventoryCrafting invCrafting, World world) { return this.customMatches((WLLC_myWE_CrystalInfuserInventoryCrafting) invCrafting, world); } @Override public ItemStack getCraftingResult(InventoryCrafting invCrafting) { return this.customGetCraftingResult((WLLC_myWE_CrystalInfuserInventoryCrafting) invCrafting); } } How can I resolve this? Or I'm doing this terribly wrong? Thanks in advice Can we see your container code please? About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
August 27, 20187 yr Author Container code: Spoiler package com.WLLC.mysticWeapons.containers; import com.WLLC.mysticWeapons.blocks.WLLC_myWE_Blocks; import com.WLLC.mysticWeapons.crafting.crystalInfuser.WLLC_myWE_CrystalInfuserCraftingManager; import com.WLLC.mysticWeapons.crafting.crystalInfuser.WLLC_myWE_CrystalInfuserInventoryCrafting; 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.world.World; public class WLLC_myWE_CrystalInfuserContainer extends Container { public WLLC_myWE_CrystalInfuserInventoryCrafting craftMatrix; public IInventory craftResult; private World worldObj; private int posX, posY, posZ; public WLLC_myWE_CrystalInfuserContainer(InventoryPlayer invPlayer, World world, int x, int y, int z) { craftMatrix = new WLLC_myWE_CrystalInfuserInventoryCrafting(this); craftResult = new InventoryCraftResult(); worldObj = world; posX = x; posY = y; posZ = z; this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 141, 43)); for (int i = 0; i < 5; i++) { for (int k = 0; k < 5; k++) { if (i != 1 && i != 2 && i != 3) { this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 8 + k * 18, 7 + i * 18)); } else if (i == 1 || i == 3) { if (k == 0 || k == 4) { this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 8 + k * 18, 7 + i * 18)); } } else if (i == 2) { if (k != 1 && k != 3) { this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 8 + k * 18, 7 + i * 18)); } } } } for (int i = 0; i < 3; i++) { for (int k = 0; k < 9; k++) { this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 18, 106 + i * 18)); } } for (int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 164)); } onCraftMatrixChanged(craftMatrix); } public void onCraftMatrixChanged(IInventory iinventory) { craftResult.setInventorySlotContents(0, WLLC_myWE_CrystalInfuserCraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj)); } @Override public boolean canInteractWith(EntityPlayer player) { if (worldObj.getBlock(posX, posY, posZ) != WLLC_myWE_Blocks.crystalInfuser) { return false; } else { return player.getDistanceSq((double) posX + 0.5D, (double) posY + 0.5D, (double) posZ + 0.5D) <= 64.0D; } } public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); if (!this.worldObj.isRemote) { for (int i = 0; i < 25; ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); if (itemstack != null) { player.dropPlayerItemWithRandomChoice(itemstack, false); } } } } public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int invSlot) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(invSlot); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (invSlot == 0) { if (!this.mergeItemStack(itemstack1, 10, 46, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (invSlot >= 10 && invSlot < 37) { if (!this.mergeItemStack(itemstack1, 37, 46, false)) { return null; } } else if (invSlot >= 37 && invSlot < 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(p_82846_1_, itemstack1); } return itemstack; } }
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.