Résolu GUI d'une enclume + questions sur dimensions
-
Salut à tous,
ayant quelques soucis avec des items irréparable je me suis lancée dans l’idée de faire une enclume qui permettra de réparer sans limite et qui aura une réduction des prix de réparation de 50%
Ayant un peu de mal avec les GUI je me suis inspiré du GUI de l’anvil, donc maintenant j’ai bien mon enclume et quand je clique droit dessus le GUI s’ouvre puis se ferme juste après.
Je vous mets tout les codes en lien avec l’enclume:
package Gallad.Mineald.block; import java.util.List; import Gallad.Mineald.Import; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockAnvil; import net.minecraft.block.BlockSand; import net.minecraft.block.StepSound; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityFallingSand; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class Rubanvil extends BlockAnvil { /** List of types/statues the Anvil can be in. */ public static final String[] statuses = new String[] {"intact", "slightlyDamaged", "veryDamaged"}; private static final String[] anvilIconNames = new String[] {"Rubanvil_top_damaged_0", "Rubanvil_top_damaged_1", "Rubanvil_top_damaged_2"}; @SideOnly(Side.CLIENT) public int field_82521_b; @SideOnly(Side.CLIENT) private Icon[] iconArray; public Rubanvil(int ID, float Hardness, float resistance, float lightlevel, int lightopacity, Material material,String name, StepSound sound) { super(ID); this.setHardness(Hardness); this.setResistance(resistance); this.setLightValue(lightlevel); this.setLightOpacity(lightopacity); this.setUnlocalizedName(name); this.setStepSound(sound); } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } /** * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. */ public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) /** * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata */ public Icon getIcon(int par1, int par2) { if (this.field_82521_b == 3 && par1 == 1) { int k = (par2 >> 2) % this.iconArray.length; return this.iconArray[k]; } else { return this.blockIcon; } } @SideOnly(Side.CLIENT) /** * When this method is called, your block should register all the icons it needs with the given IconRegister. This * is the only chance you get to register icons. */ public void registerIcons(IconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon("anvil_base"); this.iconArray = new Icon[anvilIconNames.length]; for (int i = 0; i < this.iconArray.length; ++i) { this.iconArray* = par1IconRegister.registerIcon(anvilIconNames*); } } /** * Called when the block is placed in the world. */ public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; int i1 = par1World.getBlockMetadata(par2, par3, par4) >> 2; ++l; l %= 4; if (l == 0) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 2 | i1 << 2, 2); } if (l == 1) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 3 | i1 << 2, 2); } if (l == 2) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 0 | i1 << 2, 2); } if (l == 3) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 1 | i1 << 2, 2); } } /** * 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.openGui(Import.instance, 2, par1World, par2, par3, par4); return true; } } /** * The type of render function that is called for this block */ public int getRenderType() { return 35; } /** * Determines the damage on the item the block drops. Used in cloth and wood. */ public int damageDropped(int par1) { return par1 >> 2; } /** * Updates the blocks bounds based on its current state. Args: world, x, y, z */ public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 3; if (l != 3 && l != 1) { this.setBlockBounds(0.125F, 0.0F, 0.0F, 0.875F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.125F, 1.0F, 1.0F, 0.875F); } } @SideOnly(Side.CLIENT) /** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) { par3List.add(new ItemStack(par1, 1, 0)); par3List.add(new ItemStack(par1, 1, 1)); par3List.add(new ItemStack(par1, 1, 2)); } /** * Called when the falling block entity for this block is created */ protected void onStartFalling(EntityFallingSand par1EntityFallingSand) { par1EntityFallingSand.setIsAnvil(true); } /** * Called when the falling block entity for this block hits the ground and turns back into a block */ public void onFinishFalling(World par1World, int par2, int par3, int par4, int par5) { par1World.playAuxSFX(1022, par2, par3, par4, 0); } @SideOnly(Side.CLIENT) /** * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given * coordinates. Args: blockAccess, x, y, z, side */ public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { return true; } }
package Gallad.Mineald.gui; import java.util.List; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import Gallad.Mineald.container.ContainerRubanvil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerRepair; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class GuiRubanvil extends GuiContainer implements ICrafting { private static final ResourceLocation anvilGuiTextures = new ResourceLocation("textures/gui/container/anvil.png"); private ContainerRubanvil repairContainer; private GuiTextField itemNameField; private InventoryPlayer field_82325_q; public GuiRubanvil(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5) { super(new ContainerRubanvil(par1InventoryPlayer, par2World, par3, par4, par5, Minecraft.getMinecraft().thePlayer)); this.field_82325_q = par1InventoryPlayer; this.repairContainer = (ContainerRubanvil)this.inventorySlots; } /** * Adds the buttons (and other controls) to the screen in question. */ public void initGui() { super.initGui(); Keyboard.enableRepeatEvents(true); int i = (this.width - this.xSize) / 2; int j = (this.height - this.ySize) / 2; this.itemNameField = new GuiTextField(this.fontRenderer, i + 62, j + 24, 103, 12); this.itemNameField.setTextColor(-1); this.itemNameField.setDisabledTextColour(-1); this.itemNameField.setEnableBackgroundDrawing(false); this.itemNameField.setMaxStringLength(40); this.inventorySlots.removeCraftingFromCrafters(this); this.inventorySlots.addCraftingToCrafters(this); } /** * Called when the screen is unloaded. Used to disable keyboard repeat events */ public void onGuiClosed() { super.onGuiClosed(); Keyboard.enableRepeatEvents(false); this.inventorySlots.removeCraftingFromCrafters(this); } /** * Draw the foreground layer for the GuiContainer (everything in front of the items) */ protected void drawGuiContainerForegroundLayer(int par1, int par2) { GL11.glDisable(GL11.GL_LIGHTING); this.fontRenderer.drawString(I18n.getString("container.repair"), 60, 6, 4210752); if (this.repairContainer.maximumCost > 0) { int k = 8453920; boolean flag = true; String s = I18n.getStringParams("container.repair.cost", new Object[] {Integer.valueOf(this.repairContainer.maximumCost)}); if (!this.repairContainer.getSlot(2).getHasStack()) { flag = false; } else if (!this.repairContainer.getSlot(2).canTakeStack(this.field_82325_q.player)) { k = 16736352; } if (flag) { int l = -16777216 | (k & 16579836) >> 2 | k & -16777216; int i1 = this.xSize - 8 - this.fontRenderer.getStringWidth(s); byte b0 = 67; if (this.fontRenderer.getUnicodeFlag()) { drawRect(i1 - 3, b0 - 2, this.xSize - 7, b0 + 10, -16777216); drawRect(i1 - 2, b0 - 1, this.xSize - 8, b0 + 9, -12895429); } else { this.fontRenderer.drawString(s, i1, b0 + 1, l); this.fontRenderer.drawString(s, i1 + 1, b0, l); this.fontRenderer.drawString(s, i1 + 1, b0 + 1, l); } this.fontRenderer.drawString(s, i1, b0, k); } } GL11.glEnable(GL11.GL_LIGHTING); } /** * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). */ protected void keyTyped(char par1, int par2) { if (this.itemNameField.textboxKeyTyped(par1, par2)) { this.func_135015_g(); } else { super.keyTyped(par1, par2); } } private void func_135015_g() { String s = this.itemNameField.getText(); Slot slot = this.repairContainer.getSlot(0); if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName())) { s = ""; } this.repairContainer.updateItemName(s); this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", s.getBytes())); } /** * Called when the mouse is clicked. */ protected void mouseClicked(int par1, int par2, int par3) { super.mouseClicked(par1, par2, par3); this.itemNameField.mouseClicked(par1, par2, par3); } /** * Draws the screen and all the components in it. */ public void drawScreen(int par1, int par2, float par3) { super.drawScreen(par1, par2, par3); GL11.glDisable(GL11.GL_LIGHTING); this.itemNameField.drawTextBox(); } /** * 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.getTextureManager().bindTexture(anvilGuiTextures); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); this.drawTexturedModalRect(k + 59, l + 20, 0, this.ySize + (this.repairContainer.getSlot(0).getHasStack() ? 0 : 16), 110, 16); if ((this.repairContainer.getSlot(0).getHasStack() || this.repairContainer.getSlot(1).getHasStack()) && !this.repairContainer.getSlot(2).getHasStack()) { this.drawTexturedModalRect(k + 99, l + 45, this.xSize, 0, 28, 21); } } public void sendContainerAndContentsToPlayer(Container par1Container, List par2List) { this.sendSlotContents(par1Container, 0, par1Container.getSlot(0).getStack()); } /** * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual * contents of that slot. Args: Container, slot number, slot contents */ public void sendSlotContents(Container par1Container, int par2, ItemStack par3ItemStack) { if (par2 == 0) { this.itemNameField.setText(par3ItemStack == null ? "" : par3ItemStack.getDisplayName()); this.itemNameField.setEnabled(par3ItemStack != null); if (par3ItemStack != null) { this.func_135015_g(); } } } /** * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress, * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new * value. Both are truncated to shorts in non-local SMP. */ public void sendProgressBarUpdate(Container par1Container, int par2, int par3) {} }
package Gallad.Mineald.container; import java.util.Iterator; import java.util.Map; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemEnchantedBook; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import org.apache.commons.lang3.StringUtils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ContainerRubanvil extends Container { /** Here comes out item you merged and/or renamed. */ private IInventory outputSlot = new InventoryCraftResult(); /** * The 2slots where you put your items in that you want to merge and/or rename. */ private IInventory inputSlots = new ContainerRepairINNER1(this, "Repair", true, 2); private World theWorld; private int field_82861_i; private int field_82858_j; private int field_82859_k; /** The maximum cost of repairing/renaming in the anvil. */ public int maximumCost; /** determined by damage of input item and stackSize of repair materials */ private int stackSizeToBeUsedInRepair; private String repairedItemName; /** The player that has this container open. */ private final EntityPlayer thePlayer; public ContainerRubanvil(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) { this.theWorld = par2World; this.field_82861_i = par3; this.field_82858_j = par4; this.field_82859_k = par5; this.thePlayer = par6EntityPlayer; this.addSlotToContainer(new Slot(this.inputSlots, 0, 27, 47)); this.addSlotToContainer(new Slot(this.inputSlots, 1, 76, 47)); this.addSlotToContainer(new ContainerRubanvilINNER2(this, this.outputSlot, 2, 134, 47, par2World, par3, par4, par5)); int l; for (l = 0; l < 3; ++l) { for (int 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)); } } /** * Callback for when the crafting matrix is changed. */ public void onCraftMatrixChanged(IInventory par1IInventory) { super.onCraftMatrixChanged(par1IInventory); if (par1IInventory == this.inputSlots) { this.updateRepairOutput(); } } /** * called when the Anvil Input Slot changes, calculates the new result and puts it in the output slot */ public void updateRepairOutput() { ItemStack itemstack = this.inputSlots.getStackInSlot(0); this.maximumCost = 0; int i = 0; byte b0 = 0; int j = 0; if (itemstack == null) { this.outputSlot.setInventorySlotContents(0, (ItemStack)null); this.maximumCost = 0; } else { ItemStack itemstack1 = itemstack.copy(); ItemStack itemstack2 = this.inputSlots.getStackInSlot(1); Map map = EnchantmentHelper.getEnchantments(itemstack1); boolean flag = false; int k = b0 + itemstack.getRepairCost() + (itemstack2 == null ? 0 : itemstack2.getRepairCost()); this.stackSizeToBeUsedInRepair = 0; int l; int i1; int j1; int k1; int l1; Iterator iterator; Enchantment enchantment; if (itemstack2 != null) { flag = itemstack2.itemID == Item.enchantedBook.itemID && Item.enchantedBook.func_92110_g(itemstack2).tagCount() > 0; if (itemstack1.isItemStackDamageable() && Item.itemsList[itemstack1.itemID].getIsRepairable(itemstack, itemstack2)) { l = Math.min(itemstack1.getItemDamageForDisplay(), itemstack1.getMaxDamage() / 4); if (l <= 0) { this.outputSlot.setInventorySlotContents(0, (ItemStack)null); this.maximumCost = 0; return; } for (i1 = 0; l > 0 && i1 < itemstack2.stackSize; ++i1) { j1 = itemstack1.getItemDamageForDisplay() - l; itemstack1.setItemDamage(j1); i += Math.max(1, l / 100) + map.size(); l = Math.min(itemstack1.getItemDamageForDisplay(), itemstack1.getMaxDamage() / 4); } this.stackSizeToBeUsedInRepair = i1; } else { if (!flag && (itemstack1.itemID != itemstack2.itemID || !itemstack1.isItemStackDamageable())) { this.outputSlot.setInventorySlotContents(0, (ItemStack)null); this.maximumCost = 0; return; } if (itemstack1.isItemStackDamageable() && !flag) { l = itemstack.getMaxDamage() - itemstack.getItemDamageForDisplay(); i1 = itemstack2.getMaxDamage() - itemstack2.getItemDamageForDisplay(); j1 = i1 + itemstack1.getMaxDamage() * 12 / 100; int i2 = l + j1; k1 = itemstack1.getMaxDamage() - i2; if (k1 < 0) { k1 = 0; } if (k1 < itemstack1.getItemDamage()) { itemstack1.setItemDamage(k1); i += Math.max(1, j1 / 100); } } Map map1 = EnchantmentHelper.getEnchantments(itemstack2); iterator = map1.keySet().iterator(); while (iterator.hasNext()) { j1 = ((Integer)iterator.next()).intValue(); enchantment = Enchantment.enchantmentsList[j1]; k1 = map.containsKey(Integer.valueOf(j1)) ? ((Integer)map.get(Integer.valueOf(j1))).intValue() : 0; l1 = ((Integer)map1.get(Integer.valueOf(j1))).intValue(); int j2; if (k1 == l1) { ++l1; j2 = l1; } else { j2 = Math.max(l1, k1); } l1 = j2; int k2 = l1 - k1; boolean flag1 = enchantment.canApply(itemstack); if (this.thePlayer.capabilities.isCreativeMode || itemstack.itemID == ItemEnchantedBook.enchantedBook.itemID) { flag1 = true; } Iterator iterator1 = map.keySet().iterator(); while (iterator1.hasNext()) { int l2 = ((Integer)iterator1.next()).intValue(); if (l2 != j1 && !enchantment.canApplyTogether(Enchantment.enchantmentsList[l2])) { flag1 = false; i += k2; } } if (flag1) { if (l1 > enchantment.getMaxLevel()) { l1 = enchantment.getMaxLevel(); } map.put(Integer.valueOf(j1), Integer.valueOf(l1)); int i3 = 0; switch (enchantment.getWeight()) { case 1: i3 = 8; break; case 2: i3 = 4; case 3: case 4: case 6: case 7: case 8: case 9: default: break; case 5: i3 = 2; break; case 10: i3 = 1; } if (flag) { i3 = Math.max(1, i3 / 2); } i += i3 * k2; } } } } if (StringUtils.isBlank(this.repairedItemName)) { if (itemstack.hasDisplayName()) { j = itemstack.isItemStackDamageable() ? 7 : itemstack.stackSize * 5; i += j; itemstack1.func_135074_t(); } } else if (!this.repairedItemName.equals(itemstack.getDisplayName())) { j = itemstack.isItemStackDamageable() ? 7 : itemstack.stackSize * 5; i += j; if (itemstack.hasDisplayName()) { k += j / 2; } itemstack1.setItemName(this.repairedItemName); } l = 0; for (iterator = map.keySet().iterator(); iterator.hasNext(); k += l + k1 * l1) { j1 = ((Integer)iterator.next()).intValue(); enchantment = Enchantment.enchantmentsList[j1]; k1 = ((Integer)map.get(Integer.valueOf(j1))).intValue(); l1 = 0; ++l; switch (enchantment.getWeight()) { case 1: l1 = 8; break; case 2: l1 = 4; case 3: case 4: case 6: case 7: case 8: case 9: default: break; case 5: l1 = 2; break; case 10: l1 = 1; } if (flag) { l1 = Math.max(1, l1 / 2); } } if (flag) { k = Math.max(1, k / 2); } if (flag && itemstack1!=null && !Item.itemsList[itemstack1.itemID].isBookEnchantable(itemstack1,itemstack2)) { itemstack1 = null; } this.maximumCost = k + i; if (i <= 0) { itemstack1 = null; } if (itemstack1 != null) { i1 = itemstack1.getRepairCost(); if (itemstack2 != null && i1 < itemstack2.getRepairCost()) { i1 = itemstack2.getRepairCost(); } if (itemstack1.hasDisplayName()) { i1 -= 9; } if (i1 < 0) { i1 = 0; } i1 += 2; itemstack1.setRepairCost(i1); EnchantmentHelper.setEnchantments(map, itemstack1); } this.outputSlot.setInventorySlotContents(0, itemstack1); this.detectAndSendChanges(); } } public void addCraftingToCrafters(ICrafting par1ICrafting) { super.addCraftingToCrafters(par1ICrafting); par1ICrafting.sendProgressBarUpdate(this, 0, this.maximumCost); } @SideOnly(Side.CLIENT) public void updateProgressBar(int par1, int par2) { if (par1 == 0) { this.maximumCost = par2; } } /** * Called when the container is closed. */ public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); if (!this.theWorld.isRemote) { for (int i = 0; i < this.inputSlots.getSizeInventory(); ++i) { ItemStack itemstack = this.inputSlots.getStackInSlotOnClosing(i); if (itemstack != null) { par1EntityPlayer.dropPlayerItem(itemstack); } } } } public boolean canInteractWith(EntityPlayer par1EntityPlayer) { return this.theWorld.getBlockId(this.field_82861_i, this.field_82858_j, this.field_82859_k) != Block.anvil.blockID ? false : par1EntityPlayer.getDistanceSq((double)this.field_82861_i + 0.5D, (double)this.field_82858_j + 0.5D, (double)this.field_82859_k + 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 == 2) { if (!this.mergeItemStack(itemstack1, 3, 39, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (par2 != 0 && par2 != 1) { if (par2 >= 3 && par2 < 39 && !this.mergeItemStack(itemstack1, 0, 2, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 3, 39, 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; } /** * used by the Anvil GUI to update the Item Name being typed by the player */ public void updateItemName(String par1Str) { this.repairedItemName = par1Str; if (this.getSlot(2).getHasStack()) { ItemStack itemstack = this.getSlot(2).getStack(); if (StringUtils.isBlank(par1Str)) { itemstack.func_135074_t(); } else { itemstack.setItemName(this.repairedItemName); } } this.updateRepairOutput(); } static IInventory getRepairInputInventory(ContainerRubanvil repairContainer) { return repairContainer.getInputSlots(); } private IInventory getInputSlots() { return this.inputSlots; } static int getStackSizeUsedInRepair(ContainerRubanvil par0ContainerRubanvil) { return par0ContainerRubanvil.getStackSizeToBeUsedInRepair(); } private int getStackSizeToBeUsedInRepair() { return this.stackSizeToBeUsedInRepair; } }
package Gallad.Mineald.gui; import Gallad.Mineald.container.ContainerPhytriteFurnace; import Gallad.Mineald.container.ContainerRubanvil; import Gallad.Mineald.tile.TileEntityPhytriteFurnace; import net.minecraft.block.Block; 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 1: return new ContainerPhytriteFurnace(player.inventory, (TileEntityPhytriteFurnace)tile_entity); case 2: return new ContainerRubanvil(player.inventory, world, x, y, z, player); } 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 1: return new GuiPhytriteFurnace(player.inventory, (TileEntityPhytriteFurnace)tile_entity); case 2: return new GuiRubanvil(player.inventory, world, x, y, z); } return null; } }
J’ai essayé de comprendre un minimum le code, cependant plusieurs parties me perdent, en l’occurence celle ci:
if (this.repairContainer.maximumCost > 0) { int k = 8453920; boolean flag = true; String s = I18n.getStringParams("container.repair.cost", new Object[] {Integer.valueOf(this.repairContainer.maximumCost)}); if (!this.repairContainer.getSlot(2).getHasStack()) { flag = false; } else if (!this.repairContainer.getSlot(2).canTakeStack(this.field_82325_q.player)) { k = 16736352; } if (flag) { int l = -16777216 | (k & 16579836) >> 2 | k & -16777216; int i1 = this.xSize - 8 - this.fontRenderer.getStringWidth(s); byte b0 = 67; if (this.fontRenderer.getUnicodeFlag()) { drawRect(i1 - 3, b0 - 2, this.xSize - 7, b0 + 10, -16777216); drawRect(i1 - 2, b0 - 1, this.xSize - 8, b0 + 9, -12895429); } else { this.fontRenderer.drawString(s, i1, b0 + 1, l); this.fontRenderer.drawString(s, i1 + 1, b0, l); this.fontRenderer.drawString(s, i1 + 1, b0 + 1, l); } this.fontRenderer.drawString(s, i1, b0, k); } }
Pourquoi un tel nombre pour k?
#Deuxième question(Deuxième question)
J’avais précédemment évoqué un bug entre ma nouvelle dimension et mon world sur serveur avec essentials
d’après ce que robin m’a dit ils n’ont pas ce bug avec leur mod, j’en déduis donc que le soucis vient de mon code, quelqu’un saurait il quel élément est la cause de ce soucis, en essayant quelques commandes sur mon serveur je me suis rendu compte que quand je faisais la commande /mw goto DIM2 soit la commande pour aller dans ma dimension, la réponse du serveur était qu’il m’avait tp dans le world world. J’en conclut donc que ma dimension est mal reconnue, peut être une piste?Edit: RESOLU par xavpok, merci à lui pour avoir vus cette erreur toute bête que j’avais faite
-
Utilise FMLNetworkHandler.openGui(…) pour ouvrir les Gui plutôt que player.openGui.
k -> Couleur du texte -
ça changement quoi concrètement?
même soucismerci pour la couleur
-
xavpok, c’est la même chose.
-
après quelques recherche, j’ai restreint mon champ de recherche:
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.openGui(Import.instance, 2, par1World, par2, par3, par4); return true; } }
Avec ce code, le GUI ne s’ouvre pas du tout
par contre si j’utilise celui ci:public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { FMLNetworkHandler.openGui(par5EntityPlayer, Import.instance, 2, par1World, par2, par3, par4); return true; }
Il s’ouvre puis se referme juste après
si par contre avec eclispe je mets un breakpoint sur le return, eclispe coupe 2 fois, puis ouvre le GUI sans le refermer.
quelqu’un aurait il une idéeµ? le reste du code est toujours le même. -
Personnellement, je fais comme ceci ```java
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if(world.isRemote)
{
return true;
}
else
{
TileEntityCompressor compressor = (TileEntityCompressor) world.getTileEntity(x, y, z);if(compressor != null)
{
player.openGui(Wolf_Addons.instance, 0, world, x, y, z);
}
return true;
}
}Et cela fonctionne parfaitement.
-
En modifiant mon code selon ton modèle, j’obtiens cela:
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { if(world.isRemote) { return true; } else { int block = world.getBlockId(x, y, z); if(block == Import.Rubanvil.blockID) { FMLNetworkHandler.openGui(player, Import.instance, 2, world, x, y, z); } return true; } }
je pense que le soucis vient de: if(world.isRemote) mais je ne comprends pas en quoi.
-
non pas sur l’enclume, c’est ce que je trouve byzarre aussi
-
Oups, désolé, j’ai supprimé mon post. Mais l’enclume vanilla a bien une tileEntity?
-
non justement, j’ai simplement copié celle vanilla et c’est ce qui m’a paru byzarre
-
world.isRemote = world client
!world.isRemote = world server.
Cette méthode est fait en client et serveur, normalement le open gui doit être fait côté serveur, donc ça m’a l’air bon.
Je pense que le problème vient plutôt du gui handler. Il est bien enregistré ?
Limite, remplace :if(block == Import.Rubanvil.blockID) { FMLNetworkHandler.openGui(player, Import.instance, 2, world, x, y, z); System.out.println("ouverture du gui"); }
Et dans ton gui handler, dans la condition pour ton gui, met aussi un println, puis regarde lequel ne s’affiche pas.
-
EN fait j’ai testé en remplaçant simplement world.isremote par !world.isRemote
et la le GUI s’ouvre sans se refermer, il est cependant complétement bugué.Je récapitule: Si je ne mets pas de condition et que je lui dis clairement d’ouvrir le GUI, il me l’ouvre puis le referme sauf si je mets un breakpoint sur le return.
Si je mets if (!world.isRemote) le GUI s’ouvre mais côté client donc inutilisable
mon code est éxactement le même que celui de l’enclume normale
qu’ai je biens pus oublier?Autre remarque: j’ai mis deux println, un dans l’ouverture du GUI, l’autre dans le Handler
or à chaque fois que je fais un clic sur mon enclume, chaque message apparait en double
quand je mets une condition isremote aussi, peu importe le sens que je mette world ou !world, il me l’affiche 4 fois.