• Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved Affichage gui

    1.12.x
    1.12.2
    3
    4
    139
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ciolgaming
      Ciolgaming last edited by

      Bonsoir,

      je suis en train de me remettre aux TileEntity avec Container en 1.12.2 et j’ai juste une petite question, comment récupérer la valeur de ma variable lavaquantity dans mon gui afin d’afficher la quantité de fuel sous forme graphique

      Petite image de ce que j’ai fait :
      text alternatif

      Merci de bien vouloir m’orienter dans la bonne direction, voici mon code :

      Code du Gui

      package fr.ciolgaming.magistry.gui;
      
      import fr.ciolgaming.magistry.blocks.container.ContainerAcu;
      import fr.ciolgaming.magistry.blocks.tileentities.TileAcu;
      import net.minecraft.client.gui.inventory.GuiContainer;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.util.ResourceLocation;
      
      public class GuiAcu extends GuiContainer{
      	
      	private static final ResourceLocation background = new ResourceLocation("magistry","textures/gui/gui_acu.png");
      	private TileAcu tile;
      	
      	public GuiAcu(TileAcu tile, InventoryPlayer playerInv) {
              super(new ContainerAcu(tile, playerInv));
              this.tile = tile;
              
      	}
      	@Override
      	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
      	    int i = (this.width - this.xSize) / 2;
      	    int j = (this.height - this.ySize) / 2;
      	    this.drawDefaultBackground();
      	    this.mc.getTextureManager().bindTexture(background);
      	    this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
      	 
      	    int timePassed = this.tile.getField(1);
      	    int textureWidth = (int) (26f / 200f * timePassed);
      	    this.drawTexturedModalRect(i + 102, j + 39, 176, 14, textureWidth, 11);
      	    	 
      	    if (this.tile.isBurning()) {
      	        int burningTime = this.tile.getField(0);
      	        int textureHeight = (int) (14f / this.tile.getFullBurnTime() * burningTime);
      	   //     this.drawTexturedModalRect(i + 18, j + 22, 176, 14 - textureHeight, 29, textureHeight);
      	    }
      	    
      	    int textureH = (int) ((this.tile.getLavaLeft()*8) / 53);
      	    this.drawTexturedModalRect(i + 7, j + 53, 176, 25, 18, textureH);
      	    
      	    this.fontRenderer.drawString("Lave : " + this.tile.getLavaLeft(), i + 3, j + 3, 0xFFFFFF);
      	}
      }
      

      Code de la TileEntity :

      package fr.ciolgaming.magistry.blocks.tileentities;
      
      import fr.ciolgaming.magistry.blocks.recipes.RecipesAcu;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.init.Items;
      import net.minecraft.inventory.Container;
      import net.minecraft.inventory.ItemStackHelper;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.tileentity.TileEntityLockable;
      import net.minecraft.util.ITickable;
      import net.minecraft.util.NonNullList;
      import net.minecraftforge.oredict.OreDictionary;
      
      public class TileAcu extends TileEntityLockable implements ITickable{
      	
      	private NonNullList<ItemStack> stacks = NonNullList.withSize(5, ItemStack.EMPTY);
      	private String customName;
      	private int	timePassed = 0;
      	private int	burningTimeLeft	= 0;
      	private int	lavaquantity = 1;
      	
      	@Override
      	public void readFromNBT(NBTTagCompound compound) {
      	    super.readFromNBT(compound);
      	    this.stacks = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
      	    ItemStackHelper.loadAllItems(compound, this.stacks);
      	 
      	    if (compound.hasKey("CustomName", 8)) {
      	        this.customName = compound.getString("CustomName");
      	    }
      	    this.burningTimeLeft = compound.getInteger("burningTimeLeft");
      	    
      	    this.lavaquantity = compound.getInteger("lavaquantity");
      	    
      	    this.timePassed = compound.getInteger("timePassed");
      	}
      	 
      	@Override
      	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
      	    super.writeToNBT(compound);
      	    ItemStackHelper.saveAllItems(compound, this.stacks);
      	 
      	    if (this.hasCustomName()) {
      	        compound.setString("CustomName", this.customName);
      	    }
      	 
      	    compound.setInteger("burningTimeLeft", this.burningTimeLeft);
      	    compound.setInteger("timePassed", this.timePassed);
      	    compound.setInteger("lavaquantity", this.lavaquantity);
      	 
      	    return compound;
      	}
      	
      	@Override
      	public boolean hasCustomName() {
      	    return this.customName != null && !this.customName.isEmpty();
      	}
      	 
      	@Override
      	public String getName() {
      	    return hasCustomName() ? this.customName : "tile.custom_furnace";
      	}
      	 
      	public void setCustomName(String name) {
      	    this.customName = name;
      	}
      	
      	@Override
      	public int getField(int id) {
      	    switch (id) {
      	        case 0:
      	            return this.burningTimeLeft;
      	        case 1:
      	            return this.timePassed;
      	    }
      	    return 0;
      	}
      	 
      	@Override
      	public void setField(int id, int value) {
      	    switch (id) {
      	        case 0:
      	            this.burningTimeLeft = value;
      	            break;
      	        case 1:
      	            this.timePassed = value;
      	    }
      	}
      	 
      	@Override
      	public int getFieldCount() {
      	    return 2;
      	}
      	
      	@Override
      	public int getSizeInventory() {
      	    return this.stacks.size();
      	}
      	 
      	@Override
      	public ItemStack getStackInSlot(int index) {
      	    return this.stacks.get(index);
      	}
      	 
      	@Override
      	public ItemStack decrStackSize(int index, int count) {
      	    return ItemStackHelper.getAndSplit(this.stacks, index, count);
      	}
      	 
      	@Override
      	public ItemStack removeStackFromSlot(int index) {
      	    return ItemStackHelper.getAndRemove(stacks, index);
      	}
      	 
      	@Override
      	public void setInventorySlotContents(int index, ItemStack stack) {
      	    this.stacks.set(index, stack);
      	 
      	    if (stack.getCount() > this.getInventoryStackLimit()) {
      	        stack.setCount(this.getInventoryStackLimit());
      	    }
      	}
      	 
      	@Override
      	public int getInventoryStackLimit() {
      	    return 64;
      	}
      	 
      	@Override
      	public boolean isEmpty() {
      	    for(ItemStack stack : this.stacks) {
      	        if (!stack.isEmpty()) {
      	            return false;
      	        }
      	    }
      	    return true;
      	}
      	 
      	@Override
      	public void clear() {
      	    for(int i = 0; i < this.stacks.size(); i++) {
      	        this.stacks.set(i, ItemStack.EMPTY);
      	    }
      	}
      	
      	@Override
      	public void openInventory(EntityPlayer player) {}
      	 
      	@Override
      	public void closeInventory(EntityPlayer player) {}
      	
      	@Override
      	public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
      	    return null;
      	}
      	 
      	@Override
      	public String getGuiID() {
      	    return null;
      	}
      	
      	@Override
      	public boolean isItemValidForSlot(int index, ItemStack stack) {
      	    // Le slot 3 je n'autorise que les planches de bois
      	    if (index == 2)
      	    	return stack.getItem() == Items.COAL;
      	    // Le slot 4 je n'autorise que le blé
      	    // Le slot 5 (celui du résultat) je n'autorise rien
      	    if (index == 4)
      	        return false;
      	    // Sinon pour les slots 1 et 2 on met ce qu'on veut
      	    return true;
      	}
      	
      	public boolean isUsableByPlayer(EntityPlayer player) {
      	    return this.world.getTileEntity(this.pos) != this ? false : player
      	            .getDistanceSq((double) this.pos.getX() + 0.5D,
      	                    (double) this.pos.getY() + 0.5D,
      	                    (double) this.pos.getZ() + 0.5D) <= 64.0D;
      	}
      	
      	public boolean hasFuelEmpty() {
      	    return this.getStackInSlot(2).isEmpty();
      	}
      	
      	public ItemStack getRecipeResult() {
      	    return RecipesAcu.getRecipeResult(new ItemStack[] {
      	            this.getStackInSlot(0), this.getStackInSlot(1) });
      	}
      	
      	public boolean canSmelt() {
      	    // On récupère le résultat de la recette
      	    ItemStack result = this.getRecipeResult();
      	 
      	    // Le résultat est null si il n'y a pas de recette associée, donc on retourne faux
      	    if (result != null && lavaquantity > 0) {
      	 
      	        // On récupère le contenu du slot de résultat
      	        ItemStack slot4 = this.getStackInSlot(4);
      	 
      	        // Si il est vide on renvoie vrai
      	        if (slot4.isEmpty())
      	            return true;
      	 
      	        // Sinon on vérifie que ce soit le même objet, les même métadata et que la taille finale ne sera pas trop grande
      	        if (slot4.getItem() == result.getItem() && slot4.getItemDamage() == result.getItemDamage()) {
      	            int newStackSize = slot4.getCount() + result.getCount();
      	            if (newStackSize <= this.getInventoryStackLimit() && newStackSize <= slot4.getMaxStackSize()) {
      	                return true;
      	            }
      	        }
      	    }
      	    return false;
      	}
      	
      	public void smelt() {
      	    // Cette fonction n'est appelée que si result != null, c'est pourquoi on ne fait pas de null check
      	    ItemStack result = this.getRecipeResult();
      	    // On enlève un item de chaque ingrédient
      	    this.decrStackSize(0, 1);
      	    this.decrStackSize(1, 1);
      	    lavaquantity--;
      	    // On récupère le slot de résultat
      	    ItemStack stack4 = this.getStackInSlot(4);
      	    // Si il est vide
      	    if (stack4.isEmpty()) {
      	        // On y insère une copie du résultat
      	        this.setInventorySlotContents(4, result.copy());
      	    } else {
      	        // Sinon on augmente le nombre d'objets de l'ItemStack
      	        stack4.setCount(stack4.getCount() + result.getCount());
      	    }
      	}
      	
      	/** Temps de cuisson de la recette */
      	public int getFullRecipeTime() {
      	    return 200;
      	}
      	 
      	/** Temps que dure 1 unité de carburant (ici : 1 planche + 1 blé) */
      	public int getFullBurnTime() {
      	    return 300;
      	}
      	
      	public int getLavaLeft() {
      	    return lavaquantity;
      	}
      	 
      	/** Renvoie vrai si le feu est allumé */
      	public boolean isBurning() {
      		if(burningTimeLeft >0 && lavaquantity >0) {
      			return true;
      		}
      	    return false;
      	}
      	
      	@Override
      	public void update() {
      	    if (!this.world.isRemote) {
      	 
      	        /* Si le carburant brûle, on réduit réduit le temps restant */
      	        if (this.isBurning()) {
      	            this.burningTimeLeft--;
      	        }
      	 
      	        if(!this.getStackInSlot(3).isEmpty()) {
      	        	this.decrStackSize(3, 1);
      	        	lavaquantity = lavaquantity+5;
      	        }
      	        /*
      	            * Si la on peut faire cuire la recette et que le four ne cuit pas
      	            * alors qu'il peut, alors on le met en route
      	            */
      	        if (!this.isBurning() && this.canSmelt() && !this.hasFuelEmpty()) {
      	            this.burningTimeLeft = this.getFullBurnTime();
      	            this.decrStackSize(2, 1);
      	            
      	        }
      	 
      	        /* Si on peut faire cuire la recette et que le feu cuit */
      	        if (this.isBurning() && this.canSmelt()) {
      	            this.timePassed++;
      	            if (timePassed >= this.getFullRecipeTime()) {
      	                timePassed = 0;
      	                this.smelt();
      	            }
      	        } else {
      	            timePassed = 0;
      	        }
      	        this.markDirty();
      	    }
      	}
      
      }
      
      

      Merci de votre réponse et vous souhaite une agréable journée,

      Ciolgaming

      1 Reply Last reply Reply Quote 0
      • JustAnDev
        JustAnDev last edited by

        @Ciolgaming T’as essayé le

        TileAcu.lavaquantity
        

        ???Moi je sais pas draw des image selon une var mais je te donne une astuce(Mets un getter si il demande de le mettre en static ou si ca te chante tu peut le mettre en static

        s

        1 Reply Last reply Reply Quote 0
        • robin4002
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs last edited by

          Alors sachant que la variable est privé, il faut passer par le getter.
          Et comme la méthode n’est pas static, il faut passer par la variable qui contient l’instance du tile entity (ici tile).

          Merci de ne pas poster de fausse réponse, surtout quand il s’agit d’erreurs concernant la base de Java.

          Donc
          tile.getLavaLeft()

          Et pour le draw en fonction du pourcentage et toujours comme dans les autres versions, juste des math.

          Tu peux la valeur courante divisée par le maximum, et tu multiplies ça par le nombre de pixels totaux de la barre.
          Ensuite tu utilises ça comme valeur y pour la fonction draw.

          1 Reply Last reply Reply Quote 0
          • Ciolgaming
            Ciolgaming last edited by

            Okay, déso merci de la réponse

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Design by Woryk
            Contact / Mentions Légales

            MINECRAFT FORGE FRANCE © 2018

            Powered by NodeBB