MFF

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

    Renderer / tessellator

    Planifier Épinglé Verrouillé Déplacé Sans suite
    1.7.x
    3 Messages 2 Publieurs 1.4k 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.
    • VebertV Hors-ligne
      Vebert
      dernière édition par

      Bonjour à tous,

      Bon pour contextualiser le problème : J’ai beaucoup de mal au niveau graphique et rendu en jeu, donc après une journée a essayer de faire un bloc avec un rendu qui évolue en fonction du temps sans succès je me suis inspiré d’un vieux mod : FiniteLiquid qui était sous ModLoader à l’époque. Donc après quelque manip ça marche presque mais je ne comprend pas vraiment comment.

      premièrement la classe :
      :::

      
      public class Liquid_render implements ISimpleBlockRenderingHandler{
      
      static final float LIGHT_Y_NEG = 0.5F;
      static final float LIGHT_Y_POS = 1.0F;
      static final float LIGHT_XZ_NEG = 0.8F;
      static final float LIGHT_XZ_POS = 0.6F;
      static final double RENDER_OFFSET = 0.0010000000474974513D;
      
      @Override
      public boolean renderWorldBlock(IBlockAccess access, int x, int y, int z,
      Block block, int modelId, RenderBlocks renderer) {
      if (!(block instanceof Block_Fluid_Hagrud))
      {
      return false;
      }
      World world = access.getTileEntity(x, y, z).getWorldObj();
      renderBlock(world, x, y, z);
      return true;
      }
      
      @Override
      public int getRenderId() {
      return 0;
      }
      
      @Override
      public boolean shouldRender3DInInventory(int modelId) {return false;}
      @Override
      
      public void renderInventoryBlock(Block block, int metadata, int modelId,RenderBlocks renderer) {}
      
      private IIcon getIcon(IIcon icon)
      {
      if (icon != null) return icon;
      return ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
      }
      
      protected void renderBlock(World world, int x, int y, int z) {
      Tessellator tessellator = Tessellator.instance;
      //int l = getBlockTextureFromSide(0);
      int l = 2;
      float f = LiquidHelper.getBlockBrightness(world, x, y, z);
      tessellator.setColorOpaque_F(f, f, f);
      int i1 = (l & 0xf) << 4;
      int j1 = l & 0xf0;
      double d = i1 / 256F;
      double d1 = (i1 + 15.99F) / 256F;
      double d2 = j1 / 256F;
      double d3 = (j1 + 15.99F) / 256F;
      int k1 = world.getBlockMetadata(x, y, z);
      float f2 = 0.0F;
      TileEntityLiquid Te = (TileEntityLiquid) world.getTileEntity(x, y, z);
      Block block = world.getBlock(x, y, z);
      int quanta = Te.getquanta();
      float height = 0.0625F*quanta;
      if (!(world.getBlock(x, y, z) == world.getBlock(x, y +1, z)) || height != 16) {
      tessellator.addVertexWithUV(x + 1.0F, y
      + height, (z + 1),
      d, d2);
      tessellator.addVertexWithUV(x + 1.0F, y
      + height,
      (z + 0), d, d3);
      tessellator.addVertexWithUV(x + 0.0F, y
      + height,
      (z + 0), d1, d3);
      tessellator.addVertexWithUV(x + 0.0F, y
      + height,
      (z + 1), d1, d2);
      }
      if (LiquidHelper.canDrawWater(world,block, x, y - 1, z)) {
      tessellator.addVertexWithUV(x + 1.0F, y,
      (z + 1), d, d2);
      tessellator.addVertexWithUV(x + 1.0F, y,
      (z + 0), d, d3);
      tessellator.addVertexWithUV(x + 0.0F, y,
      (z + 0), d1, d3);
      tessellator.addVertexWithUV(x + 0.0F, y,
      (z + 1), d1, d2);
      }
      if (LiquidHelper.canDrawWater(world,block, x - 1, y, z)) {
      tessellator.addVertexWithUV(x,
      y + height + f2,
      (z + 1), d, d2);
      tessellator.addVertexWithUV(x, (y + 0) - f2,
      (z + 1), d, d3);
      tessellator.addVertexWithUV(x, (y + 0) - f2,
      (z + 0), d1, d3);
      tessellator.addVertexWithUV(x,
      y + height + f2,
      (float) (z + 0), d1, d2);
      }
      if (LiquidHelper.canDrawWater(world,block, x + 1, y, z)) {
      tessellator.addVertexWithUV((float) x + 1.0F, (float) y
      + height + f2,
      (float) (z + 1), d, d2);
      tessellator.addVertexWithUV((float) x + 1.0F, (float) (y + 0) - f2,
      (float) (z + 1), d, d3);
      tessellator.addVertexWithUV((float) x + 1.0F, (float) (y + 0) - f2,
      (float) (z + 0), d1, d3);
      tessellator.addVertexWithUV((float) x + 1.0F, (float) y
      + height + f2,
      (float) (z + 0), d1, d2);
      }
      if (LiquidHelper.canDrawWater(world,block , x, y, z - 1)) {
      tessellator.addVertexWithUV((float) x + 1.0F, (float) y
      + height + f2,
      (float) (z + 0), d, d2);
      tessellator.addVertexWithUV((float) x + 1.0F, (float) (y + 0) - f2,
      (float) (z + 0), d, d3);
      tessellator.addVertexWithUV((float) x, (float) (y + 0) - f2,
      (float) (z + 0), d1, d3);
      tessellator.addVertexWithUV((float) x,
      (float) y + height + f2,
      (float) (z + 0), d1, d2);
      }
      if (LiquidHelper.canDrawWater(world,block, x, y, z + 1)) {
      tessellator.addVertexWithUV((float) x + 1.0F, (float) y
      + height + f2,
      (float) (z + 1), d, d2);
      tessellator.addVertexWithUV((float) x + 1.0F, (float) (y + 0) - f2,
      (float) (z + 1), d, d3);
      tessellator.addVertexWithUV((float) x, (float) (y + 0) - f2,
      (float) (z + 1), d1, d3);
      tessellator.addVertexWithUV((float) x,
      (float) y + height + f2,
      (float) (z + 1), d1, d2);
      }
      }
      }
      
      

      :::

      La fonction qui nous intéresse est : protected void renderBlock(World world, int x, int y, int z)

      Donc si quelqu’un a la patience de m’expliquer comment ça fonction(vite fait) je suis preneur.
      Autrement j’ai vraiment besoin d’explication sur ça:
      :::

      
      //int l = getBlockTextureFromSide(0);
      int l = 2;
      float f = LiquidHelper.getBlockBrightness(world, x, y, z);
      tessellator.setColorOpaque_F(f, f, f);
      int i1 = (l & 0xf) << 4;
      int j1 = l & 0xf0;
      double d = i1 / 256F;
      double d1 = (i1 + 15.99F) / 256F;
      double d2 = j1 / 256F;
      double d3 = (j1 + 15.99F) / 256F;
      
      

      :::

      Cette variable l me permet de changer la texture : 2 c’est de l’eau qui coule, les autres ce sont des textures de buildcraft (j’ai les codes de buildcraft pour faire un add-on en parallèles). Je ne comprend pas du tout comment ça fonctionne et j’aimerais bien pouvoir ajouter mes propres textures à ce système.

      Enfin sur le rendu final il me manque deux faces (Nord et Ouest) si vous voyez d’où ça peut venir.

      Merci d’avance,
      Vebert.

      EDIT : Les faces qui ne s’affichent pas ne sont en fait visible que vus de dos (donc depuis l’intérieur du bloc) et pas de l’extérieur (si quelqu’un a une idée pour résoudre ça).

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

        Salut,

        Je vais essaye de te donné quelque piste.

        
        int l = 2;
        //float f = LiquidHelper.getBlockBrightness(world, x, y, z);
        //tessellator.setColorOpaque_F(f, f, f);
        int i1 = (l & 0xf) << 4;
        int j1 = l & 0xf0;
        double d = i1 / 256F;
        double d1 = (i1 + 15.99F) / 256F;
        double d2 = j1 / 256F;
        double d3 = (j1 + 15.99F) / 256F;
        
        

        Ce code permet de calculer les coordonnés de la texture à appliquer sur ton block. Tu a normalement une image de 256256 contant de multiple image 1616 à l’intérieur.

        
        int l = IndiceX * 16 + IndiceY ; // ou inverse
        
        

        Apres, il te reste à changé la valeur de l a chaque tick pour choisir la texture que tu souhaite affichée.

        Pour ton problème de texture, c’est l’ordre des coordonnées des Vertex qui est inversé. Change le sens est normalement la texture devrai être correct.

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

          Ok merci je vais tester ça, au fait ça marche un peu comment dans les anciennes version de minecraft où les textures était toutes sur les même images ?

          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