MFF

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

    Hitbox en fonction de la direction du bloc

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    24 Messages 3 Publieurs 4.1k Vues 1 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.
    • Benjamin LoisonB Hors-ligne
      Benjamin Loison
      dernière édition par

      Alors je voudrais faire une hitbox qui va sur le demi d’un bloc, bon c’est simple ! Mais ce bloc est directionnel et la hitbox doit donc s’adapter à la direction du bloc comment faire ? 😮
      Voici ma classe :

      ​package fr.altiscraft.altiscraft.common;
      
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.item.ItemStack;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.util.MathHelper;
      import net.minecraft.world.IBlockAccess;
      import net.minecraft.world.World;
      import net.minecraftforge.common.util.ForgeDirection;
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      import fr.altiscraft.altiscraft.proxy.ClientProxy;
      
      public class BlocPoubelle extends Block
      {
      
      protected BlocPoubelle()
      {
      super(Material.ground);
      }
      
      @Override
      public boolean hasTileEntity(int metadata)
      {
      return true;
      }
      
      @Override
      public TileEntity createTileEntity(World world, int metadata)
      {
      return new TileEntityPoubelle();
      }
      
      public boolean isOpaqueCube()
          {
              return false;
          }
      
          public boolean renderAsNormalBlock()
          {
              return false;
          }
      
          @SideOnly(Side.CLIENT)
          public int getRenderType()
          {
              return ClientProxy.tesrRenderId;
          }
          public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
          {
              if(stack.getItemDamage() == 0)
              {
                  TileEntity tile = world.getTileEntity(x, y, z);
                  if(tile instanceof TileEntityPoubelle)
                  {
                      int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
                      ((TileEntityPoubelle)tile).setDirection((byte)direction);
                  }
              }
          }
      
          @Override
          public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis)
          {
              if((axis == ForgeDirection.UP || axis == ForgeDirection.DOWN) && !world.isRemote && world.getBlockMetadata(x, y, z) == 0)
              {
                  TileEntity tile = world.getTileEntity(x, y, z);
                  if(tile instanceof TileEntityPoubelle)
                  {
                      TileEntityPoubelle tilePoubelle = (TileEntityPoubelle)tile;
                      byte direction = tilePoubelle.getDirection();
                      direction++;
                      if(direction > 3)
                      {
                          direction = 0;
                      }
                      tilePoubelle.setDirection(direction);
                      return true;
                  }
              }
              return false;
          }
      
          public ForgeDirection[] getValidRotations(World world, int x, int y, int z)
          {
              return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] {ForgeDirection.UP, ForgeDirection.DOWN} : ForgeDirection.VALID_DIRECTIONS;
          }
      public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y,
      int z) {
      this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
      }
          }
      

      >! Développeur de Altis-Life (Arma III) sur Minecraft !
      >! Site web     : https://lemnoslife.com

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

        Tu fais le setBlockBounds en fonction de la direction.

        1 réponse Dernière réponse Répondre Citer 0
        • Benjamin LoisonB Hors-ligne
          Benjamin Loison
          dernière édition par

          C’est-à-dire ? :S Parce que là je commence à me perde 😞

          >! Développeur de Altis-Life (Arma III) sur Minecraft !
          >! Site web     : https://lemnoslife.com

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

            public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
                   {
            TileEntity tile = world.getTileEntity(x, y, z);
            if(tile instanceof TileEntityPoubelle)
            {
            int direction = ((TileEntityPoubelle)tile).getDirection();
            if(direction == 0)
            {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
            // premier cas
            }
            if(direction == 1)
            {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F);
            // deuxième cas
            }
            // etc …
            }
            }
            
            1 réponse Dernière réponse Répondre Citer 0
            • Benjamin LoisonB Hors-ligne
              Benjamin Loison
              dernière édition par

              Et j’aimerais faire aussi avec un bloc quand on clique droit dessus ça le change en un autre bloc comment faire ? :S

              >! Développeur de Altis-Life (Arma III) sur Minecraft !
              >! Site web     : https://lemnoslife.com

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

                Avec la fonction onBlockActivated, tu fais un setBlock

                1 réponse Dernière réponse Répondre Citer 0
                • Benjamin LoisonB Hors-ligne
                  Benjamin Loison
                  dernière édition par

                  et j’aimerais faire que ce ne soit que les gens qui ont un scoreboard de 1 Policier qui puisse l’ouvrir comment faire avec le if == et tout là ? :S

                  >! Développeur de Altis-Life (Arma III) sur Minecraft !
                  >! Site web     : https://lemnoslife.com

                  1 réponse Dernière réponse Répondre Citer 0
                  • SCAREXS Hors-ligne
                    SCAREX
                    dernière édition par

                    Et bien tu trouves par toi même comment récupérer le ScoreBoard, il faut chercher un peu !

                    Site web contenant mes scripts : http://SCAREXgaming.github.io

                    Pas de demandes de support par MP ni par skype SVP.
                    Je n'accepte sur skype que l…

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

                      En passant j’ai changé le titre, avec l’ancien titre 0 % de chance que quelqu’un qui a le même problème tombe sur ce sujet.
                      Il faut mettre un titre qui décrit le problème.

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

                        J’ai supprimé l’autre discussion que tu venais de créer, ça ne sert à rien de créer plusieurs discussions pour un même problème …
                        Tu avais juste à up celle-ci.

                        Ajoutes ceux deux fonctions :

                        @SideOnly(Side.CLIENT)
                        public AxisAlignedBB getSelectedBoundingBox(World world, int x, int y, int z)
                        {
                        this.setBlockBoundsBasedOnState(world, x, y, z);
                        return super.getSelectedBoundingBox(world, x, y, z);
                        }
                        
                        public AxisAlignedBB getCollisionBoundingBox(World world, int x, int y, int z)
                        {
                        this.setBlockBoundsBasedOnState(world, x, y, z);
                        return super.getCollisionBoundingBox(world, x, y, z);
                        }
                        
                        1 réponse Dernière réponse Répondre Citer 0
                        • Benjamin LoisonB Hors-ligne
                          Benjamin Loison
                          dernière édition par

                          Il ne veut pas getSelectedBoundingBox et getCollisionBoundingBox il n’accepte que getCollisionBoundingBoxFromPool et de même pour getSelected :S et ça ne change rien avec ce code…

                          ​package fr.altiscraft.altiscraft.common;
                          
                          import cpw.mods.fml.relauncher.Side;
                          import cpw.mods.fml.relauncher.SideOnly;
                          import fr.altiscraft.altiscraft.proxy.ClientProxy;
                          import net.minecraft.block.Block;
                          import net.minecraft.block.material.Material;
                          import net.minecraft.entity.EntityLivingBase;
                          import net.minecraft.item.ItemStack;
                          import net.minecraft.tileentity.TileEntity;
                          import net.minecraft.util.AxisAlignedBB;
                          import net.minecraft.util.MathHelper;
                          import net.minecraft.world.IBlockAccess;
                          import net.minecraft.world.World;
                          import net.minecraftforge.common.util.ForgeDirection;
                          
                          public class BlocPoubelle extends Block {
                          protected BlocPoubelle() {
                          super(Material.ground);
                          }
                          
                          public boolean hasTileEntity(int metadata) {
                          return true;
                          }
                          
                          public TileEntity createTileEntity(World world, int metadata) {
                          return new TileEntityPoubelle();
                          }
                          
                          public boolean isOpaqueCube() {
                          return false;
                          }
                          
                          public boolean renderAsNormalBlock() {
                          return false;
                          }
                          
                          @SideOnly(Side.CLIENT)
                          public int getRenderType() {
                          return ClientProxy.tesrRenderId;
                          }
                          
                          @SideOnly(Side.CLIENT)
                              public AxisAlignedBB getSelectedBoundingBox(World world, int x, int y, int z)
                              {
                                  this.setBlockBoundsBasedOnState(world, x, y, z);
                                  return super.getSelectedBoundingBoxFromPool(world,  x, y, z);
                              }
                          
                              public AxisAlignedBB getCollisionBoundingBox(World world, int x, int y, int z)
                              {
                                  this.setBlockBoundsBasedOnState(world, x, y, z);
                                  return super.getCollisionBoundingBoxFromPool(world, x, y, z);
                              }
                          
                          public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) {
                          if (stack.getItemDamage() == 0) {
                          TileEntity tile = world.getTileEntity(x, y, z);
                          if ((tile instanceof TileEntityPoubelle)) {
                          int direction = MathHelper.floor_double(living.rotationYaw * 4.0F / 360.0F + 2.5D) & 0x3;
                          ((TileEntityPoubelle) tile).setDirection((byte) direction);
                          }
                          }
                          }
                          
                          public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
                          if (((axis == ForgeDirection.UP) || (axis == ForgeDirection.DOWN)) && (!world.isRemote)
                          && (world.getBlockMetadata(x, y, z) == 0)) {
                          TileEntity tile = world.getTileEntity(x, y, z);
                          if ((tile instanceof TileEntityPoubelle)) {
                          TileEntityPoubelle tilePoubelle = (TileEntityPoubelle) tile;
                          byte direction = tilePoubelle.getDirection();
                          direction = (byte) (direction + 1);
                          if (direction > 3) {
                          direction = 0;
                          }
                          tilePoubelle.setDirection(direction);
                          return true;
                          }
                          }
                          return false;
                          }
                          
                          public ForgeDirection[] getValidRotations(World world, int x, int y, int z) {
                          return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN }
                          : ForgeDirection.VALID_DIRECTIONS;
                          }
                            public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
                            {
                               TileEntity tile = world.getTileEntity(x, y, z);
                               if(tile instanceof TileEntityPoubelle)
                               {
                                    int direction = ((TileEntityPoubelle)tile).getDirection();
                                    if(direction == 0)
                                    {
                                           this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
                                    }
                                    if(direction == 1)
                                    {
                                           this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                                    }
                                    if(direction == 2)
                                    {
                                           this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F);
                                    }
                                    if(direction == 3)
                                    {
                                           this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F);
                                    }
                               }
                            }
                          }
                          

                          L’emplacement de la classe du bloc est la bonne ?

                          >! Développeur de Altis-Life (Arma III) sur Minecraft !
                          >! Site web     : https://lemnoslife.com

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

                            Comme ça alors :

                            public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
                            {
                            this.setBlockBoundsBasedOnState(world, x, y, z);
                            return super.getSelectedBoundingBoxFromPool(world, x, y, z);
                            }
                            
                            public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
                            {
                            this.setBlockBoundsBasedOnState(world, x, y, z);
                            return super.getCollisionBoundingBoxFromPool(world, x, y, z);
                            }
                            

                            Je suis en 1.8, visiblement le nom des fonctions ne sont pas les mêmes.

                            1 réponse Dernière réponse Répondre Citer 0
                            • Benjamin LoisonB Hors-ligne
                              Benjamin Loison
                              dernière édition par

                              Toujours le même problème… :S

                              Ps: normal que tu es enlevé le side only client ?

                              >! Développeur de Altis-Life (Arma III) sur Minecraft !
                              >! Site web     : https://lemnoslife.com

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

                                Non, remets-le.
                                Vérifies que la fonction setBlockBoundsBasedOnState est bien appelé (ajoutes des System.out.println(“test”) a différent endroit de la fonction)

                                1 réponse Dernière réponse Répondre Citer 0
                                • Benjamin LoisonB Hors-ligne
                                  Benjamin Loison
                                  dernière édition par

                                  ​package fr.altiscraft.altiscraft.common;
                                  
                                  import cpw.mods.fml.relauncher.Side;
                                  import cpw.mods.fml.relauncher.SideOnly;
                                  import fr.altiscraft.altiscraft.proxy.ClientProxy;
                                  import net.minecraft.block.Block;
                                  import net.minecraft.block.material.Material;
                                  import net.minecraft.entity.EntityLivingBase;
                                  import net.minecraft.item.ItemStack;
                                  import net.minecraft.tileentity.TileEntity;
                                  import net.minecraft.util.AxisAlignedBB;
                                  import net.minecraft.util.MathHelper;
                                  import net.minecraft.world.IBlockAccess;
                                  import net.minecraft.world.World;
                                  import net.minecraftforge.common.util.ForgeDirection;
                                  
                                  public class BlocPoubelle extends Block {
                                  protected BlocPoubelle() {
                                  super(Material.ground);
                                  }
                                  
                                  public boolean hasTileEntity(int metadata) {
                                  return true;
                                  }
                                  
                                  public TileEntity createTileEntity(World world, int metadata) {
                                  return new TileEntityPoubelle();
                                  }
                                  
                                  public boolean isOpaqueCube() {
                                  return false;
                                  }
                                  
                                  public boolean renderAsNormalBlock() {
                                  return false;
                                  }
                                  
                                  @SideOnly(Side.CLIENT)
                                  public int getRenderType() {
                                          System.out.println("hello");
                                  return ClientProxy.tesrRenderId;
                                  }
                                  
                                  @SideOnly(Side.CLIENT)
                                      public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
                                      {
                                          System.out.println("ici");
                                          this.setBlockBoundsBasedOnState(world, x, y, z);
                                          System.out.println("la");
                                          return super.getSelectedBoundingBoxFromPool(world,  x, y, z);
                                      }
                                  
                                      public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
                                      {
                                          this.setBlockBoundsBasedOnState(world, x, y, z);
                                          return super.getCollisionBoundingBoxFromPool(world, x, y, z);
                                      }
                                  
                                  public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) {
                                  if (stack.getItemDamage() == 0) {
                                  TileEntity tile = world.getTileEntity(x, y, z);
                                  if ((tile instanceof TileEntityPoubelle)) {
                                  int direction = MathHelper.floor_double(living.rotationYaw * 4.0F / 360.0F + 2.5D) & 0x3;
                                  ((TileEntityPoubelle) tile).setDirection((byte) direction);
                                  }
                                  }
                                  }
                                  
                                  public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
                                  if (((axis == ForgeDirection.UP) || (axis == ForgeDirection.DOWN)) && (!world.isRemote)
                                  && (world.getBlockMetadata(x, y, z) == 0)) {
                                  TileEntity tile = world.getTileEntity(x, y, z);
                                  if ((tile instanceof TileEntityPoubelle)) {
                                  TileEntityPoubelle tilePoubelle = (TileEntityPoubelle) tile;
                                  byte direction = tilePoubelle.getDirection();
                                  direction = (byte) (direction + 1);
                                  if (direction > 3) {
                                  direction = 0;
                                  }
                                  tilePoubelle.setDirection(direction);
                                  return true;
                                  }
                                  }
                                  return false;
                                  }
                                  
                                  public ForgeDirection[] getValidRotations(World world, int x, int y, int z) {
                                  return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN }
                                  : ForgeDirection.VALID_DIRECTIONS;
                                  }
                                    public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
                                    {
                                       TileEntity tile = world.getTileEntity(x, y, z);
                                       if(tile instanceof TileEntityPoubelle)
                                       {
                                            int direction = ((TileEntityPoubelle)tile).getDirection();
                                            if(direction == 0)
                                            {
                                                   this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
                                            }
                                            if(direction == 1)
                                            {
                                                   this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                                            }
                                            if(direction == 2)
                                            {
                                                   this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F);
                                            }
                                            if(direction == 3)
                                            {
                                                   this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F);
                                            }
                                       }
                                    }
                                  }
                                  

                                  Et ça spam la console de ici hello et la… :S

                                  >! Développeur de Altis-Life (Arma III) sur Minecraft !
                                  >! Site web     : https://lemnoslife.com

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

                                    Et comme ça ?

                                    public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
                                    {
                                    TileEntity tile = world.getTileEntity(x, y, z);
                                    if(tile instanceof TileEntityPoubelle)
                                    {
                                    int direction = ((TileEntityPoubelle)tile).getDirection();
                                    System.out.println(direction);
                                    if(direction == 0)
                                    {
                                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
                                    }
                                    if(direction == 1)
                                    {
                                    this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                                    }
                                    if(direction == 2)
                                    {
                                    this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F);
                                    }
                                    if(direction == 3)
                                    {
                                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F);
                                    }
                                    }
                                    }
                                    
                                    1 réponse Dernière réponse Répondre Citer 0
                                    • Benjamin LoisonB Hors-ligne
                                      Benjamin Loison
                                      dernière édition par

                                      Non mais la hitbox est très bizarre quand je vise le bas ça met le bloc d’en dessous et sinon parfois je passe et parfois non…

                                      >! Développeur de Altis-Life (Arma III) sur Minecraft !
                                      >! Site web     : https://lemnoslife.com

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

                                        Comment ça ? Et avec ce que je t’ai donné les logs affichent quoi ?

                                        1 réponse Dernière réponse Répondre Citer 0
                                        • Benjamin LoisonB Hors-ligne
                                          Benjamin Loison
                                          dernière édition par

                                          Ca spam de 0, 1 et 2 mais le 3 est absent…

                                          >! Développeur de Altis-Life (Arma III) sur Minecraft !
                                          >! Site web     : https://lemnoslife.com

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

                                            Tu as posé des blocs dans les 4 directions possibles ?
                                            Si ce print s’affiche bien ta hitbox devrait aussi fonctionner normalement.

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

                                            MINECRAFT FORGE FRANCE © 2024

                                            Powered by NodeBB