• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu Échec dans la création d'un bloc orientable avec rendu avancé

    1.7.x
    1.7.10
    2
    4
    1154
    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.
    • Folgansky
      Folgansky Correcteurs dernière édition par

      Bien le bonjour, je suis, comme la plupart des gens qui viennent demander un peu d’aide ici, novice en modding et j’ai suivi les excellents tutoriels de robin afin de débuter dans le domaine.

      J’ai dans l’idée de créer un bloc “trophée” avec rendu avancé ressemblant à une main tout simplement bref une création techne de test avant de m’attaquer à plus grand par la suite.
      J’avais réussis après de très longues heures à regarder les tutos, revérifier encore et encore et cétéra pour enfin arriver à faire un bloc orientable.
      Comme ceci:

      Seulement j’ai eu un problème pour build mon mod et j’avais tout remis à plat à zéro (mon problème venant des sources de forge).

      Au final, cet après midi je me remotive à refaire tout seulement au final j’obtiens ça:

      Edit: Je précise que poser le bloc fait crash le client.
      Voilà je repasse tout en revu et évidemment je n’arrive pas à comprendre.
      Je me dis que ça vient du TESRInventory mais pourtant tout me semble bon.

      :::

      package fr.heroesconflict.modhc.common;
      
      import fr.heroesconflict.modhc.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.util.MathHelper;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.world.World;
      import net.minecraftforge.common.util.ForgeDirection;
      
      public class Trophee extends Block
      {
      public Trophee(Material mat)
      {
      super(mat);
      }
      
       public boolean hasTileEntity(int metadata)
        {
            return true;
        }  
      
        public TileEntity createTileEntity(World world, int metadata)
        {
            return new TileEntityTrophee();
        }
      
        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 TileEntityTrophee)
                {
                    int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
                    ((TileEntityTrophee)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 TileEntityTrophee)
                {
                TileEntityTrophee tileDirectional = (TileEntityTrophee)tile;
                    byte direction = tileDirectional.getDirection();
                    direction++;
                    if(direction > 3)
                    {
                        direction = 0;
                    }
                    tileDirectional.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 boolean isOpaqueCube()
        {
            return false;
        }   
      
        public boolean renderAsNormalBlock()
        {
            return false;
        } 
      
        public int getRenderType()
        {
            return ClientProxy.tesrRenderId;
        }
      }
      

      :::

      :::

      package fr.heroesconflict.modhc.common;
      
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.network.NetworkManager;
      import net.minecraft.network.Packet;
      import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
      import net.minecraft.tileentity.TileEntity;
      
      public class TileEntityTrophee extends TileEntity
      {
      private byte direction;
      
          @Override
          public void readFromNBT(NBTTagCompound compound)
          {
              super.readFromNBT(compound);
              this.direction = compound.getByte("Direction");
          }
      
          @Override
          public void writeToNBT(NBTTagCompound compound)
          {
              super.writeToNBT(compound);
              compound.setByte("Direction", this.direction);
          }
      
          public byte getDirection()
          {
              return direction;
          }
      
          public void setDirection(byte direction)
          {
              this.direction = direction;
              this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
          }
      
          public Packet getDescriptionPacket()
          {
              NBTTagCompound nbttagcompound = new NBTTagCompound();
              this.writeToNBT(nbttagcompound);
              return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
          }
      
          public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
          {
              this.readFromNBT(pkt.func_148857_g());
              this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord);
          }
      }
      

      :::

      :::

      package fr.heroesconflict.modhc.client;
      
      import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
      import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.util.ResourceLocation;
      
      import org.lwjgl.opengl.GL11;
      
      import fr.heroesconflict.modhc.common.Modhc;
      import fr.heroesconflict.modhc.common.TileEntityTrophee;
      
      public class TileEntityTropheeSpecialRenderer extends TileEntitySpecialRenderer
      {
          public static TropheeMain model = new TropheeMain();
          public static ResourceLocation texture = new ResourceLocation(Modhc.MODID, "textures/models/blocks/trophee.png");
      
          public TileEntityTropheeSpecialRenderer()
          {
              this.func_147497_a(TileEntityRendererDispatcher.instance);
          }
      
          @Override
          public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialRenderTick)
          {
              this.renderTileEntityTropheeAt((TileEntityTrophee)tile, x, y, z, partialRenderTick);
          }
      
          private void renderTileEntityTropheeAt(TileEntityTrophee tile, double x, double y, double z, float partialRenderTick)
          {
              GL11.glPushMatrix();
              GL11.glTranslated(x + 0.5D, y + 1.5D, z + 0.5D);
              GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
              GL11.glRotatef((90F * tile.getDirection()) + 180F, 0.0F, 1.0F, 0.0F);
              this.bindTexture(texture);
              model.renderAll();
              GL11.glPopMatrix();
          }
      }
      

      :::

      :::

      package fr.heroesconflict.modhc.proxy;
      
      import net.minecraft.block.Block;
      import net.minecraft.client.Minecraft;
      import net.minecraft.client.renderer.RenderBlocks;
      import net.minecraft.world.IBlockAccess;
      
      import org.lwjgl.opengl.GL11;
      
      import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
      import fr.heroesconflict.modhc.client.TileEntityTropheeSpecialRenderer;
      import fr.heroesconflict.modhc.common.Modhc;
      
      public class TESRInventoryRenderer implements ISimpleBlockRenderingHandler
      {
      @Override
      public void renderInventoryBlock(Block block, int metadata, int modelId,RenderBlocks renderer) 
      {
      if(block == Modhc.trophee && metadata == 0)
      {
      GL11.glPushMatrix();
         GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
         GL11.glTranslatef(0.0F, -1.0F, 0.0F);
         GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
         Minecraft.getMinecraft().getTextureManager().bindTexture(TileEntityTropheeSpecialRenderer.texture);
         TileEntityTropheeSpecialRenderer.model.renderAll();
         GL11.glPopMatrix();
      }
      }
      
      @Override
      public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) 
      {
      return false;
      }
      
      @Override
      public boolean shouldRender3DInInventory(int modelId)
          {
      return true;
      }
      
      @Override
      public int getRenderId() 
      {
      return ClientProxy.tesrRenderId;
      }
      }
      

      :::

      :::

      package fr.heroesconflict.modhc.proxy;
      
      import cpw.mods.fml.client.registry.ClientRegistry;
      import cpw.mods.fml.client.registry.RenderingRegistry;
      import fr.heroesconflict.modhc.client.TileEntityTropheeSpecialRenderer;
      import fr.heroesconflict.modhc.common.TileEntityTrophee;
      
      public class ClientProxy extends CommonProxy
      {
      public static int tesrRenderId;
      
      @Override
      public void registerRender()
      {
        RenderingRegistry.registerBlockHandler(new TESRInventoryRenderer());
        tesrRenderId = RenderingRegistry.getNextAvailableRenderId();
      
        ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTrophee.class, new TileEntityTropheeSpecialRenderer());
      }
      }
      

      :::

      :::
      public static Block trophee;
      […]
      public static Block trophee;
      […]
      @EventHandler
      public void preInit(FMLPreInitializationEvent event)
      {
      trophee = new Trophee(Material.rock).setBlockName(“trophee”).setBlockTextureName(MODID + “:trophee”).setCreativeTab(Modhc.tabHc);

      GameRegistry.registerBlock(trophee, “trophee”);
      […]
      }

      @EventHandler
      public void Init(FMLInitializationEvent event)
      {
      GameRegistry.registerTileEntity(TileEntityTrophee.class, “modhc:trophee”);  //Edit:Rajouté, du coup ça ne crash plus
      proxy.registerRender();
      }

      :::

      Voilà, si quelqu’un voit, sait, comprend et par dessus tout saurait m’expliquer où j’ai merdé, je lui en serais très reconnaissant.

      Au plaisir de côtoyer la communauté.

      Edit: Pour le crash c’est un que j’avais oublié le fameux     “GameRegistry.registerTileEntity(TileEntityBidule.class, “Truc:Bidule”);”
              Il me reste la texture en main qui n’est pas bonne et non plus quand je casse le bloc

      1 réponse Dernière réponse Répondre Citer 0
      • Folgansky
        Folgansky Correcteurs dernière édition par

        Ok alors c’est tout bête, deux grosses erreurs.

        De un, j’avais tout simplement pas Register mon Entity dans le l’Init
        De deux, dans mon ClientProxy j’avais mis le “RenderingRegistry…” avant de déclarer le tesrRenderId

        Bon, ça m’a pris quelques heures + un bon film pour se détendre avant de finalement tomber pile sur le prob.
        Alors soit ce topic servira à quelqu’un, soit vous pouvez carrément le supprimer.

        Au plaisir.

        1 réponse Dernière réponse Répondre Citer 0
        • L
          Laserflip33 dernière édition par

          Salut, tu as trouvé la solution tout seul, bien joué mais est-ce que tu pourrais passer le sujet en résolu? Et à l’avenir également, c’est moins de boulot pour les modérateurs.

          1 réponse Dernière réponse Répondre Citer 0
          • Folgansky
            Folgansky Correcteurs dernière édition par

            @‘Laserflip33’:

            Salut, tu as trouvé la solution tout seul, bien joué mais est-ce que tu pourrais passer le sujet en résolu? Et à l’avenir également, c’est moins de boulot pour les modérateurs.

            Ouaip, navré je ne pensais qu’à aller me pieuter après avoir trouvé +posté la “solution” pour éviter de déranger.

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

            MINECRAFT FORGE FRANCE © 2018

            Powered by NodeBB