Table de craft perso
-
Salut, je tente de faire une table de craft personnaliser. Tout va bien, mais le Gui ne s’ouvre pas. Je comprend pas pourquoi. Je suis en 1.6.2, voici mes class:
Main
:::package Crafting; import net.minecraft.block.Block; import net.minecraft.block.BlockWorkbench; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid="CT", name="NOMMOD", version="SA VERSION") @NetworkMod(clientSideRequired=true, serverSideRequired=false) // NE PAS MODIFIER CETTE LIGNE public class main { public static Block craftingtable; @Instance("CT") public static main instance; private GuiHandler guiHandler = new GuiHandler(); @SidedProxy(clientSide="Crafting.ClientProxy", serverSide="Crafting.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { } @EventHandler public void load(FMLInitializationEvent event) { proxy.registerRenderers(); craftingtable = new CraftingTable(650).setHardness(2.5F).setUnlocalizedName("craftingtable").func_111022_d("table").setStepSound(Block.soundStoneFootstep); GameRegistry.registerBlock(craftingtable, "Quartz Workbench"); NetworkRegistry.instance().registerGuiHandler(this, guiHandler); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }
:::
Container
:::package Crafting; import net.minecraft.block.Block; 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; public class ContainerTable extends Container { /** The crafting matrix inventory (3x3). */ public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); public IInventory craftResult = new InventoryCraftResult(); private World worldObj; private int posX; private int posY; private int posZ; public ContainerTable(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); } /** * Callback for when the crafting matrix is changed. */ public void onCraftMatrixChanged(IInventory par1IInventory) { this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } /** * Called when the container is closed. */ public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); if (!this.worldObj.isRemote) { for (int i = 0; i < 9; ++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) != main.craftingtable.blockID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D; } /** * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. */ 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); } }
:::
Le Block
:::package Crafting; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.Icon; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class CraftingTable extends Block { @SideOnly(Side.CLIENT) private Icon tableIconBottom; @SideOnly(Side.CLIENT) private Icon tableIconTop; @SideOnly(Side.CLIENT) private Icon tableIconFront; protected CraftingTable(int par1) { super(par1, Material.wood); this.setCreativeTab(CreativeTabs.tabDecorations); } @SideOnly(Side.CLIENT) public Icon getIcon(int side, int metadata) { if(side == 0) { return tableIconBottom; } else if(side == 1) { return tableIconTop; } else { return tableIconFront; } } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon("ct:table_Side"); this.tableIconFront = par1IconRegister.registerIcon("ct:table_Front"); this.tableIconBottom = par1IconRegister.registerIcon("ct:table_Bottom"); this.tableIconTop = par1IconRegister.registerIcon( "ct:table_Top"); } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if (par1World.isRemote) { return true; } else { par5EntityPlayer.displayGUIWorkbench(par2, par3, par4); return true; } } }
:::
Le GuiHandler
:::package Crafting; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile_entity = world.getBlockTileEntity(x, y, z); switch(id) { case 0: return id == 0 && world.getBlockId(x, y, z) == main.craftingtable.blockID ? new ContainerTable(player.inventory, world, x, y, z) : null; } return null; } @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile_entity = world.getBlockTileEntity(x, y, z); switch(id) { case 0: return id == 0 && world.getBlockId(x, y, z) == main.craftingtable.blockID ? new TableGui(player.inventory, world, x, y, z) : null; } return null; } }
:::
Le Slot
:::package Crafting; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.AchievementList; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; import cpw.mods.fml.common.registry.GameRegistry; public class SlotTable extends Slot { /** The craft matrix inventory linked to this result slot. */ private final IInventory craftMatrix; /** The player that is using the GUI where this slot resides. */ private EntityPlayer thePlayer; /** * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */ private int amountCrafted; public SlotTable(EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6) { super(par3IInventory, par4, par5, par6); this.thePlayer = par1EntityPlayer; this.craftMatrix = par2IInventory; } /** * Check if the stack is a valid item for this slot. Always true beside for the armor slots. */ public boolean isItemValid(ItemStack par1ItemStack) { 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 par1) { if (this.getHasStack()) { this.amountCrafted += Math.min(par1, this.getStack().stackSize); } return super.decrStackSize(par1); } /** * 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 par1ItemStack, int par2) { this.amountCrafted += par2; this.onCrafting(par1ItemStack); } /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack par1ItemStack) { par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); this.amountCrafted = 0; if (par1ItemStack.itemID == Block.workbench.blockID) { this.thePlayer.addStat(AchievementList.buildWorkBench, 1); } else if (par1ItemStack.itemID == Item.pickaxeWood.itemID) { this.thePlayer.addStat(AchievementList.buildPickaxe, 1); } else if (par1ItemStack.itemID == Block.furnaceIdle.blockID) { this.thePlayer.addStat(AchievementList.buildFurnace, 1); } else if (par1ItemStack.itemID == Item.hoeWood.itemID) { this.thePlayer.addStat(AchievementList.buildHoe, 1); } else if (par1ItemStack.itemID == Item.bread.itemID) { this.thePlayer.addStat(AchievementList.makeBread, 1); } else if (par1ItemStack.itemID == Item.cake.itemID) { this.thePlayer.addStat(AchievementList.bakeCake, 1); } else if (par1ItemStack.itemID == Item.pickaxeStone.itemID) { this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1); } else if (par1ItemStack.itemID == Item.swordWood.itemID) { this.thePlayer.addStat(AchievementList.buildSword, 1); } else if (par1ItemStack.itemID == Block.enchantmentTable.blockID) { this.thePlayer.addStat(AchievementList.enchantments, 1); } else if (par1ItemStack.itemID == Block.bookShelf.blockID) { this.thePlayer.addStat(AchievementList.bookcase, 1); } } public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) { GameRegistry.onItemCrafted(par1EntityPlayer, par2ItemStack, craftMatrix); this.onCrafting(par2ItemStack); for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i) { ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); if (itemstack1 != null) { this.craftMatrix.decrStackSize(i, 1); if (itemstack1.getItem().hasContainerItem()) { ItemStack itemstack2 = itemstack1.getItem().getContainerItemStack(itemstack1); if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage()) { MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2)); itemstack2 = null; } if (itemstack2 != null && (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !this.thePlayer.inventory.addItemStackToInventory(itemstack2))) { if (this.craftMatrix.getStackInSlot(i) == null) { this.craftMatrix.setInventorySlotContents(i, itemstack2); } else { this.thePlayer.dropPlayerItem(itemstack2); } } } } } } }
:::
Le CraftingManager
:::package 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.item.crafting.RecipeFireworks; import net.minecraft.item.crafting.RecipesArmor; import net.minecraft.item.crafting.RecipesArmorDyes; import net.minecraft.item.crafting.RecipesCrafting; import net.minecraft.item.crafting.RecipesDyes; import net.minecraft.item.crafting.RecipesFood; import net.minecraft.item.crafting.RecipesIngots; import net.minecraft.item.crafting.RecipesMapCloning; import net.minecraft.item.crafting.RecipesMapExtending; import net.minecraft.item.crafting.RecipesTools; import net.minecraft.item.crafting.RecipesWeapons; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraft.world.World; public class tablecraftingmanager { /** The static instance of this class */ private static final tablecraftingmanager instance = new tablecraftingmanager(); /** A list of all the recipes added */ private List recipes = new ArrayList(); /** * Returns the static instance of this class */ public static final tablecraftingmanager getInstance() { return instance; } private tablecraftingmanager() { this.recipes.add(new RecipesArmorDyes()); this.recipes.add(new RecipesMapCloning()); this.recipes.add(new RecipesMapExtending()); this.recipes.add(new RecipeFireworks()); this.addRecipe(new ItemStack(Item.paper, 3), new Object[] {"###", '#', Item.reed}); this.addShapelessRecipe(new ItemStack(Item.book, 1), new Object[] {Item.paper, Item.paper, Item.paper, Item.leather}); this.addShapelessRecipe(new ItemStack(Item.writableBook, 1), new Object[] {Item.book, new ItemStack(Item.dyePowder, 1, 0), Item.feather}); this.addRecipe(new ItemStack(Block.fence, 2), new Object[] {"###", "###", '#', Item.stick}); this.addRecipe(new ItemStack(Block.cobblestoneWall, 6, 0), new Object[] {"###", "###", '#', Block.cobblestone}); this.addRecipe(new ItemStack(Block.cobblestoneWall, 6, 1), new Object[] {"###", "###", '#', Block.cobblestoneMossy}); this.addRecipe(new ItemStack(Block.netherFence, 6), new Object[] {"###", "###", '#', Block.netherBrick}); this.addRecipe(new ItemStack(Block.fenceGate, 1), new Object[] {"#W#", "#W#", '#', Item.stick, 'W', Block.planks}); this.addRecipe(new ItemStack(Block.jukebox, 1), new Object[] {"###", "#X#", "###", '#', Block.planks, 'X', Item.diamond}); this.addRecipe(new ItemStack(Item.field_111214_ch, 2), new Object[] {"~~ ", "~O ", " ~", '~', Item.silk, 'O', Item.slimeBall}); this.addRecipe(new ItemStack(Block.music, 1), new Object[] {"###", "#X#", "###", '#', Block.planks, 'X', Item.redstone}); this.addRecipe(new ItemStack(Block.bookShelf, 1), new Object[] {"###", "XXX", "###", '#', Block.planks, 'X', Item.book}); this.addRecipe(new ItemStack(Block.blockSnow, 1), new Object[] {"##", "##", '#', Item.snowball}); this.addRecipe(new ItemStack(Block.snow, 6), new Object[] {"###", '#', Block.blockSnow}); this.addRecipe(new ItemStack(Block.blockClay, 1), new Object[] {"##", "##", '#', Item.clay}); this.addRecipe(new ItemStack(Block.brick, 1), new Object[] {"##", "##", '#', Item.brick}); this.addRecipe(new ItemStack(Block.glowStone, 1), new Object[] {"##", "##", '#', Item.glowstone}); this.addRecipe(new ItemStack(Block.blockNetherQuartz, 1), new Object[] {"##", "##", '#', Item.netherQuartz}); this.addRecipe(new ItemStack(Block.cloth, 1), new Object[] {"##", "##", '#', Item.silk}); this.addRecipe(new ItemStack(Block.tnt, 1), new Object[] {"X#X", "#X#", "X#X", 'X', Item.gunpowder, '#', Block.sand}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 3), new Object[] {"###", '#', Block.cobblestone}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 0), new Object[] {"###", '#', Block.stone}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 1), new Object[] {"###", '#', Block.sandStone}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 4), new Object[] {"###", '#', Block.brick}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 5), new Object[] {"###", '#', Block.stoneBrick}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 6), new Object[] {"###", '#', Block.netherBrick}); this.addRecipe(new ItemStack(Block.stoneSingleSlab, 6, 7), new Object[] {"###", '#', Block.blockNetherQuartz}); this.addRecipe(new ItemStack(Block.woodSingleSlab, 6, 0), new Object[] {"###", '#', new ItemStack(Block.planks, 1, 0)}); this.addRecipe(new ItemStack(Block.woodSingleSlab, 6, 2), new Object[] {"###", '#', new ItemStack(Block.planks, 1, 2)}); this.addRecipe(new ItemStack(Block.woodSingleSlab, 6, 1), new Object[] {"###", '#', new ItemStack(Block.planks, 1, 1)}); this.addRecipe(new ItemStack(Block.woodSingleSlab, 6, 3), new Object[] {"###", '#', new ItemStack(Block.planks, 1, 3)}); this.addRecipe(new ItemStack(Block.ladder, 3), new Object[] {"# #", "###", "# #", '#', Item.stick}); this.addRecipe(new ItemStack(Item.doorWood, 1), new Object[] {"##", "##", "##", '#', Block.planks}); this.addRecipe(new ItemStack(Block.trapdoor, 2), new Object[] {"###", "###", '#', Block.planks}); this.addRecipe(new ItemStack(Item.doorIron, 1), new Object[] {"##", "##", "##", '#', Item.ingotIron}); this.addRecipe(new ItemStack(Item.sign, 3), new Object[] {"###", "###", " X ", '#', Block.planks, 'X', Item.stick}); this.addRecipe(new ItemStack(Item.cake, 1), new Object[] {"AAA", "BEB", "CCC", 'A', Item.bucketMilk, 'B', Item.sugar, 'C', Item.wheat, 'E', Item.egg}); this.addRecipe(new ItemStack(Item.sugar, 1), new Object[] {"#", '#', Item.reed}); this.addRecipe(new ItemStack(Block.planks, 4, 0), new Object[] {"#", '#', new ItemStack(Block.wood, 1, 0)}); this.addRecipe(new ItemStack(Block.planks, 4, 1), new Object[] {"#", '#', new ItemStack(Block.wood, 1, 1)}); this.addRecipe(new ItemStack(Block.planks, 4, 2), new Object[] {"#", '#', new ItemStack(Block.wood, 1, 2)}); this.addRecipe(new ItemStack(Block.planks, 4, 3), new Object[] {"#", '#', new ItemStack(Block.wood, 1, 3)}); this.addRecipe(new ItemStack(Item.stick, 4), new Object[] {"#", "#", '#', Block.planks}); this.addRecipe(new ItemStack(Block.torchWood, 4), new Object[] {"X", "#", 'X', Item.coal, '#', Item.stick}); this.addRecipe(new ItemStack(Block.torchWood, 4), new Object[] {"X", "#", 'X', new ItemStack(Item.coal, 1, 1), '#', Item.stick}); this.addRecipe(new ItemStack(Item.bowlEmpty, 4), new Object[] {"# #", " # ", '#', Block.planks}); this.addRecipe(new ItemStack(Item.glassBottle, 3), new Object[] {"# #", " # ", '#', Block.glass}); this.addRecipe(new ItemStack(Block.rail, 16), new Object[] {"X X", "X#X", "X X", 'X', Item.ingotIron, '#', Item.stick}); this.addRecipe(new ItemStack(Block.railPowered, 6), new Object[] {"X X", "X#X", "XRX", 'X', Item.ingotGold, 'R', Item.redstone, '#', Item.stick}); this.addRecipe(new ItemStack(Block.railActivator, 6), new Object[] {"XSX", "X#X", "XSX", 'X', Item.ingotIron, '#', Block.torchRedstoneActive, 'S', Item.stick}); this.addRecipe(new ItemStack(Block.railDetector, 6), new Object[] {"X X", "X#X", "XRX", 'X', Item.ingotIron, 'R', Item.redstone, '#', Block.pressurePlateStone}); this.addRecipe(new ItemStack(Item.minecartEmpty, 1), new Object[] {"# #", "###", '#', Item.ingotIron}); this.addRecipe(new ItemStack(Item.cauldron, 1), new Object[] {"# #", "# #", "###", '#', Item.ingotIron}); this.addRecipe(new ItemStack(Item.brewingStand, 1), new Object[] {" B ", "###", '#', Block.cobblestone, 'B', Item.blazeRod}); this.addRecipe(new ItemStack(Block.pumpkinLantern, 1), new Object[] {"A", "B", 'A', Block.pumpkin, 'B', Block.torchWood}); this.addRecipe(new ItemStack(Item.minecartCrate, 1), new Object[] {"A", "B", 'A', Block.chest, 'B', Item.minecartEmpty}); this.addRecipe(new ItemStack(Item.minecartPowered, 1), new Object[] {"A", "B", 'A', Block.furnaceIdle, 'B', Item.minecartEmpty}); this.addRecipe(new ItemStack(Item.minecartTnt, 1), new Object[] {"A", "B", 'A', Block.tnt, 'B', Item.minecartEmpty}); this.addRecipe(new ItemStack(Item.minecartHopper, 1), new Object[] {"A", "B", 'A', Block.hopperBlock, 'B', Item.minecartEmpty}); this.addRecipe(new ItemStack(Item.boat, 1), new Object[] {"# #", "###", '#', Block.planks}); this.addRecipe(new ItemStack(Item.bucketEmpty, 1), new Object[] {"# #", " # ", '#', Item.ingotIron}); this.addRecipe(new ItemStack(Item.flowerPot, 1), new Object[] {"# #", " # ", '#', Item.brick}); this.addRecipe(new ItemStack(Item.flintAndSteel, 1), new Object[] {"A ", " B", 'A', Item.ingotIron, 'B', Item.flint}); this.addRecipe(new ItemStack(Item.bread, 1), new Object[] {"###", '#', Item.wheat}); this.addRecipe(new ItemStack(Block.stairsWoodOak, 4), new Object[] {"# ", "## ", "###", '#', new ItemStack(Block.planks, 1, 0)}); this.addRecipe(new ItemStack(Block.stairsWoodBirch, 4), new Object[] {"# ", "## ", "###", '#', new ItemStack(Block.planks, 1, 2)}); this.addRecipe(new ItemStack(Block.stairsWoodSpruce, 4), new Object[] {"# ", "## ", "###", '#', new ItemStack(Block.planks, 1, 1)}); this.addRecipe(new ItemStack(Block.stairsWoodJungle, 4), new Object[] {"# ", "## ", "###", '#', new ItemStack(Block.planks, 1, 3)}); this.addRecipe(new ItemStack(Item.fishingRod, 1), new Object[] {" #", " #X", "# X", '#', Item.stick, 'X', Item.silk}); this.addRecipe(new ItemStack(Item.carrotOnAStick, 1), new Object[] {"# ", " X", '#', Item.fishingRod, 'X', Item.carrot}).func_92100_c(); this.addRecipe(new ItemStack(Block.stairsCobblestone, 4), new Object[] {"# ", "## ", "###", '#', Block.cobblestone}); this.addRecipe(new ItemStack(Block.stairsBrick, 4), new Object[] {"# ", "## ", "###", '#', Block.brick}); this.addRecipe(new ItemStack(Block.stairsStoneBrick, 4), new Object[] {"# ", "## ", "###", '#', Block.stoneBrick}); this.addRecipe(new ItemStack(Block.stairsNetherBrick, 4), new Object[] {"# ", "## ", "###", '#', Block.netherBrick}); this.addRecipe(new ItemStack(Block.stairsSandStone, 4), new Object[] {"# ", "## ", "###", '#', Block.sandStone}); this.addRecipe(new ItemStack(Block.stairsNetherQuartz, 4), new Object[] {"# ", "## ", "###", '#', Block.blockNetherQuartz}); this.addRecipe(new ItemStack(Item.painting, 1), new Object[] {"###", "#X#", "###", '#', Item.stick, 'X', Block.cloth}); this.addRecipe(new ItemStack(Item.itemFrame, 1), new Object[] {"###", "#X#", "###", '#', Item.stick, 'X', Item.leather}); this.addRecipe(new ItemStack(Item.appleGold, 1, 0), new Object[] {"###", "#X#", "###", '#', Item.ingotGold, 'X', Item.appleRed}); this.addRecipe(new ItemStack(Item.appleGold, 1, 1), new Object[] {"###", "#X#", "###", '#', Block.blockGold, 'X', Item.appleRed}); this.addRecipe(new ItemStack(Item.goldenCarrot, 1, 0), new Object[] {"###", "#X#", "###", '#', Item.goldNugget, 'X', Item.carrot}); this.addRecipe(new ItemStack(Item.speckledMelon, 1), new Object[] {"###", "#X#", "###", '#', Item.goldNugget, 'X', Item.melon}); this.addRecipe(new ItemStack(Block.lever, 1), new Object[] {"X", "#", '#', Block.cobblestone, 'X', Item.stick}); this.addRecipe(new ItemStack(Block.tripWireSource, 2), new Object[] {"I", "S", "#", '#', Block.planks, 'S', Item.stick, 'I', Item.ingotIron}); this.addRecipe(new ItemStack(Block.torchRedstoneActive, 1), new Object[] {"X", "#", '#', Item.stick, 'X', Item.redstone}); this.addRecipe(new ItemStack(Item.redstoneRepeater, 1), new Object[] {"#X#", "III", '#', Block.torchRedstoneActive, 'X', Item.redstone, 'I', Block.stone}); this.addRecipe(new ItemStack(Item.comparator, 1), new Object[] {" # ", "#X#", "III", '#', Block.torchRedstoneActive, 'X', Item.netherQuartz, 'I', Block.stone}); this.addRecipe(new ItemStack(Item.pocketSundial, 1), new Object[] {" # ", "#X#", " # ", '#', Item.ingotGold, 'X', Item.redstone}); this.addRecipe(new ItemStack(Item.compass, 1), new Object[] {" # ", "#X#", " # ", '#', Item.ingotIron, 'X', Item.redstone}); this.addRecipe(new ItemStack(Item.emptyMap, 1), new Object[] {"###", "#X#", "###", '#', Item.paper, 'X', Item.compass}); this.addRecipe(new ItemStack(Block.stoneButton, 1), new Object[] {"#", '#', Block.stone}); this.addRecipe(new ItemStack(Block.woodenButton, 1), new Object[] {"#", '#', Block.planks}); this.addRecipe(new ItemStack(Block.pressurePlateStone, 1), new Object[] {"##", '#', Block.stone}); this.addRecipe(new ItemStack(Block.pressurePlatePlanks, 1), new Object[] {"##", '#', Block.planks}); this.addRecipe(new ItemStack(Block.pressurePlateIron, 1), new Object[] {"##", '#', Item.ingotIron}); this.addRecipe(new ItemStack(Block.pressurePlateGold, 1), new Object[] {"##", '#', Item.ingotGold}); this.addRecipe(new ItemStack(Block.dispenser, 1), new Object[] {"###", "#X#", "#R#", '#', Block.cobblestone, 'X', Item.bow, 'R', Item.redstone}); this.addRecipe(new ItemStack(Block.dropper, 1), new Object[] {"###", "# #", "#R#", '#', Block.cobblestone, 'R', Item.redstone}); this.addRecipe(new ItemStack(Block.pistonBase, 1), new Object[] {"TTT", "#X#", "#R#", '#', Block.cobblestone, 'X', Item.ingotIron, 'R', Item.redstone, 'T', Block.planks}); this.addRecipe(new ItemStack(Block.pistonStickyBase, 1), new Object[] {"S", "P", 'S', Item.slimeBall, 'P', Block.pistonBase}); this.addRecipe(new ItemStack(Item.bed, 1), new Object[] {"###", "XXX", '#', Block.cloth, 'X', Block.planks}); this.addRecipe(new ItemStack(Block.enchantmentTable, 1), new Object[] {" B ", "D#D", "###", '#', Block.obsidian, 'B', Item.book, 'D', Item.diamond}); this.addRecipe(new ItemStack(Block.anvil, 1), new Object[] {"III", " i ", "iii", 'I', Block.blockIron, 'i', Item.ingotIron}); this.addShapelessRecipe(new ItemStack(Item.eyeOfEnder, 1), new Object[] {Item.enderPearl, Item.blazePowder}); this.addShapelessRecipe(new ItemStack(Item.fireballCharge, 3), new Object[] {Item.gunpowder, Item.blazePowder, Item.coal}); this.addShapelessRecipe(new ItemStack(Item.fireballCharge, 3), new Object[] {Item.gunpowder, Item.blazePowder, new ItemStack(Item.coal, 1, 1)}); this.addRecipe(new ItemStack(Block.daylightSensor), new Object[] {"GGG", "QQQ", "WWW", 'G', Block.glass, 'Q', Item.netherQuartz, 'W', Block.woodSingleSlab}); this.addRecipe(new ItemStack(Block.hopperBlock), new Object[] {"I I", "ICI", " I ", 'I', Item.ingotIron, 'C', Block.chest}); Collections.sort(this.recipes, new RecipeSorter(this)); } public ShapedRecipes addRecipe(ItemStack par1ItemStack, Object … par2ArrayOfObj) { String s = ""; int i = 0; int j = 0; int k = 0; if (par2ArrayOfObj* 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* instanceof String) { String s2 = (String)par2ArrayOfObj[i++]; ++k; j = s2.length(); s = s + s2; } } HashMap hashmap; for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2) { Character character = (Character)par2ArrayOfObj*; ItemStack itemstack1 = null; if (par2ArrayOfObj _instanceof Item) { itemstack1 = new ItemStack((Item)par2ArrayOfObj_); } else if (par2ArrayOfObj _instanceof Block) { itemstack1 = new ItemStack((Block)par2ArrayOfObj_, 1, 32767); } else if (par2ArrayOfObj _instanceof ItemStack) { itemstack1 = (ItemStack)par2ArrayOfObj_; } 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, 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 recipy!"); } arraylist.add(new ItemStack((Block)object1)); } } this.recipes.add(new ShapelessRecipes(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 == 2 && 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; } } /** * returns the List<> of all recipes */ public List getRecipeList() { return this.recipes; } }
:::
Le Gui
:::package Crafting; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class TableGui extends GuiContainer { private static final ResourceLocation field_110422_t = new ResourceLocation("textures/gui/container/crafting_table.png"); public TableGui(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5) { super(new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5)); } /** * Draw the foreground layer for the GuiContainer (everything in front of the items) */ protected void drawGuiContainerForegroundLayer(int par1, int par2) { this.fontRenderer.drawString(I18n.func_135053_a("container.crafting"), 28, 6, 4210752); this.fontRenderer.drawString(I18n.func_135053_a("container.inventory"), 8, this.ySize - 96 + 2, 4210752); } /** * Draw the background layer for the GuiContainer (everything behind the items) */ protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.func_110434_K().func_110577_a(field_110422_t); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); } }
:::
Le RecipeSorter
:::package Crafting; import java.util.Comparator; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; class RecipeSorter implements Comparator { final tablecraftingmanager craftingManager; RecipeSorter(tablecraftingmanager par1CraftingManager) { this.craftingManager = par1CraftingManager; } public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe) { return par1IRecipe instanceof ShapelessRecipes && par2IRecipe instanceof ShapedRecipes ? 1 : (par2IRecipe instanceof ShapelessRecipes && par1IRecipe instanceof ShapedRecipes ? -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); } }
:::______
-
C’est sur que si tu reprends les codes de Minecraft sans les modifiés pour ton mod, cela ne fonctionneras pas, regarde le tuto sur les gui et les containers de robin4002.
-
Cela ma plus mélanger que d’autre chose. Plus que je voudrais savoir c’est pourquoi le Gui ne s’ouvre pas.
-
Car ce code :
par5EntityPlayer.displayGUIWorkbench(par2, par3, par4);
Sert à ouvrir le gui de la workbench de minecraft. -
Alors, si je change cela par ce que tu a mis dans la class de ton bloc cela devrais marcher ou j’ai d’autre chose a faire?