Jump to content

Making a Mob Spawn Item


Ravenclaw572

Recommended Posts

Hello! I've come across an issue while trying to create a mod. I can't find any way to create a custom mob spawner item, like ItemMonsterPlacer.class, without making a mob egg. Is there any way I can do this? Or can I somehow edit the texture for my specific mob's egg? Any and all help is appreciated! :)

Link to comment
Share on other sites

Register your entity like this:

	EntityRegistry.registerModEntity(MyEntity.class,"myEntityID",id,this,trackingRange,updateFrequency,true);

I use 256 for trackingRange and 1 for updateFrequency.

Then you need to override onItemRightClick() in your item class. Look at ItemBoat for how to do it.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Register your entity like this:

	EntityRegistry.registerModEntity(MyEntity.class,"myEntityID",id,this,trackingRange,updateFrequency,true);

I use 256 for trackingRange and 1 for updateFrequency.

Then you need to override onItemRightClick() in your item class. Look at ItemBoat for how to do it.

 

I'd already registered it, and had it working. I just needed the item. I did look at the boat code, to no avail. I'm still quite clueless. Here's the code:

public class MobSpawner extends Item {
    public MobSpawner(int par1)
    {
        super(par1);
        this.setCreativeTab(MyMod.MyTab);
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        float f = 1.0F;
        float f1 = par3EntityPlayer.prevRotationPitch + (par3EntityPlayer.rotationPitch - par3EntityPlayer.prevRotationPitch) * f;
        float f2 = par3EntityPlayer.prevRotationYaw + (par3EntityPlayer.rotationYaw - par3EntityPlayer.prevRotationYaw) * f;
        double d0 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)f;
        double d1 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)f + 1.62D - (double)par3EntityPlayer.yOffset;
        double d2 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)f;
        Vec3 vec3 = par2World.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
        float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
        float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
        float f5 = -MathHelper.cos(-f1 * 0.017453292F);
        float f6 = MathHelper.sin(-f1 * 0.017453292F);
        float f7 = f4 * f5;
        float f8 = f3 * f5;
        double d3 = 5.0D;
        Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
        MovingObjectPosition movingobjectposition = par2World.rayTraceBlocks_do(vec3, vec31, true);

        if (movingobjectposition == null)
        {
            return par1ItemStack;
        }
        else
        {
            Vec3 vec32 = par3EntityPlayer.getLook(f);
            boolean flag = false;
            float f9 = 1.0F;
            List list = par2World.getEntitiesWithinAABBExcludingEntity(par3EntityPlayer, par3EntityPlayer.boundingBox.addCoord(vec32.xCoord * d3, vec32.yCoord * d3, vec32.zCoord * d3).expand((double)f9, (double)f9, (double)f9));
            int i;

            for (i = 0; i < list.size(); ++i)
            {
                Entity entity = (Entity)list.get(i);

                if (entity.canBeCollidedWith())
                {
                    float f10 = entity.getCollisionBorderSize();
                    AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f10, (double)f10, (double)f10);

                    if (axisalignedbb.isVecInside(vec3))
                    {
                        flag = true;
                    }
                }
            }

            if (flag)
            {
                return par1ItemStack;
            }
            else
            {
                if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
                {
                    i = movingobjectposition.blockX;
                    int j = movingobjectposition.blockY;
                    int k = movingobjectposition.blockZ;

                    if (par2World.getBlockId(i, j, k) == Block.snow.blockID)
                    {
                        --j;
                    }

                    EntityMyEntity entitymyentity = new EntityMyEntity(par2World);
                    entitymyentity.rotationYaw = (float)(((MathHelper.floor_double((double)(par3EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) - 1) * 90);

                    if (!par2World.getCollidingBoundingBoxes(entitymyentity, entitymyentity.boundingBox.expand(-0.1D, -0.1D, -0.1D)).isEmpty())
                    {
                        return par1ItemStack;
                    }

                    if (!par2World.isRemote)
                    {
                        par2World.spawnEntityInWorld(entitymyentity);
                    }

                    if (!par3EntityPlayer.capabilities.isCreativeMode)
                    {
                        --par1ItemStack.stackSize;
                    }
                }

                return par1ItemStack;
            }
        }
    }
    
       public String getTextureFile() {
           return "/myspawner.png";
       }
}

Link to comment
Share on other sites

Did you try putting some sort of a check in there to see if it's getting called? Remember, also, that you have to spawn it far enough; that checks for collisions as with boats.

 

I'm not sure exactly how to. I'm new to Forge Modding. Not so much ModLoader, though it is essentially the same thing, in a way. I know that shouldn't affect items, however. I need something like the mob spawn eggs. That's how my mod was originally. Is there anyway I could edit the texture, or create a new entity list? Like, a separate new mob egg item? I could do textures for that. Considering most of the stuff is just recolored.

Link to comment
Share on other sites

You can still open up the vanilla classes and see how they do things and copy their code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.