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

      ​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 Hors-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 Hors-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 Hors-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
                • Benjamin LoisonB Hors-ligne
                  Benjamin Loison
                  dernière édition par

                  Oui dans tous les sens… :S

                  EDIT: Ah maintenant le 3 apparait… :S Que faire ?

                  >! 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
                  • Benjamin LoisonB Hors-ligne
                    Benjamin Loison
                    dernière édition par

                    Ah maintenant le 3 apparait… :S Que faire ?

                    >! 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 Hors-ligne
                      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                      dernière édition par

                      J’en ai profité d’avoir ton code pour tester de mon côté.
                      Toutes les hitbox fonctionne correctement sauf celle de la direction 2.
                      Car tu as mit une valeur au minimum supérieur au maximum …

                      Regarde bien ce que tu as mit :

                      if (direction == 2) {
                      this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F);
                      }
                      

                      La fonction setBlockBounds a pour argument minX, minY, minZ, maxX, maxY, maxZ. Or 1.0F > 0.5F (minZ et maxZ)
                      Il faut donc mettre :

                      if (direction == 2) {
                      this.setBlockBounds(0.0F, 0.0F, 0.5F, 1.0F, 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

                        Effectivement j’avais oublié cette restriction merci beaucoup et désolé de la maladresse…

                        >! 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
                        • 1
                        • 2
                        • 2 / 2
                        • Premier message
                          Dernier message
                        Design by Woryk
                        ContactMentions Légales

                        MINECRAFT FORGE FRANCE © 2024

                        Powered by NodeBB