Résolu Table de craft buguée
-
Bonjour à tous, donc j’ai un petit problème pas trop gênant avec ma table de craft custom.
Enfaite, quand ej craft mon item, les ressources ne sont pas consommés. très peut gênant hein, t’a 9 diamants, BOOM t’en plus d’un million ( Même si le craft de bloc de diamant n’est pas possible sur ma table de craft )
Je sais pas ce qui cloche, j’ai peut-être laissé un ContainerWorktable, ou BlockWorktable, un truc comme cela. ( Ce qui est très peu probable vu que aucun de ces trucs ne figurent dans les importEnfin, ça peut être gênant dans le contexte du mod surtout avec les balles de fusils, qui seront craft sur cette table, avec 3 plaques d’or 1 lingot de fer et une poudre, des ressources pas donnés, et si tu peut en avoir à l’infini
Bloc
package eryah.usefulthings.blocks; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumFacing; import net.minecraft.util.IChatComponent; import net.minecraft.world.IInteractionObject; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; import eryah.usefulthings.container.ContainerWeaponTable; import eryah.usefulthings.tileentity.TileEntityCrusher; public class WeaponTable extends Block { protected WeaponTable(Material mat) { super(Material.iron); this.setHarvestLevel("pickaxe", 1); this.setHardness(10.0f); this.setResistance(15.0f); } public static Block weapon_table; public static void init() { weapon_table = new WeaponTable(Material.rock).setUnlocalizedName("weapon_table").setCreativeTab(UsefulthingsMod.UTTab); } public static void register() { GameRegistry.registerBlock(weapon_table, weapon_table.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(weapon_table); } public static void registerRender(Block block) { Item item = Item.getItemFromBlock(block); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { playerIn.openGui(UsefulthingsMod.instance, 2, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } @SideOnly(Side.CLIENT) public Item getItem(World worldIn, BlockPos pos) { return Item.getItemFromBlock(WeaponTable.weapon_table); } public static class InterfaceWeaponTable implements IInteractionObject { private final World world; private final BlockPos position; private static final String __OBFID = "CL_00002127"; public InterfaceWeaponTable(World worldIn, BlockPos pos) { this.world = worldIn; this.position = pos; } /** * Gets the name of this command sender (usually username, but possibly "Rcon") */ public String getName() { return null; } /** * Returns true if this thing is named */ public boolean hasCustomName() { return false; } public IChatComponent getDisplayName() { return new ChatComponentTranslation(WeaponTable.weapon_table.getUnlocalizedName() + ".name", new Object[0]); } public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerWeaponTable(playerInventory, this.world, this.position); } public String getGuiID() { return "ut:weapon_table"; } } }
Container
package eryah.usefulthings.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.util.BlockPos; import net.minecraft.world.World; import eryah.usefulthings.blocks.WeaponTable; import eryah.usefulthings.recipes.WeaponTableRecipes; public class ContainerWeaponTable extends Container { /** The crafting matrix inventory (3x3). */ public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); public IInventory craftResult = new InventoryCraftResult(); private World worldObj; private BlockPos field_178145_h; private static final String __OBFID = "CL_00001744"; public ContainerWeaponTable(InventoryPlayer playerInventory, World worldIn, BlockPos p_i45800_3_) { this.worldObj = worldIn; this.field_178145_h = p_i45800_3_; this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35)); int i; int j; for (i = 0; i < 3; ++i) { for (j = 0; j < 3; ++j) { this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18)); } } for (i = 0; i < 3; ++i) { for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142)); } this.onCraftMatrixChanged(this.craftMatrix); } /** * Callback for when the crafting matrix is changed. */ public void onCraftMatrixChanged(IInventory inventoryIn) { this.craftResult.setInventorySlotContents(0, WeaponTableRecipes.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } /** * Called when the container is closed. */ public void onContainerClosed(EntityPlayer playerIn) { super.onContainerClosed(playerIn); if (!this.worldObj.isRemote) { for (int i = 0; i < 9; ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); if (itemstack != null) { playerIn.dropPlayerItemWithRandomChoice(itemstack, false); } } } } public boolean canInteractWith(EntityPlayer playerIn) { return this.worldObj.getBlockState(this.field_178145_h).getBlock() != WeaponTable.weapon_table ? false : playerIn.getDistanceSq((double)this.field_178145_h.getX() + 0.5D, (double)this.field_178145_h.getY() + 0.5D, (double)this.field_178145_h.getZ() + 0.5D) <= 64.0D; } /** * Take a stack from the specified inventory slot. */ public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index == 0) { if (!this.mergeItemStack(itemstack1, 10, 46, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (index >= 10 && index < 37) { if (!this.mergeItemStack(itemstack1, 37, 46, false)) { return null; } } else if (index >= 37 && index < 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(playerIn, itemstack1); } return itemstack; } /** * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in * is null for the initial slot that was double-clicked. */ public boolean canMergeSlot(ItemStack p_94530_1_, Slot p_94530_2_) { return p_94530_2_.inventory != this.craftResult && super.canMergeSlot(p_94530_1_, p_94530_2_); } }
GUI
package eryah.usefulthings.gui; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.BlockPos; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import eryah.usefulthings.container.ContainerWeaponTable; @SideOnly(Side.CLIENT) public class GuiWeaponTable extends GuiContainer { private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("textures/gui/container/crafting_table.png"); private static final String __OBFID = "CL_00000750"; public GuiWeaponTable(InventoryPlayer playerInv, World worldIn) { this(playerInv, worldIn, BlockPos.ORIGIN); } public GuiWeaponTable(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition) { super(new ContainerWeaponTable(playerInv, worldIn, blockPosition)); } /** * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY */ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 28, 6, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); } /** * Args : renderPartialTicks, mouseX, mouseY */ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(craftingTableGuiTextures); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); } }
Recipes
package eryah.usefulthings.recipes; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import net.minecraft.block.Block; import net.minecraft.init.Blocks; 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.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.world.World; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import eryah.usefulthings.init.MakeshiftRifle; public class WeaponTableRecipes { /** The static instance of this class */ private static final WeaponTableRecipes instance = new WeaponTableRecipes(); /** A list of all the recipes added */ private final List recipes = Lists.newArrayList(); private static final String __OBFID = "CL_00000090"; /** * Returns the static instance of this class */ public static WeaponTableRecipes getInstance() { /** The static instance of this class */ return instance; } private WeaponTableRecipes() { this.addRecipe(new ItemStack(MakeshiftRifle.makeshift_rifle), new Object[] {"I I", "I I", " I ", 'I', Items.iron_ingot, 'C', Blocks.chest}); // Je précisie que ceci est le craft du hooper sans le coffre et qui donne mon item, et non le craft définitif ^^' } /** * Adds a shaped recipe to the games recipe list. */ public ShapedRecipes addRecipe(ItemStack stack, Object … recipeComponents) { String s = ""; int i = 0; int j = 0; int k = 0; if (recipeComponents* instanceof String[]) { String[] astring = (String[])((String[])recipeComponents[i++]); for (int l = 0; l < astring.length; ++l) { String s1 = astring[l]; ++k; j = s1.length(); s = s + s1; } } else { while (recipeComponents* instanceof String) { String s2 = (String)recipeComponents[i++]; ++k; j = s2.length(); s = s + s2; } } HashMap hashmap; for (hashmap = Maps.newHashMap(); i < recipeComponents.length; i += 2) { Character character = (Character)recipeComponents*; ItemStack itemstack1 = null; if (recipeComponents _instanceof Item) { itemstack1 = new ItemStack((Item)recipeComponents_); } else if (recipeComponents _instanceof Block) { itemstack1 = new ItemStack((Block)recipeComponents_, 1, 32767); } else if (recipeComponents _instanceof ItemStack) { itemstack1 = (ItemStack)recipeComponents_; } 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; } } ShapedRecipes shapedrecipes = new ShapedRecipes(j, k, aitemstack, stack); this.recipes.add(shapedrecipes); return shapedrecipes; } /** * Adds a shapeless crafting recipe to the the game. * * @param recipeComponents An array of ItemStack's Item's and Block's that make up the recipe. */ public void addShapelessRecipe(ItemStack stack, Object … recipeComponents) { ArrayList arraylist = Lists.newArrayList(); Object[] aobject = recipeComponents; int i = recipeComponents.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 IllegalArgumentException("Invalid shapeless recipe: unknown type " + object1.getClass().getName() + "!"); } arraylist.add(new ItemStack((Block)object1)); } } this.recipes.add(new ShapelessRecipes(stack, arraylist)); } /** * Adds an IRecipe to the list of crafting recipes. * * @param recipe A recipe that will be added to the recipe list. */ public void addRecipe(IRecipe recipe) { this.recipes.add(recipe); } /** * Retrieves an ItemStack that has multiple recipes for it. */ public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World worldIn) { Iterator iterator = this.recipes.iterator(); IRecipe irecipe; do { if (!iterator.hasNext()) { return null; } irecipe = (IRecipe)iterator.next(); } while (!irecipe.matches(p_82787_1_, worldIn)); return irecipe.getCraftingResult(p_82787_1_); } public ItemStack[] func_180303_b(InventoryCrafting p_180303_1_, World worldIn) { Iterator iterator = this.recipes.iterator(); while (iterator.hasNext()) { IRecipe irecipe = (IRecipe)iterator.next(); if (irecipe.matches(p_180303_1_, worldIn)) { return irecipe.getRemainingItems(p_180303_1_); } } ItemStack[] aitemstack = new ItemStack[p_180303_1_.getSizeInventory()]; for (int i = 0; i < aitemstack.length; ++i) { aitemstack* = p_180303_1_.getStackInSlot(i); } return aitemstack; } /** * returns the List<> of all recipes */ public List getRecipeList() { return this.recipes; } } ```______
-
Bon, déjà retire tous les private static final String __OBFID = “CL_00001744”; ils n’ont rien à faire là.
Le problème est surement au niveau du container, mais je ne vois pas où il est. -
J’aime paaaaaaaaaaaas les problèmes inexpliqués !!
Je check aprtout, je trouve rien, mais après, je comprend rien au GUI, Container, donc c’est dur, mais j’ai check partout, j’ai comparé avec le code de base, y’a aucune différence….
Je comprend rien à cette erreur…
Je vais approfondir ma recherche, mais la, franchement, je coincePS : Je vois pas à quoi sert le string, que tu me demande d’enlever à chaque fois
Il ne gêne pas, il n’est pas utilisé, il sert a rien, donc je vois pas pourquoi l’enlever. Enfi oui je vois, c’est pour que ce soit plus propre, mais je n’y pense pas tout le temps, puisqu’il ne gêne pas dans le code
Peut-etre qu’il gêne, mais je ne voit pas en quoiEDIT : J’ai trouvé un bon s’homme ( Orthographe volontaire ) dans le même cas que moi. Malheureusement, je suis un homme assez contradictioire, je comrpend facilement l’anglais en audio, et j’écris mieux l’anglais que je ne le parle. Mais quand il s’agit de lire de l’anglais, j’ia du mal.
http://www.minecraftforge.net/forum/index.php?topic=30417.0 -
Le String inutile sert à réobfusqué/déobfusqué les classes. Donc pas besoin dans tes propres classes.
Le problème vient du fait que le clear de la table de craft se fait lorsqu’on enlève un Item du slot de résultat, Minecraft utilise un slot custom mais toi tu as ajouté des slots normaux.
-
Ah, et comment faire, j’aurais besoin d’éclairement,car moi et les GUI’s, sa fait 2, voir 3 peut-etre
Faut que je fasse ma propre classe de slot ?
(Je fais tenter cela, car il y a bien Slot, et SlotCrafting )Edit: Non, c’est pas ça. Bon j’ai juste fait un copier coller de la classe vanilla…
Il faut peut-etre rajouter un truc mais je sais pas ce que c’estpackage net.minecraft.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.stats.AchievementList; public class SlotCrafting extends Slot { /** The craft matrix inventory linked to this result slot. */ private final InventoryCrafting craftMatrix; /** The player that is using the GUI where this slot resides. */ private final EntityPlayer thePlayer; /** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */ private int amountCrafted; private static final String __OBFID = "CL_00001761"; public SlotCrafting(EntityPlayer player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition) { super(p_i45790_3_, slotIndex, xPosition, yPosition); this.thePlayer = player; this.craftMatrix = craftingInventory; } /** * Check if the stack is a valid item for this slot. Always true beside for the armor slots. */ public boolean isItemValid(ItemStack stack) { return false; } /** * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new * stack. */ public ItemStack decrStackSize(int amount) { if (this.getHasStack()) { this.amountCrafted += Math.min(amount, this.getStack().stackSize); } return super.decrStackSize(amount); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an * internal count then calls onCrafting(item). */ protected void onCrafting(ItemStack stack, int amount) { this.amountCrafted += amount; this.onCrafting(stack); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack stack) { if (this.amountCrafted > 0) { stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); } this.amountCrafted = 0; if (stack.getItem() == Item.getItemFromBlock(Blocks.crafting_table)) { this.thePlayer.triggerAchievement(AchievementList.buildWorkBench); } if (stack.getItem() instanceof ItemPickaxe) { this.thePlayer.triggerAchievement(AchievementList.buildPickaxe); } if (stack.getItem() == Item.getItemFromBlock(Blocks.furnace)) { this.thePlayer.triggerAchievement(AchievementList.buildFurnace); } if (stack.getItem() instanceof ItemHoe) { this.thePlayer.triggerAchievement(AchievementList.buildHoe); } if (stack.getItem() == Items.bread) { this.thePlayer.triggerAchievement(AchievementList.makeBread); } if (stack.getItem() == Items.cake) { this.thePlayer.triggerAchievement(AchievementList.bakeCake); } if (stack.getItem() instanceof ItemPickaxe && ((ItemPickaxe)stack.getItem()).getToolMaterial() != Item.ToolMaterial.WOOD) { this.thePlayer.triggerAchievement(AchievementList.buildBetterPickaxe); } if (stack.getItem() instanceof ItemSword) { this.thePlayer.triggerAchievement(AchievementList.buildSword); } if (stack.getItem() == Item.getItemFromBlock(Blocks.enchanting_table)) { this.thePlayer.triggerAchievement(AchievementList.enchantments); } if (stack.getItem() == Item.getItemFromBlock(Blocks.bookshelf)) { this.thePlayer.triggerAchievement(AchievementList.bookcase); } if (stack.getItem() == Items.golden_apple && stack.getMetadata() == 1) { this.thePlayer.triggerAchievement(AchievementList.overpowered); } } public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix); this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(playerIn); ItemStack[] aitemstack = CraftingManager.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < aitemstack.length; ++i) { ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); ItemStack itemstack2 = aitemstack*; if (itemstack1 != null) { this.craftMatrix.decrStackSize(i, 1); } if (itemstack2 != null) { if (this.craftMatrix.getStackInSlot(i) == null) { this.craftMatrix.setInventorySlotContents(i, itemstack2); } else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2)) { this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false); } } } } }
EDIT² j’ai trouvé l’erreur mais je ne peut pas al corriger maintenat
-
C’était ça, maintenant, trouvez l’erreur
( Elle est plûtot simple a trouver, je l’ai vu en quelques secondes )
Le premier qui trouve aura le droit à un COOKIE -
Enleve ça: private static final String __OBFID = “CL_00001761”; c’est pour l’obfuscation, tu n’en as pas besoin
-
J’en ai pas besoin mais il ne gêne as, j’ai carrèment la flemme de l’enlever pour être franc
-
Haha, d’accord
-
Ah, je viens de me rendre compte que c’est pas ma classe … Fuck, désolé ^^’
Voici ma classepackage eryah.usefulthings.container; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import eryah.usefulthings.recipes.WeaponTableRecipes; public class SlotWeaponResult extends Slot { /** The craft matrix inventory linked to this result slot. */ private final InventoryCrafting craftMatrix; /** The player that is using the GUI where this slot resides. */ private final EntityPlayer thePlayer; /** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */ private int amountCrafted; public SlotWeaponResult(EntityPlayer player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition) { super(p_i45790_3_, slotIndex, xPosition, yPosition); this.thePlayer = player; this.craftMatrix = craftingInventory; } /** * Check if the stack is a valid item for this slot. Always true beside for the armor slots. */ public boolean isItemValid(ItemStack stack) { return false; } /** * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new * stack. */ public ItemStack decrStackSize(int amount) { if (this.getHasStack()) { this.amountCrafted += Math.min(amount, this.getStack().stackSize); } return super.decrStackSize(amount); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an * internal count then calls onCrafting(item). */ protected void onCrafting(ItemStack stack, int amount) { this.amountCrafted += amount; this.onCrafting(stack); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack stack) { if (this.amountCrafted > 0) { stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); } this.amountCrafted = 0; } public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix); this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(playerIn); ItemStack[] aitemstack = WeaponTableRecipes.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < aitemstack.length; ++i) { ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); ItemStack itemstack2 = aitemstack*; if (itemstack1 != null) { this.craftMatrix.decrStackSize(i, 1); } if (itemstack2 != null) { if (this.craftMatrix.getStackInSlot(i) == null) { this.craftMatrix.setInventorySlotContents(i, itemstack2); } else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2)) { this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false); } } } } }
-
protected void onCrafting(ItemStack stack, int amount) { this.amountCrafted += amount; this.onCrafting(stack); }
Tu augmentes le nombre d’items dans la case résultat sans vider la matrice de craft?
**EDIT : **Je suis con, amountCrafted c’est même pas le nombre d’items en résultat… si?
EDIT 2 :…Eryah il est con aussi, il nous donne la classe corrigée, comment il veut qu’on trouve l’erreur facepalm -
Ca pourrait être ça, mais non
-
J’ai mis la classe corrigée –’
package eryah.usefulthings.container; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import eryah.usefulthings.recipes.WeaponTableRecipes; public class SlotWeaponResult extends Slot { /** The craft matrix inventory linked to this result slot. */ private final InventoryCrafting craftMatrix; /** The player that is using the GUI where this slot resides. */ private final EntityPlayer thePlayer; /** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */ private int amountCrafted; public SlotWeaponResult(EntityPlayer player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition) { super(p_i45790_3_, slotIndex, xPosition, yPosition); this.thePlayer = player; this.craftMatrix = craftingInventory; } /** * Check if the stack is a valid item for this slot. Always true beside for the armor slots. */ public boolean isItemValid(ItemStack stack) { return false; } /** * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new * stack. */ public ItemStack decrStackSize(int amount) { if (this.getHasStack()) { this.amountCrafted += Math.min(amount, this.getStack().stackSize); } return super.decrStackSize(amount); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an * internal count then calls onCrafting(item). */ protected void onCrafting(ItemStack stack, int amount) { this.amountCrafted += amount; this.onCrafting(stack); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack stack) { if (this.amountCrafted > 0) { stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); } this.amountCrafted = 0; } public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix); this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(playerIn); ItemStack[] aitemstack = CraftingManager.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < aitemstack.length; ++i) { ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); ItemStack itemstack2 = aitemstack*; if (itemstack1 != null) { this.craftMatrix.decrStackSize(i, 1); } if (itemstack2 != null) { if (this.craftMatrix.getStackInSlot(i) == null) { this.craftMatrix.setInventorySlotContents(i, itemstack2); } else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2)) { this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false); } } } } }
-
Code erroné :
ItemStack[] aitemstack = CraftingManager.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj);
Code corrigé :
ItemStack[] aitemstack = WeaponTableRecipes.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj);
:::
Trouvé avec ceci x)
::: -
Je l’ai dit avant
-
Mais pas sur ce topic
-
Arghhh je venais de voir le même truc x( mais Sasukz, tu fus plus rapide…
-
Vous avez gagnés un cookie
GG a vous deux -
C’était easy avec Winmerge