Jump to content

[1.7.10] how to create a spawn egg for custom mob


Glistre

Recommended Posts

having trouble creating the spawn egg, the mob I created Glistre Wolf is working fine and spawning, but no egg.  I have tried various codes cannot seem to get this right: 

 

This is my main mod class in the pre init:

 


//  REGISTER YOUR ENTITY
//        int randomId = EntityRegistry.findGlobalUniqueEntityId();

	EntityRegistry.registerGlobalEntityID(EntityGlistreWolf.class, "Glistre_Wolf", EntityRegistry.findGlobalUniqueEntityId());
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 2, 3, 7, EnumCreatureType.creature, BiomeGenBase.desert);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungle);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungleEdge);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.taiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.forest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.roofedForest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.savanna);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.coldTaiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 20, 3, 7, EnumCreatureType.creature, BiomeGenBase.plains);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.swampland);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.birchForest);
//		EntityList.addMapping(EntityGlistreWolf.class, "Glistre_Wolf", EntityRegistry.findGlobalUniqueEntityId(), 0x000000, 0xFFFFFF);

 

And this is the code for my spawn egg ...I have tried putting this in the main class before the pre-init method, or in the pre init method (gives me errors: for "randomID" Eclipse says "remove invalid modifiers" and for "registerEntityEgg" Eclipse says "void is an invalid type for the variable registerEnityEgg".  I also tried placing the egg code in both my custom mob class and tried registering the egg in the the Init method, but I cannot seem to get this right.

 

Here is my custom mob file:

 package com.glistre.glistremod;

import java.awt.Color;

import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBeg;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityGlistreWolf extends EntityTameable
{

private float field_70926_e;
    private float field_70924_f;
    /** true is the wolf is wet else false */
    private boolean isShaking;
    private boolean field_70928_h;
    /** This time increases while wolf is shaking and emitting water particles. */
    private float timeWolfIsShaking;
    private float prevTimeWolfIsShaking;
    private static final String __OBFID = "CL_00001654";

    public EntityGlistreWolf(World p_i1696_1_)
    {
        super(p_i1696_1_);
        this.setSize(0.6F, 0.8F);
        this.getNavigator().setAvoidsWater(true);
        this.tasks.addTask(1, new EntityAISwimming(this));
        this.tasks.addTask(2, this.aiSit);
        this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
        this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
        this.tasks.addTask(6, new EntityAIMate(this, 1.0D));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
//        this.tasks.addTask(8, new EntityAIBeg(this, 8.0F));
        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(9, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
        this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
        this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
        this.setTamed(false);
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);

        if (this.isTamed())
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
        }
        else
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
        }
    }

    /**
     * Returns true if the newer Entity AI code should be run
     */
    public boolean isAIEnabled()
    {
        return true;
    }

    /**
     * Sets the active target the Task system uses for tracking
     */
    public void setAttackTarget(EntityLivingBase p_70624_1_)
    {
        super.setAttackTarget(p_70624_1_);

        if (p_70624_1_ == null)
        {
            this.setAngry(false);
        }
        else if (!this.isTamed())
        {
            this.setAngry(true);
        }
    }

    /**
     * main AI tick function, replaces updateEntityActionState
     */
    protected void updateAITick()
    {
        this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
    }

    protected void entityInit()
    {
        super.entityInit();
        this.dataWatcher.addObject(18, new Float(this.getHealth()));
        this.dataWatcher.addObject(19, new Byte((byte)0));
        this.dataWatcher.addObject(20, new Byte((byte)BlockColored.func_150032_b(1)));
    }

    protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_)
    {
        this.playSound("mob.wolf.step", 0.15F, 1.0F);
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    public void writeEntityToNBT(NBTTagCompound p_70014_1_)
    {
        super.writeEntityToNBT(p_70014_1_);
        p_70014_1_.setBoolean("Angry", this.isAngry());
        p_70014_1_.setByte("CollarColor", (byte)this.getCollarColor());
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound p_70037_1_)
    {
        super.readEntityFromNBT(p_70037_1_);
        this.setAngry(p_70037_1_.getBoolean("Angry"));

        if (p_70037_1_.hasKey("CollarColor", 99))
        {
            this.setCollarColor(p_70037_1_.getByte("CollarColor"));
        }
    }

    /**
     * Returns the sound this mob makes while it's alive.
     */
    protected String getLivingSound()
    {
        return this.isAngry() ? "mob.wolf.growl" : (this.rand.nextInt(3) == 0 ? (this.isTamed() && this.dataWatcher.getWatchableObjectFloat(18) < 10.0F ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
    }

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    protected String getHurtSound()
    {
        return "mob.wolf.hurt";
    }

    /**
     * Returns the sound this mob makes on death.
     */
    protected String getDeathSound()
    {
        return "mob.wolf.death";
    }

    /**
     * Returns the volume for the sounds this mob makes.
     */
    protected float getSoundVolume()
    {
        return 0.4F;
    }

    protected Item getDropItem()
    {
        return Item.getItemById(-1);
    }

    /**
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
     * use this to react to sunlight and start to burn.
     */
    public void onLivingUpdate()
    {
        super.onLivingUpdate();

        if (!this.worldObj.isRemote && this.isShaking && !this.field_70928_h && !this.hasPath() && this.onGround)
        {
            this.field_70928_h = true;
            this.timeWolfIsShaking = 0.0F;
            this.prevTimeWolfIsShaking = 0.0F;
            this.worldObj.setEntityState(this, (byte);
        }
    }

    /**
     * Called to update the entity's position/logic.
     */
    public void onUpdate()
    {
        super.onUpdate();
        this.field_70924_f = this.field_70926_e;

        if (this.func_70922_bv())
        {
            this.field_70926_e += (1.0F - this.field_70926_e) * 0.4F;
        }
        else
        {
            this.field_70926_e += (0.0F - this.field_70926_e) * 0.4F;
        }

        if (this.func_70922_bv())
        {
            this.numTicksToChaseTarget = 10;
        }

        if (this.isWet())
        {
            this.isShaking = true;
            this.field_70928_h = false;
            this.timeWolfIsShaking = 0.0F;
            this.prevTimeWolfIsShaking = 0.0F;
        }
        else if ((this.isShaking || this.field_70928_h) && this.field_70928_h)
        {
            if (this.timeWolfIsShaking == 0.0F)
            {
                this.playSound("mob.wolf.shake", this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            }

            this.prevTimeWolfIsShaking = this.timeWolfIsShaking;
            this.timeWolfIsShaking += 0.05F;

            if (this.prevTimeWolfIsShaking >= 2.0F)
            {
                this.isShaking = false;
                this.field_70928_h = false;
                this.prevTimeWolfIsShaking = 0.0F;
                this.timeWolfIsShaking = 0.0F;
            }

            if (this.timeWolfIsShaking > 0.4F)
            {
                float f = (float)this.boundingBox.minY;
                int i = (int)(MathHelper.sin((this.timeWolfIsShaking - 0.4F) * (float)Math.PI) * 7.0F);

                for (int j = 0; j < i; ++j)
                {
                    float f1 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
                    float f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
                    this.worldObj.spawnParticle("splash", this.posX + (double)f1, (double)(f + 0.8F), this.posZ + (double)f2, this.motionX, this.motionY, this.motionZ);
                }
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public boolean getWolfShaking()
    {
        return this.isShaking;
    }

    /**
     * Used when calculating the amount of shading to apply while the wolf is shaking.
     */
    @SideOnly(Side.CLIENT)
    public float getShadingWhileShaking(float p_70915_1_)
    {
        return 0.75F + (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70915_1_) / 2.0F * 0.25F;
    }

    @SideOnly(Side.CLIENT)
    public float getShakeAngle(float p_70923_1_, float p_70923_2_)
    {
        float f2 = (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70923_1_ + p_70923_2_) / 1.8F;

        if (f2 < 0.0F)
        {
            f2 = 0.0F;
        }
        else if (f2 > 1.0F)
        {
            f2 = 1.0F;
        }

        return MathHelper.sin(f2 * (float)Math.PI) * MathHelper.sin(f2 * (float)Math.PI * 11.0F) * 0.15F * (float)Math.PI;
    }

    public float getEyeHeight()
    {
        return this.height * 0.8F;
    }

    @SideOnly(Side.CLIENT)
    public float getInterestedAngle(float p_70917_1_)
    {
        return (this.field_70924_f + (this.field_70926_e - this.field_70924_f) * p_70917_1_) * 0.15F * (float)Math.PI;
    }

    /**
     * The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently
     * use in wolves.
     */
    public int getVerticalFaceSpeed()
    {
        return this.isSitting() ? 20 : super.getVerticalFaceSpeed();
    }

    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
    {
        if (this.isEntityInvulnerable())
        {
            return false;
        }
        else
        {
            Entity entity = p_70097_1_.getEntity();
            this.aiSit.setSitting(false);

            if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
            {
                p_70097_2_ = (p_70097_2_ + 1.0F) / 2.0F;
            }

            return super.attackEntityFrom(p_70097_1_, p_70097_2_);
        }
    }

    public boolean attackEntityAsMob(Entity p_70652_1_)
    {
        int i = this.isTamed() ? 4 : 2;
        return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);
    }

    public void setTamed(boolean p_70903_1_)
    {
        super.setTamed(p_70903_1_);

        if (p_70903_1_)
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
        }
        else
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
        }
    }

    /**
     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
     */
    public boolean interact(EntityPlayer p_70085_1_)
    {
        ItemStack itemstack = p_70085_1_.inventory.getCurrentItem();

        if (this.isTamed())
        {
            if (itemstack != null)
            {
                if (itemstack.getItem() instanceof ItemFood)
                {
                    ItemFood itemfood = (ItemFood)itemstack.getItem();

                    if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F)
                    {
                        if (!p_70085_1_.capabilities.isCreativeMode)
                        {
                            --itemstack.stackSize;
                        }

                        this.heal((float)itemfood.func_150905_g(itemstack));

                        if (itemstack.stackSize <= 0)
                        {
                            p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
                        }

                        return true;
                    }
                }
                else if (itemstack.getItem() == Items.dye)
                {
                    int i = BlockColored.func_150032_b(itemstack.getItemDamage());

                    if (i != this.getCollarColor())
                    {
                        this.setCollarColor(i);

                        if (!p_70085_1_.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
                        {
                            p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
                        }

                        return true;
                    }
                }
            }

            if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack))
            {
                this.aiSit.setSitting(!this.isSitting());
                this.isJumping = false;
                this.setPathToEntity((PathEntity)null);
                this.setTarget((Entity)null);
                this.setAttackTarget((EntityLivingBase)null);
            }
        }
        else if (itemstack != null && itemstack.getItem() == Items.bone && !this.isAngry())
        {
            if (!p_70085_1_.capabilities.isCreativeMode)
            {
                --itemstack.stackSize;
            }

            if (itemstack.stackSize <= 0)
            {
                p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
            }

            if (!this.worldObj.isRemote)
            {
                if (this.rand.nextInt(3) == 0)
                {
                    this.setTamed(true);
                    this.setPathToEntity((PathEntity)null);
                    this.setAttackTarget((EntityLivingBase)null);
                    this.aiSit.setSitting(true);
                    this.setHealth(20.0F);
                    this.func_152115_b(p_70085_1_.getUniqueID().toString());
                    this.playTameEffect(true);
                    this.worldObj.setEntityState(this, (byte)7);
                }
                else
                {
                    this.playTameEffect(false);
                    this.worldObj.setEntityState(this, (byte)6);
                }
            }

            return true;
        }

        return super.interact(p_70085_1_);
    }

    @SideOnly(Side.CLIENT)
    public void handleHealthUpdate(byte p_70103_1_)
    {
        if (p_70103_1_ == 
        {
            this.field_70928_h = true;
            this.timeWolfIsShaking = 0.0F;
            this.prevTimeWolfIsShaking = 0.0F;
        }
        else
        {
            super.handleHealthUpdate(p_70103_1_);
        }
    }

    @SideOnly(Side.CLIENT)
    public float getTailRotation()
    {
        return this.isAngry() ? 1.5393804F : (this.isTamed() ? (0.55F - (20.0F - this.dataWatcher.getWatchableObjectFloat(18)) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F));
    }

    /**
     * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
     * the animal type)
     */
    public boolean isBreedingItem(ItemStack p_70877_1_)
    {
        return p_70877_1_ == null ? false : (!(p_70877_1_.getItem() instanceof ItemFood) ? false : ((ItemFood)p_70877_1_.getItem()).isWolfsFavoriteMeat());
    }

    /**
     * Will return how many at most can spawn in a chunk at once.
     */
    public int getMaxSpawnedInChunk()
    {
        return 8;
    }

    /**
     * Determines whether this wolf is angry or not.
     */
    public boolean isAngry()
    {
        return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
    }

    /**
     * Sets whether this wolf is angry or not.
     */
    public void setAngry(boolean p_70916_1_)
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);

        if (p_70916_1_)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2)));
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3)));
        }
    }

    /**
     * Return this wolf's collar color.
     */
    public int getCollarColor()
    {
        return this.dataWatcher.getWatchableObjectByte(20) & 15;
    }

    /**
     * Set this wolf's collar color.
     */
    public void setCollarColor(int p_82185_1_)
    {
        this.dataWatcher.updateObject(20, Byte.valueOf((byte)(p_82185_1_ & 15)));
    }

    public EntityGlistreWolf createChild(EntityAgeable p_90011_1_)
    {
        EntityGlistreWolf entitywolf = new EntityGlistreWolf(this.worldObj);
        String s = this.func_152113_b();

        if (s != null && s.trim().length() > 0)
        {
            entitywolf.func_152115_b(s);
            entitywolf.setTamed(true);
        }

        return entitywolf;
    }

    public void func_70918_i(boolean p_70918_1_)
    {
        if (p_70918_1_)
        {
            this.dataWatcher.updateObject(19, Byte.valueOf((byte)1));
        }
        else
        {
            this.dataWatcher.updateObject(19, Byte.valueOf((byte)0));
        }
    }

    /**
     * Returns true if the mob is currently able to mate with the specified mob.
     */
    public boolean canMateWith(EntityAnimal p_70878_1_)
    {
        if (p_70878_1_ == this)
        {
            return false;
        }
        else if (!this.isTamed())
        {
            return false;
        }
        else if (!(p_70878_1_ instanceof EntityGlistreWolf))
        {
            return false;
        }
        else
        {
            EntityGlistreWolf entitywolf = (EntityGlistreWolf)p_70878_1_;
            return !entitywolf.isTamed() ? false : (entitywolf.isSitting() ? false : this.isInLove() && entitywolf.isInLove());
        }
    }

    public boolean func_70922_bv()
    {
        return this.dataWatcher.getWatchableObjectByte(19) == 1;
    }

    /**
     * Determines if an entity can be despawned, used on idle far away entities
     */
    protected boolean canDespawn()
    {
        return !this.isTamed() && this.ticksExisted > 2400;
    }

    public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_)
    {
        if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast))
        {
            if (p_142018_1_ instanceof EntityGlistreWolf)
            {
                EntityGlistreWolf entitywolf = (EntityGlistreWolf)p_142018_1_;

                if (entitywolf.isTamed() && entitywolf.getOwner() == p_142018_2_)
                {
                    return false;
                }
            }

            return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse)p_142018_1_).isTame();
        }
        else
        {
            return false;
        }
    }
}

 

Any suggestions would help I thought spawn eggs would be pretty easy since I am just trying to extend the Wolf class

 

 

Link to comment
Share on other sites

Thanks for your response I had the spawn egg working for a moment after using your code to copy ItemMonsterPlacer class, but then custom mob was not spawning ...I tried to register the mob a different way and now nothing works

 

I am confused now.

 

Here is the code I used in my main class in the preinit method:

		Item itemSpawnEgg = new GlistreEntityMonsterPlacer("Glistre_Wolf", 0x000000, 0xFFFFFF)
	.setUnlocalizedName ("spawn_egg_")
	.setTextureName("glistremod.spawn_egg");
	GameRegistry.registerItem(itemSpawnEgg, "spawnEgg");

 

Here is the code of my ItemMonsterPlacer class:

		package com.glistre.glistremod;
import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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.world.World;
import net.minecraft.world.biome.BiomeCache.Block;

public class GlistreEntityMonsterPlacer extends ItemMonsterPlacer
{
    @SideOnly(Side.CLIENT)
    private IIcon theIcon;
    protected int colorBase = 0x000000;
    protected int colorSpots = 0xFFFFFF;
    protected String entityToSpawnName = "Glistre_Wolf";
    protected String entityToSpawnNameFull = "Glistre_Wolf";
    protected EntityLiving entityToSpawn = null;

    public GlistreEntityMonsterPlacer()
    {
        super();
    }
    
    public GlistreEntityMonsterPlacer(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
        {
            net.minecraft.block.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 = GlistreMod.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("Glistre Wolf 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() + "_Glistre_Wolf");
    }
    
    /**
     * 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 = GlistreMod.MODID+"."+entityToSpawnName; 
    }

}

 

Here is my hopeless attempt at registering the mob and egg not working at all now very confused:

       EntityRegistry.registerGlobalEntityID(EntityGlistreWolf.class, "Glistre_Wolf", EntityGlistreWolfID);
//       EntityRegistry.registerModEntity(EntityGlistreWolf.class, "Glistre_Wolf", EntityGlistreWolfID, GlistreMod.modinstance, 64, 1, true);
        EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 2, 3, 7, EnumCreatureType.creature, BiomeGenBase.desert);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungle);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungleEdge);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.taiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.forest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.roofedForest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.savanna);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.coldTaiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 20, 3, 7, EnumCreatureType.creature, BiomeGenBase.plains);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.swampland);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.birchForest);
//	EntityRegistry.registerGlobalEntityID(EntityGlistreWolf.class, "Glistre_Wolf", EntityGlistreWolfEggID, 0xE18519, 0x000000);
//	EntityGlistreWolf.registerEntityEgg(EntityGlistreWolf.class, 0xE18519, 0x000000);

 

Could you possibly help me get straightened out?

Link to comment
Share on other sites

You're still using the old way of registering the entity, instead of

EntityRegistry.registerGlobalEntityID(EntityGlistreWolf.class, "Glistre_Wolf", EntityGlistreWolfID);

you should use:

int modEntityID = 0;
EntityRegistry.registerModEntity(EntityGlistreWolf.class, "Glistre_Wolf", ++modEntityID, <name of your mod's main class>.instance, 80, 3, false);

 

All that other spawn stuff is related to natural spawning and not the spawn egg.

 

Other than that, to debug you should put some console statements with System.out.println() at judicious places in the code and confirm that it is executing as expected.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Outstanding!!  Both spawning Glistre_Wolf and spawnEgg working.  Sometimes the spawn egg stops working and I am not able to "summon" Glistre_Wolf.

 

I did not understand how to use .instance so I put <this>...I am still learning

 

Here is my current code main file I am planning to clean it up later today:

 

 package com.glistre.glistremod;

import java.awt.Color;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.projectile.EntityEgg;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.world.WorldType;

import com.glistre.glistremod.WorldTypeGlistre;

import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.common.BiomeManager;
import net.minecraftforge.common.BiomeManager.BiomeEntry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

import com.glistre.glistremod.BiomeRegistry;
import com.glistre.glistremod.GlistreArmor;
import com.glistre.glistremod.GlistreDust;
import com.glistre.glistremod.GlistreOre;
import com.glistre.glistremod.GlistreSword;
import com.glistre.glistremod.CommonProxy;
import com.glistre.glistremod.ClientProxy;
import com.glistre.glistremod.MyItem;
import com.glistre.glistremod.MyPickaxe;
import com.glistre.glistremod.MySword;
import com.glistre.glistremod.MyFood;
import com.glistre.glistremod.MyBlock;
//import com.glistre.glistremod.MyArmor;
import com.glistre.glistremod.GlistreBiome;
//import com.glistre.glistremod.MyBlockGen;
import com.glistre.glistremod.EntityGlistreWolf;
//import com.glistre.glistremod.MyEntityTobo;


/* 	MOD INFO */
@Mod(modid = GlistreMod.MODID, name = "Glistre Mod", version = "2.0")

public class GlistreMod {

public static final String MODID = "GlistreMod";
public static final String NAME = "Glistre Mod";
public static final String VERSION = "2.0";

	/*	PROXY INFO */
@SidedProxy(clientSide = ("com.glistre.glistremod.ClientProxy"), serverSide = ("com.glistre.glistremod.CommonProxy"))
public static CommonProxy proxy;

GlistreEventHandler handler = new GlistreEventHandler();
private String parSpawnName;

/**	
* DECLARATION SECTION 
* *********************************************************** */
public static ItemArmor GlistreArmor;

// DECLARE THE ARMOR
public static Item MyHelmet_1;
public static Item MyChestplate_1;
public static Item MyLeggings_1;
public static Item MyBoots_1;

//ARMOR ID's
public static int MyHelmet_1ID;
public static int MyChestplate_1ID;
public static int MyLeggings_1ID;
public static int MyBoots_1ID;



// DECLARE THE ARMOR MATERIAL
public static ArmorMaterial Glistre=
/** maxDamageFactor, damageReductionAmountArray, enchantability*/		
		EnumHelper.addArmorMaterial("Glistre", 28, new int[]{3, 7, 6, 4}, 50);
//GlistreArmor= EnumHelper.addArmorMaterial("GlistreArmor", 28, new int[]{3, 7, 6, 4}, 50);

//  DECLARE THE SWORD 
        public static Item MySword_1;
        
//  DECLARE THE SWORD 
        public static Item Glistre_Sword;
    
//  DECLARE THE PICKAXE 
        public static Item MyPickaxe_1;

//  DECLARE THE PICKAXE 
        public static Item Glistre_Pickaxe;
        
//  DECLARE THE ITEM
        public static Item MyItem_1;

//  DECLARE THE ITEM
        public static Item Glistre_Dust;

//  DECLARE THE ITEM
        public static Item Glistre_Ore;

//  DECLARE GLISTERING BREAD
        public static Item MyFood_1;
        
//  DECLARE GLISTERING PIE
        public static Item MyFood_2;

//  DECLARE THE BLOCK
        public static Block MyBlock_1;

//  DECLARE THE BIOME
      
//  DECLARE THE MOB ID

   

//  DECLARE THE MOB SPAWN EGG



//	DECLARE THE NEW ACHIEVEMENTS	
        public static Achievement MyAchievement_1;
        public static Achievement MyAchievement_2;    	
        public static Achievement MyAchievement_3;

        public int modEntityID = 0;


/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


        
@EventHandler	
public void preInit( FMLPreInitializationEvent event ){

FMLCommonHandler.instance().bus().register(handler);
MinecraftForge.EVENT_BUS.register(handler);

proxy.registerRendering();
;

/**	
* LOAD SECTION 
* *********************************************************** */ 
//LOAD THE ARMOR

	MyHelmet_1 = new GlistreArmor(Glistre, MyHelmet_1ID, 0).setUnlocalizedName("MyHelmet_1").setCreativeTab(CreativeTabs.tabCombat).setTextureName(MODID + ":" + "MyHelmet_1");
	//MyArmor(2060, EnumArmorMaterial.IRON, 0, 0, "myarmor");
	GameRegistry.registerItem(MyHelmet_1, "MyHelmet_1");

	MyChestplate_1 = new GlistreArmor(Glistre, MyChestplate_1ID, 1).setUnlocalizedName("MyChestplate_1").setCreativeTab(CreativeTabs.tabCombat).setTextureName(MODID + ":" + "MyChestplate_1");
	GameRegistry.registerItem(MyChestplate_1, "MyChestplate_1");

	MyLeggings_1 = new GlistreArmor(Glistre, MyLeggings_1ID, 2).setUnlocalizedName("MyLeggings_1").setCreativeTab(CreativeTabs.tabCombat).setTextureName(MODID + ":" + "MyLeggings_1");
	GameRegistry.registerItem(MyLeggings_1, "MyLeggings_1");

	MyBoots_1 = new GlistreArmor(Glistre, MyBoots_1ID, 3).setUnlocalizedName("MyBoots_1").setCreativeTab(CreativeTabs.tabCombat).setTextureName(MODID + ":" + "MyBoots_1");
	GameRegistry.registerItem(MyBoots_1, "MyBoots_1");        

//  LOAD THE SWORDS
        MySword_1 = new Item().setUnlocalizedName("MySword_1").setCreativeTab(CreativeTabs.tabCombat).setTextureName(MODID + ":" + "MySword_1"); 
        	//	MySword(ToolMaterial Item, EnumToolMaterial, "MySword_1");
        GameRegistry.registerItem(MySword_1, MySword_1.getUnlocalizedName());

        Glistre_Sword = new Item().setUnlocalizedName("Glistre_Sword").setCreativeTab(CreativeTabs.tabCombat).setTextureName(MODID + ":" + "Glistre_Sword");
        GameRegistry.registerItem(Glistre_Sword, Glistre_Sword.getUnlocalizedName());
       
//  LOAD THE PICKAXE
        MyPickaxe_1 = new Item().setUnlocalizedName("MyPickaxe_1").setCreativeTab(CreativeTabs.tabTools).setTextureName(MODID + ":" + "MyPickaxe_1");
        GameRegistry.registerItem(MyPickaxe_1, MyPickaxe_1.getUnlocalizedName());

//  LOAD THE ITEMS
        MyItem_1 = new Item().setUnlocalizedName("MyItem_1").setCreativeTab(CreativeTabs.tabMisc).setMaxStackSize(64).setTextureName(MODID + ":" + "MyItem_1");
        GameRegistry.registerItem(MyItem_1, MyItem_1.getUnlocalizedName());

        Glistre_Dust = new Item().setUnlocalizedName("Glistre_Dust").setCreativeTab(CreativeTabs.tabMaterials).setMaxStackSize(64).setTextureName(GlistreMod.MODID + ":" + "Glistre_Dust");
        GameRegistry.registerItem(Glistre_Dust, Glistre_Dust.getUnlocalizedName());

        Glistre_Ore = new Item().setUnlocalizedName("Glistre_Ore").setCreativeTab(CreativeTabs.tabMisc).setMaxStackSize(64).setTextureName(MODID + ":" + "Glistre_Ore");
        		//GlistreOre(2034, "Glistre_Ore").setCreativeTab(CreativeTabs.tabMisc).setMaxStackSize(64);
        GameRegistry.registerItem(Glistre_Ore, Glistre_Ore.getUnlocalizedName());

//  GLISTERING BREAD
        /** itemID, healAmount, saturationModifier (F), isWolfsFavoriteMeat, Texture Name */
        MyFood_1 = new ItemFood(6,5.0F,true).setUnlocalizedName("MyFood_1").setCreativeTab(CreativeTabs.tabFood).setMaxStackSize(64).setTextureName(MODID + ":" + "MyFood_1");
        GameRegistry.registerItem(MyFood_1, MyFood_1.getUnlocalizedName());

//  GLISTERING PIE
        /** itemID, healAmount, saturationModifier (F), isWolfsFavoriteMeat, Texture Name */
        MyFood_2 = new ItemFood(8,5.5F, true).setUnlocalizedName("MyFood_2").setCreativeTab(CreativeTabs.tabFood).setMaxStackSize(64).setTextureName(MODID + ":" + "MyFood_2");
        //MyFood(2041, 8, 5.5F, true, "MyFood_2").setAlwaysEdible().setCreativeTab(CreativeTabs.tabFood);
        GameRegistry.registerItem(MyFood_2, MyFood_2.getUnlocalizedName());

//  LOAD THE BLOCK 
        MyBlock_1 = new MyBlock().setBlockName("MyBlock_1").setCreativeTab(CreativeTabs.tabBlock).setBlockTextureName(MODID + ":" + "MyBlock_1")
        		.setLightLevel(1.0F).setResistance(5.0F).setHardness(3.5F).setStepSound(Block.soundTypeStone);
        GameRegistry.registerBlock(MyBlock_1, MyBlock_1.getUnlocalizedName());
	//MinecraftForge.setBlockHarvestLevel(MyBlock_1, "pickaxe", 1);	

//  LOAD BIOME
        BiomeRegistry.GlisterMod();

//  REGISTER YOUR ENTITY
// old way of registering Entity      EntityRegistry.registerGlobalEntityID(EntityGlistreWolf.class, "Glistre_Wolf", EntityGlistreWolfID);
// new way       int modEntityID = 0;
//       EntityRegistry.registerModEntity(EntityGlistreWolf.class, "Glistre_Wolf", ++modEntityID, <name of your mod's main class>.instance, 80, 3, false);

        EntityRegistry.registerModEntity(EntityGlistreWolf.class, "Glistre_Wolf", ++modEntityID, this, 80, 3, false);
        EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 2, 3, 7, EnumCreatureType.creature, BiomeGenBase.desert);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungle);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungleEdge);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.taiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.forest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.roofedForest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.savanna);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.coldTaiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 20, 3, 7, EnumCreatureType.creature, BiomeGenBase.plains);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.swampland);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.birchForest);

//	EntityGlistreWolf.registerEntityEgg(EntityGlistreWolf.class, 0xE18519, 0x000000);

	Item itemSpawnEgg = new GlistreEntityMonsterPlacer("Glistre_Wolf", 0x000000, 0xFFFFFF)
	.setUnlocalizedName ("spawn_egg_")
	.setTextureName("glistremod.spawn_egg");
	GameRegistry.registerItem(itemSpawnEgg, "spawnEgg");

// REGISTER GLISTREWOLF SPAWNEGGS






     
       
       

//	LOAD THE ACHIEVEMENTS
	//MyAchievement_1 = new Achievement(2001, "MyAchievement_1", -1, -3, MyBlock_1, (Achievement) null).registerAchievement();
	//MyAchievement_2 = new Achievement(2002, "MyAchievement_2", -3, -3, MyItem_1, MyAchievement_1.registerAchievement());
	//MyAchievement_3 = new Achievement(2003, "MyAchievement_3", -5, -3, Glistre_Dust, AchievementList.buildFurnace);
	//	(id, "NameOfAchievement", x, y coordinates on Achievement map, icon, Required Achievement to unlock)
	// 	For no Pre-required achievement, use "(Achievement)null"

/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	
}





@EventHandler
public static void init(FMLInitializationEvent event ) 
{


/**	
* RECIPES SECTION 
* *********************************************************** */

//  SWORD RECIPE  
        GameRegistry.addRecipe(new ItemStack(MySword_1, 1), new Object[]
        {
                " X ",
                " X ",
                " S ",
            'S', Items.stick,
            'X', MyItem_1,
        });
        
//  SWORD RECIPE  
        GameRegistry.addRecipe(new ItemStack(Glistre_Sword, 1), new Object[]
        {
                " X ",
                " X ",
                " S ",
            'S', Items.stick,
            'X', Glistre_Ore,
        });

//  PICKAXE RECIPE  
        GameRegistry.addRecipe(new ItemStack(MyPickaxe_1, 1), new Object[]
        {
                "XXX",
                " X ",
                " S ",            
            'S', Items.stick,
            'X', MyItem_1,
        });

// GLISTRE DUST RECIPE
        ItemStack GlistreDust = new ItemStack(GlistreMod.Glistre_Dust);
        ItemStack SilverIngot = new ItemStack(GlistreMod.MyItem_1);
        ItemStack GoldIngot = new ItemStack(Items.gold_ingot);
        
        GameRegistry.addShapelessRecipe(GlistreDust, MyItem_1, GoldIngot);
        
// SMELTING GLISTRE ORE RECIPE
        ItemStack GlistreOre = new ItemStack(GlistreMod.Glistre_Ore);

       GameRegistry.addSmelting(GlistreMod.Glistre_Dust, GlistreOre, 12.0F);        

//  SMELTING RECIPE
        GameRegistry.addSmelting(MyBlock_1, (new ItemStack(MyItem_1, 1)), 12);

//  GLISTERING BREAD RECIPE         
        GameRegistry.addRecipe(new ItemStack(MyFood_1, 1), new Object[]
        {
                "   ",
                " X ",
                " S ",
            'S', Items.bread,
            'X', GlistreMod.Glistre_Dust,
        });

//  GLISTERING PIE RECIPE         
        GameRegistry.addRecipe(new ItemStack(MyFood_2, 1), new Object[]
        {
                " Z ",
                " S ",
                "   ",
            'Z', Items.sugar,
            'S', GlistreMod.MyFood_1,
        });
       



/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


/**	
* EXTRA METHODS SECTION 
* *********************************************************** */

//  REGISTER THE ORE GENERATION 
    //GameRegistry.registerWorldGenerator(new MyBlockGen());

//	CHANGE THE TEXT OF THE ACHIEVEMENTS	
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_1", "en_US", "Silver Ore");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_1.desc", "en_US", "Mine Silver Ore");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_2", "en_US", "Silver Ingot");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_2.desc", "en_US", "Smelt Silver Ore");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_3", "en_US", "Glistre Dust");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_3.desc", "en_US", "Craft Glistre Dust");

/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


}

@EventHandler
public static void postInit( FMLPostInitializationEvent event ) 
{

WorldType BIOMEGLISTRE = new WorldTypeGlistre(3, "biomeGlistre");

}

}

Link to comment
Share on other sites

Summon command working when using the " Aka I type /summon GlistreMod.Glistre_Wolf in the command line

 

Only thing left now is making a custom spawn egg texture not sure about the occasional lag I will try the system.out.println and see if anything shows up

 

Thank you Also Jabelar for the tuts keep them coming they are really helpful

 

Could you explain instance? I got it to work for me instead of this but I just copied someone's code and do not understand it

 

Thanks again

Link to comment
Share on other sites

Could you explain instance? I got it to work for me instead of this but I just copied someone's code and do not understand it

 

Thanks again

 

In object-oriented programming, such as Java, a class can either be static or instantiated (whenever you use the "new" keyword in Java).  And if it is instantiated it can either only have one instance (they call this a "singleton") or multiple. 

 

Because of the client server nature of games like Minecraft, static classes can be a problem if they have fields that can be modified -- then the modification might happen twice (e.g. if you had a counter decrementing, it would decrement twice every tick because both client and server will call the same static class and each decrement)  So most classes with modifiable fields should be instantiated.  These may be "singleton" on each side, but technically there may be two instances running in parallel (both client and server).

 

Classes that are supposed to be instantiated will usually have an explicit constructor, while static classes don't need them.

 

When a class has been instantiated, you have to access it's methods through the instance not just the class name. For example:

  MyClass1.myMethod(); // this is example of a static method call

  MyClass2 myClass2 = new MyClass2();

  myClass2.myMethod(); // this is example of an instance method call

 

A key point is that you need to "remember" the instance in order to access its methods.  For example, each item type has an instance which are instantiated in the Items class.

 

For classes that are singletons, they often provide an public instance field, or a public instance() method to help you find the instance when you need it.

 

Some examples in Minecraft modding:

- You can create new ItemStack all over the place.  Each of those is an instance.

- But the Items class is never instantiated.  It just has a bunch of static final (meaning can't be modified) fields representing all the possible items (which in turn are singleton instances)

- FMLCommonHandler is a singleton, so to call it's methods you need to use FMLCommonHandler .instance()

 

Hope that makes sense.  More experienced programmers may correct some of the info I stated above, but I think it should be mostly correct way to look at it.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.