MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Synchronisation de données

    Planifier Épinglé Verrouillé Déplacé Non résolu Sans suite
    1.7.10
    2 Messages 2 Publieurs 313 Vues 2 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • Q Hors-ligne
      Quinella
      dernière édition par

      Bonsoir, j’ai, suite à vos recommandations, utilisé les Extended Entity Properties pour sauvegarder des données sur les joueurs. (En question, ce sont des niveaux pour un métier). Mon problème est que j’ai essayé de créer un overlay qui afficherait la barre d’xp en fonction du niveau.
      C’est assez bizarre, parce que normalement, j’utilise un item pour me faire “up” l’xp, sauf que là, j’ai l’impression que ma fonction d’events ne prend pas en compte les niveaux que j’obtiens avec mon item.

      Je souhaiterais que ma barre d’overlay soit synchronisée avec l’xp du joueur.

      Voici la classe de l’Extended Entity Properties (fonctionnelle) :

      package ch.dentax.saoaddon.skills;
      
      import net.minecraft.entity.Entity;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.world.World;
      import net.minecraftforge.common.IExtendedEntityProperties;
      
      public class CookerEntityProperties implements IExtendedEntityProperties {
      
          public final static String EXT_PROP_COOK = "CookerExtendedPlayer";
      
          int [] xpMaxByLvl = {20, 50, 100, 175, 300, 450, 600, 800, 1100, 1300, 1600, 2000, 2500, 3100, 3800, 4800, 6000, 7200, 9200, 10500};
          int level;
      
          private final EntityPlayer propPlayer;
      
          private int currentXp;
      
          public CookerEntityProperties(EntityPlayer player) {
      
              this.propPlayer = player;
      
              this.currentXp = 0;
      
              this.level = 0;
      
              this.xpMaxByLvl[level] = 100;
      
          }
      
          public static final void register(EntityPlayer player) {
      
              player.registerExtendedProperties(CookerEntityProperties.EXT_PROP_COOK, new CookerEntityProperties(player));
      
          }
      
          public static final CookerEntityProperties get(EntityPlayer player) {
      
              return (CookerEntityProperties) player.getExtendedProperties(EXT_PROP_COOK);
      
          }
      
          @Override
          public void saveNBTData(NBTTagCompound compound) {
      
              NBTTagCompound properties = new NBTTagCompound();
      
              properties.setInteger("CurrentXp", this.currentXp);
              properties.setInteger("XpMax", this.xpMaxByLvl[this.level]);
              properties.setInteger("Level", this.level);
      
              compound.setTag(EXT_PROP_COOK, properties);
      
          }
      
          @Override
          public void loadNBTData(NBTTagCompound compound) {
              NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_COOK);
              this.currentXp = properties.getInteger("CurrentXp");
              this.level = properties.getInteger("Level");
              this.xpMaxByLvl[this.level] = properties.getInteger("XpMax");
              System.out.println("[Cooker] Xp : " + this.currentXp + "/" + this.xpMaxByLvl[this.level] + " and level :" + this.level);
          }
      
          @Override
          public void init(Entity entity, World world) {
      
          }
      
          public boolean consumeXp(int amount) {
              boolean sufficient = amount <= this.currentXp;
      
              this.currentXp -= (amount < this.currentXp ? amount : this.currentXp);
              System.out.println("[Cooker] Xp : " + this.currentXp + "/" + this.xpMaxByLvl[this.level] + " and level :" + this.level);
              return sufficient;
          }
      
          public void replenishXp() {
              System.out.println("[Cooker] Xp : " + this.currentXp + "/" + this.xpMaxByLvl[this.level] + " and level :" + this.level);
              this.currentXp = this.xpMaxByLvl[this.level];
          }
      
          public int getCurrentXp() {
      
              return this.currentXp;
      
          }
      
          public boolean addXp(int amount) {
      
              //boolean sufficient = this.currentXp + amount < this.xpMaxByLvl[this.level];
      
      
              if(this.currentXp < this.xpMaxByLvl[this.level]){
      
                  this.currentXp += amount;
      
              }
              else if (this.currentXp + amount == this.xpMaxByLvl[this.level]){
      
                  level++;
                  currentXp = 0;
      
              }
              else{
                  this.currentXp += amount;
      
                  while (this.currentXp    > this.xpMaxByLvl[this.level]){
                          this.currentXp -= this.xpMaxByLvl[this.level];
                          this.level++;
                  }
              }
      
              System.out.println("[Cooker ADD] Xp : " + this.currentXp + "/" + this.xpMaxByLvl[this.level] + " and level :" + this.level + " " + this.xpMaxByLvl[this.level]);
      
              return true;
          }
      
      
          public int getLevel(){
      
              return this.level;
      
          }
      
          public int getMaxXpByLevel(int level){
      
              return xpMaxByLvl[level];
      
          }
      }
      
      

      Voici la fonction de mon item :

      @Override
      	public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
          	{
      		if (!world.isRemote)
      		{
      			CookerEntityProperties props = CookerEntityProperties.get(player);
      			if(player.isSneaking()){
      
      				if(props.addXp(10)){
      					System.out.println("[Xp Item] L'expérience du joueur a été incrémentée de 10 points");
      
      					player.addChatComponentMessage(new ChatComponentText("Niveau : " + props.getLevel() + " et expérience  : " + props.getCurrentXp() + "/" + props.getMaxXpByLevel(props.getLevel())));
      
      				}
      
      			}
      			else {
      
      				if (props.consumeXp(15)) {
      					player.addChatComponentMessage(new ChatComponentText("Niveau : " + props.getLevel() + " et expérience  : " + props.getCurrentXp() + "/" + props.getMaxXpByLevel(props.getLevel())));
      				} else {
      					player.addChatComponentMessage(new ChatComponentText("Xp trop faible"));
      				}
      			}
      		}
      		
              return itemstack;
          }
      

      Et finalement, voici la fonction de mon overlay :

      public class GuiSkills extends Gui {
      
          public GuiSkills(Minecraft mc) {
      
              this.mc = mc;
      
          }
      
      
          private Minecraft mc;
      
          private static final ResourceLocation texturepath = new ResourceLocation("forge","saoaddon:textures/gui/forge_xp_empty.png");
      
          @SubscribeEvent(priority = EventPriority.NORMAL)
          public void onRenderExperienceBar(RenderGameOverlayEvent event){
      
              if (event.isCancelable() || event.type != ElementType.EXPERIENCE)
              {
                  return;
              }
      
      
      
      
              CookerEntityProperties props = CookerEntityProperties.get(this.mc.thePlayer);
      
              if (props == null || props.getMaxXpByLevel(props.getLevel()) == 0 ){
      
                  return;
      
              }
      
              int xPos = event.resolution.getScaledWidth() - 70;
              int yPos = 10 ;
      
              GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
      
              GL11.glDisable(GL11.GL_LIGHTING);
      
              this.mc.getTextureManager().bindTexture(texturepath);
      
              this.drawTexturedModalRect(xPos, yPos, 0, 0, 64, 32);
      
              int xpBarWidth = (int)(((float) props.getCurrentXp() / props.getMaxXpByLevel(props.getLevel())) * 25);
              System.out.println("[GUI XP] Current xp bar width: " + xpBarWidth);
      
              this.drawTexturedModalRect(xPos, yPos, 0, 63, xpBarWidth, 2);
      
              mc.ingameGUI.drawString(mc.fontRenderer, String.valueOf(props.getLevel()) , xPos + 60, yPos + 8, 0x494949);
      
          }
      }
      

      Sinon, il ne devriait pas y avoir de problèmes dans l’enregistrement des classes dans ma classe principales puisqu’elles sont toutes effectuées.

      Voilà, je sais que c’est beaucoup demandé, mais je remercie d’avance les personnes qui tenteront de m’aider.

      Merci beaucoup,
      Sincères salutations,

      1 réponse Dernière réponse Répondre Citer 0
      • robin4002R Hors-ligne
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs
        dernière édition par

        Salut,
        Il faut utiliser des paquets pour synchroniser les valeurs.
        Dès que l’xp est modifié (donc dans les fonctions addXp et consumeXp un paquet doit être envoyé vers le client pour qu’il mette à jour la valeur en question).

        1 réponse Dernière réponse Répondre Citer 0
        • 1 / 1
        • Premier message
          Dernier message
        Design by Woryk
        ContactMentions Légales

        MINECRAFT FORGE FRANCE © 2024

        Powered by NodeBB