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

    Résolu Spawn Egg custom

    1.8.x
    2
    5
    1716
    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.
    • Flow
      Flow dernière édition par

      Hello everybody ! Oui je sais , encore moi vous me voyez venir avec ma question débile , mais bon faut bien que je demande de l’aide car j’en ai besoin x)

      Voila j’aimerais créer mes propres spawn egg pour les récupérer ensuite ( merci minecraft du fait qu’on ne puisse pas récupérer les eggs qu’on enregistre directement )

      J’ai trouver ce code sur internet en faisant des recherches

      
      package mod.common.item;
      
      import java.util.Iterator;
      import java.util.List;
      
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      import mod.DinoCraft;
      import mod.client.ClientProxy;
      import mod.common.entity.EntityBrachiosaurus;
      import mod.common.entity.EntityRegister;
      import net.minecraft.block.Block;
      import net.minecraft.block.BlockLiquid;
      import net.minecraft.client.renderer.texture.IIconRegister;
      import net.minecraft.creativetab.CreativeTabs;
      import net.minecraft.entity.Entity;
      import net.minecraft.entity.EntityList;
      import net.minecraft.entity.EntityLiving;
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.entity.IEntityLivingData;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemMonsterPlacer;
      import net.minecraft.item.ItemStack;
      import net.minecraft.util.Facing;
      import net.minecraft.util.IIcon;
      import net.minecraft.util.MathHelper;
      import net.minecraft.util.MovingObjectPosition;
      import net.minecraft.util.StatCollector;
      import net.minecraft.world.World;
      
      public class BlockSpawnEgg extends ItemMonsterPlacer
      {
      @SideOnly(Side.CLIENT)
         private IIcon theIcon;
         protected int colorBase = 0x000000;
         protected int colorSpots = 0xFFFFFF;
         protected String entityToSpawnName = "EntityBrachiosaurus";
         protected String entityToSpawnNameFull = "EntityBrachiosaurus";
         protected EntityLiving entityToSpawn = null;
      
         public BlockSpawnEgg()
         {
             this.setCreativeTab(CreativeTabs.tabMisc);
         }
      
         public BlockSpawnEgg(String parEntityToSpawnName, int parPrimaryColor, 
                 int parSecondaryColor)
           {
               setHasSubtypes(false);
               maxStackSize = 64;
               setCreativeTab(CreativeTabs.tabMisc);
               setEntityToSpawnName(parEntityToSpawnName);
               colorBase = parPrimaryColor;
               colorSpots = parSecondaryColor;
               // DEBUG
               System.out.println("Spawn egg constructor for "+entityToSpawnName);
           }
      
           /**
            * Callback for item usage. If the item does something special on right clicking, 
            * he will have one of those. Return
            * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
            */
           @Override
           public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, 
                 World par3World, int par4, int par5, int par6, int par7, float par8, 
                 float par9, float par10)
           {
               if (par3World.isRemote)
               {
                   return true;
               }
               else
               {
                   Block block = par3World.getBlock(par4, par5, par6);
                   par4 += Facing.offsetsXForSide[par7];
                   par5 += Facing.offsetsYForSide[par7];
                   par6 += Facing.offsetsZForSide[par7];
                   double d0 = 0.0D;
      
                   if (par7 == 1 && block.getRenderType() == 11)
                   {
                       d0 = 0.5D;
                   }
      
                   Entity entity = spawnEntity(par3World, par4 + 0.5D, par5 + d0, par6 + 0.5D);
      
                   if (entity != null)
                   {
                       if (entity instanceof EntityLivingBase && par1ItemStack.hasDisplayName())
                       {
                           ((EntityLiving)entity).setCustomNameTag(par1ItemStack.getDisplayName());
                       }
      
                       if (!par2EntityPlayer.capabilities.isCreativeMode)
                       {
                           –par1ItemStack.stackSize;
                       }
                   }
      
                   return true;
               }
           }
      
           /**
            * Called whenever this item is equipped and the right mouse button is pressed. 
            *Args: itemStack, world, entityPlayer
            */
           @Override
           public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, 
                 EntityPlayer par3EntityPlayer)
           {
               if (par2World.isRemote)
               {
                   return par1ItemStack;
               }
               else
               {
                   MovingObjectPosition movingobjectposition = 
                         getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);
      
                   if (movingobjectposition == null)
                   {
                       return par1ItemStack;
                   }
                   else
                   {
                       if (movingobjectposition.typeOfHit == MovingObjectPosition
                             .MovingObjectType.BLOCK)
                       {
                           int i = movingobjectposition.blockX;
                           int j = movingobjectposition.blockY;
                           int k = movingobjectposition.blockZ;
      
                           if (!par2World.canMineBlock(par3EntityPlayer, i, j, k))
                           {
                               return par1ItemStack;
                           }
      
                           if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition
                                 .sideHit, par1ItemStack))
                           {
                               return par1ItemStack;
                           }
      
                           if (par2World.getBlock(i, j, k) instanceof BlockLiquid)
                           {
                               Entity entity = spawnEntity(par2World, i, j, k);
      
                               if (entity != null)
                               {
                                   if (entity instanceof EntityLivingBase && par1ItemStack
                                         .hasDisplayName())
                                   {
                                       ((EntityLiving)entity).setCustomNameTag(par1ItemStack
                                             .getDisplayName());
                                   }
      
                                   if (!par3EntityPlayer.capabilities.isCreativeMode)
                                   {
                                       --par1ItemStack.stackSize;
                                   }
                               }
                           }
                       }
      
                       return par1ItemStack;
                   }
               }
           }
      
           /**
            * Spawns the creature specified by the egg's type in the location specified by 
            * the last three parameters.
            * Parameters: world, entityID, x, y, z.
            */
           public Entity spawnEntity(World parWorld, double parX, double parY, double parZ)
           {
      
              if (!parWorld.isRemote) // never spawn entity on client side
              {
                   entityToSpawnNameFull = DinoCraft.MODID+"."+entityToSpawnName;
                   if (EntityList.stringToClassMapping.containsKey(entityToSpawnNameFull))
                   {
                       entityToSpawn = (EntityLiving) EntityList
                             .createEntityByName(entityToSpawnNameFull, parWorld);
                       entityToSpawn.setLocationAndAngles(parX, parY, parZ, 
                             MathHelper.wrapAngleTo180_float(parWorld.rand.nextFloat()
                             * 360.0F), 0.0F);
                       parWorld.spawnEntityInWorld(entityToSpawn);
                       entityToSpawn.onSpawnWithEgg((IEntityLivingData)null);
                       entityToSpawn.playLivingSound();
                   }
                   else
                   {
                       //DEBUG
                       System.out.println("Entity not found "+entityToSpawnName);
                   }
               }
      
               return entityToSpawn;
           }
      
           /**
            * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
            */
           @Override
           @SideOnly(Side.CLIENT)
           public void getSubItems(Item parItem, CreativeTabs parTab, List parList)
           {
               parList.add(new ItemStack(parItem, 1, 0));     
           }
      
           @Override
           @SideOnly(Side.CLIENT)
           public int getColorFromItemStack(ItemStack par1ItemStack, int parColorType)
           {
               return (parColorType == 0) ? colorBase : colorSpots;
           }
      
           @Override
           @SideOnly(Side.CLIENT)
           public boolean requiresMultipleRenderPasses()
           {
               return true;
           }
      
           @Override
           // Doing this override means that there is no localization for language
           // unless you specifically check for localization here and convert
           public String getItemStackDisplayName(ItemStack par1ItemStack)
           {
               return "Spawn "+entityToSpawnName;
           }  
      
           @Override
           @SideOnly(Side.CLIENT)
           public void registerIcons(IIconRegister par1IconRegister)
           {
               super.registerIcons(par1IconRegister);
               theIcon = par1IconRegister.registerIcon(getIconString() + "_overlay");
           }
      
           /**
            * Gets an icon index based on an item's damage value and the given render pass
            */
           @Override
           @SideOnly(Side.CLIENT)
           public IIcon getIconFromDamageForRenderPass(int parDamageVal, int parRenderPass)
           {
               return parRenderPass > 0 ? theIcon : super.getIconFromDamageForRenderPass(parDamageVal, 
                     parRenderPass);
           }
      
           public void setColors(int parColorBase, int parColorSpots)
           {
            colorBase = parColorBase;
            colorSpots = parColorSpots;
           }
      
           public int getColorBase()
           {
            return colorBase;
           }
      
           public int getColorSpots()
           {
            return colorSpots;
           }
      
           public void setEntityToSpawnName(String parEntityToSpawnName)
           {
               entityToSpawnName = parEntityToSpawnName;
               entityToSpawnNameFull = DinoCraft.MODID+"."+entityToSpawnName; 
           }
      
       }
      
      

      Tout d’abord cette première partie , je comprend pas , je comprend que la c’est la déclaration des noms

         protected String entityToSpawnName = "EntityBrachiosaurus";
         protected String entityToSpawnNameFull = "EntityBrachiosaurus";
         protected EntityLiving entityToSpawn = null;
      
      

      Et que le null doit être remplacer mais lorsque je remplace par mon EntityBrachiosaurus pas moyen de l’import rien 😕

      Dans le tuto ils disent aussi que je dois enregistrer comme ceci mon Egg

      [size=smallItem itemSpawnEgg =] **new** WildAnimalsMonsterPlacer("Tiger", 0xE18519, 0x000000)
      [size=small     .]setUnlocalizedName("spawn_egg_"+parSpawnName.toLowerCase())
      [size=small     .]setTextureName("wildanimals:spawn_egg");
      GameRegistry.registerItem(itemSpawnEgg, "spawnEgg"+parSpawnName%(#333333)[);
      ```]
      
      [color=#333333Ce ][color=#333333parSpawnName ]apparaît[size=small en rouge et je sais pas pourquoi , fin si il est pas déclaré mais je vois pas ou :/ Jsuis un peu bloquer :(]
      
      [color=#666666Merci à ceux qui m'aideront :)]

      Oui ce gif est drôle.

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

        @‘Legrandfifou’:

        ( merci minecraft du fait qu’on ne puisse pas récupérer les eggs qu’on enregistre directement )

        Ah bon ? Tu en es sûr ? Tu cherches à faire quoi exactement ?

        Sinon pour le code que tu as fait, ça m’a l’air d’être du grand n’importe quoi x)

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

          @‘robin4002’:

          @‘Legrandfifou’:

          ( merci minecraft du fait qu’on ne puisse pas récupérer les eggs qu’on enregistre directement )

          Ah bon ? Tu en es sûr ? Tu cherches à faire quoi exactement ?

          Sinon pour le code que tu as fait, ça m’a l’air d’être du grand n’importe quoi x)

          Bah selon les autres membres il faudrait utilisé la réflection pour récupérer les spawns egg ( les miens )

          Donc je me suis dit que créer mon propre spawn egg serait plus facile 🙂

          Le code c’est pas moi qui l’ai fait x) Voila ce que j’ai trouver sur Internet

          http://jabelarminecraft.blogspot.be/p/minecraft-forge-1721710-creating-custom.html

          Oui ce gif est drôle.

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

            package fr.minecraftforgefrance.test;
            
            import java.util.Iterator;
            import java.util.Set;
            
            import net.minecraft.entity.EntityList;
            import net.minecraft.entity.monster.EntityMob;
            import net.minecraft.init.Blocks;
            import net.minecraft.init.Items;
            import net.minecraft.item.ItemStack;
            import net.minecraft.nbt.NBTTagCompound;
            import net.minecraft.world.World;
            import net.minecraftforge.fml.common.Mod;
            import net.minecraftforge.fml.common.Mod.EventHandler;
            import net.minecraftforge.fml.common.event.FMLInitializationEvent;
            import net.minecraftforge.fml.common.registry.EntityRegistry;
            import net.minecraftforge.fml.common.registry.GameRegistry;
            
            @Mod(modid = "test", version = "1.0.0")
            public class TestMod
            {
            @EventHandler
            public void init(FMLInitializationEvent event)
            {
            EntityRegistry.registerModEntity(EntityTest.class, "test", 0, this, 20, 4, false, 0xFF0000, 0x00CC00);
            
            ItemStack stack = new ItemStack(Items.spawn_egg);
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setString("entity_name", "test.test"); // -> modid.nom de l'entité
            stack.setTagCompound(nbt);
            GameRegistry.addRecipe(stack, new Object[]{"xxx", 'x', Blocks.sponge});
            
            }
            
            public static class EntityTest extends EntityMob
            {
            public EntityTest(World worldIn)
            {
            super(worldIn);
            }
            }
            }
            

            1.8 seulement 😕

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

              Ca servira pour ceux qui cherche 🙂

              En tout cas merci à Scarex j’ai utilisé la réflection 🙂

              Oui ce gif est drôle.

              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