Jump to content

[1.7.10]How do I change what equipment Vanilla Mobs can spawn with?


Recommended Posts

Posted

I'm now trying this: post 5

 

I found this Tutorial, but it's for 1.6.2, so I don't know if it's outdated: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571568-tutorial-1-6-2-changing-vanilla-without-editing and I found this in EntityLiving:

 

    protected void addRandomArmor()
    {
        if (this.rand.nextFloat() < 0.15F * this.worldObj.func_147462_b(this.posX, this.posY, this.posZ))
        {
            int i = this.rand.nextInt(2);
            float f = this.worldObj.difficultySetting == EnumDifficulty.HARD ? 0.1F : 0.25F;

            if (this.rand.nextFloat() < 0.095F)
            {
                ++i;
            }

            if (this.rand.nextFloat() < 0.095F)
            {
                ++i;
            }

            if (this.rand.nextFloat() < 0.095F)
            {
                ++i;
            }

            for (int j = 3; j >= 0; --j)
            {
                ItemStack itemstack = this.func_130225_q(j);

                if (j < 3 && this.rand.nextFloat() < f)
                {
                    break;
                }

                if (itemstack == null)
                {
                    Item item = getArmorItemForSlot(j + 1, i);

                    if (item != null)
                    {
                        this.setCurrentItemOrArmor(j + 1, new ItemStack(item));
                    }
                }
            }
        }
    }

 

I have a main class that has:

    @EventHandler
    public void load(FMLInitializationEvent event)
    {
    	MinecraftForge.EVENT_BUS.register(new EntityLivingHandler());
    }

and I have a class called "EntityLivingHandler":

package com.multiverse.entity;

public class EntityLivingHandler {

    @ForgeSubscribe
    protected void onAddRandomArmor(addRandomArmor() event)
    {
        if (this.rand.nextFloat() < 0.15F * this.worldObj.func_147462_b(this.posX, this.posY, this.posZ)){
            int i = this.rand.nextInt(2);
            float f = this.worldObj.difficultySetting == EnumDifficulty.HARD ? 0.1F : 0.25F;
            if (this.rand.nextFloat() < 0.095F){
                ++i;
            }
            if (this.rand.nextFloat() < 0.095F){
                ++i;
            }
            if (this.rand.nextFloat() < 0.095F){
                ++i;
            }
            for (int j = 9; j >= 6; --j){
                ItemStack itemstack = this.func_130225_q(j);
                if (j < 9 && this.rand.nextFloat() < f){
                    break;
                }
                if (itemstack == null){
                    Item item = getArmorItemForSlot(j + 1, i);
                    if (item != null){
                        this.setCurrentItemOrArmor(j + 1, new ItemStack(item));
                    }
                }
            }
        }
    }
}

"@ForgeSubscribe" and "(addRandomArmor() event)" is underlined in read. This is the first time doing this, am I going about this all wrong? How do I change what armors mobs can spawn with?

Posted

ForgeSubscribe has been renamed to SubscribeEvent, and I'm not sure what Event you should be using (if there is no Random Armor Event, use an EntityJoinWorldEvent (I think)), but it would be like any other method parameter, for example:

void onAddRandomArmor(EntityJoinWorldEvent event)

Also, I think the method may have to be public.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

ForgeSubscribe has been renamed to SubscribeEvent, and I'm not sure what Event you should be using (if there is no Random Armor Event, use an EntityJoinWorldEvent (I think)), but it would be like any other method parameter, for example:

void onAddRandomArmor(EntityJoinWorldEvent event)

Also, I think the method may have to be public.

I changed it @SubscribeEvent and made it public and that fixed it some. Now "addRandomArmor() event" is underlined in red. I tried changing it to EntityJoinWorldEvent and imported using Ctrl+Shift+O and it caused a lot of things to underlined.

Posted

I'm not sure what you mean. If I open the declaration "worldObj" it leads me to Entity.class, but I want to change the way "addRandomArmor()" works in EntityLiving.class without editing base files. All that needs to be changed is this:

for (int j = 3; j >= 0; --j)
//and
if (j < 3 && this.rand.nextFloat() < f)

to this:

for (int j = 9; j >= 6; --j)
//and
if (j < 9 && this.rand.nextFloat() < f)

 

EDIT: Am I only able to use @SubscribeEvent on classes found in packages that start with "net.minecraftforge"?

 

EDIT: Do I make an event that runs after it spawns, that removes it's equipment and gives it new ones?

 

EDIT: Okay I just found this: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1429778-1-4-7-forge-how-to-override-entity-help maybe what I need to do is make a new version of zombie, and make the changes there, and make it so zombies wont spawn, but the new zombie will.

Posted

Okay I got it working. I used a new Zombie Mob and replaced the old mob with the new using "EntityRegistry.removeSpawn" I just need to remove the old spawn egg now.

Here's the new zombie mob A.I.:

 

package com.multiverse.entity;

import com.multiverse.items.MultiverseItems;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;

public class EntityNewZombieAI extends EntityZombie{

    public EntityNewZombieAI(World p_i1745_1_)
    {
        super(p_i1745_1_);
        this.getNavigator().setBreakDoors(true);
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true));
        this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
        this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(8, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, 0, false));
        this.setSize(0.6F, 1.8F);
    }
    
    public static Item getNewArmorItemForSlot(int p_82161_0_, int p_82161_1_){
        switch (p_82161_0_){
            case 4:
                if (p_82161_1_ == 0){
                    return MultiverseItems.LeatherHelmetNew;
                }
                else if (p_82161_1_ == 1){
                    return MultiverseItems.GoldenHelmetNew;
                }
                else if (p_82161_1_ == 2){
                    return MultiverseItems.ChainmailHelmetNew;
                }
                else if (p_82161_1_ == 3){
                    return MultiverseItems.IronHelmetNew;
                }
                else if (p_82161_1_ == 4){
                    return MultiverseItems.DiamondHelmetNew;
                }
            case 3:
                if (p_82161_1_ == 0){
                    return MultiverseItems.LeatherChestplateNew;
                }
                else if (p_82161_1_ == 1){
                    return MultiverseItems.GoldenChestplateNew;
                }
                else if (p_82161_1_ == 2){
                    return MultiverseItems.ChainmailChestplateNew;
                }
                else if (p_82161_1_ == 3){
                    return MultiverseItems.IronChestplateNew;
                }
                else if (p_82161_1_ == 4){
                    return MultiverseItems.DiamondChestplateNew;
                }
            case 2:
                if (p_82161_1_ == 0){
                    return MultiverseItems.LeatherLeggingsNew;
                }
                else if (p_82161_1_ == 1){
                    return MultiverseItems.GoldenLeggingsNew;
                }
                else if (p_82161_1_ == 2){
                    return MultiverseItems.ChainmailLeggingsNew;
                }
                else if (p_82161_1_ == 3){
                    return MultiverseItems.IronLeggingsNew;
                }
                else if (p_82161_1_ == 4){
                    return MultiverseItems.DiamondLeggingsNew;
                }
            case 1:
                if (p_82161_1_ == 0){
                    return MultiverseItems.LeatherBootsNew;
                }
                else if (p_82161_1_ == 1){
                    return MultiverseItems.GoldenBootsNew;
                }
                else if (p_82161_1_ == 2){
                    return MultiverseItems.ChainmailBootsNew;
                }
                else if (p_82161_1_ == 3){
                    return MultiverseItems.IronBootsNew;
                }
                else if (p_82161_1_ == 4){
                    return MultiverseItems.DiamondBootsNew;
                }
            default:
                return null;
        }
    }
    
    @Override
    protected void addRandomArmor()
    {
    	if (this.rand.nextFloat() < 0.15F * this.worldObj.func_147462_b(this.posX, this.posY, this.posZ)){
            int i = this.rand.nextInt(2);
            float f = this.worldObj.difficultySetting == EnumDifficulty.HARD ? 0.1F : 0.25F;
            if (this.rand.nextFloat() < 0.095F){
                ++i;
            }
            if (this.rand.nextFloat() < 0.095F){
                ++i;
            }
            if (this.rand.nextFloat() < 0.095F){
                ++i;
            }
            for (int j = 3; j >= 0; --j){
                ItemStack itemstack = this.func_130225_q(j);
                if (j < 3 && this.rand.nextFloat() < f){
                    break;
                }
                if (itemstack == null){
                    Item item = getNewArmorItemForSlot(j + 1, i);

                    if (item != null){
                        this.setCurrentItemOrArmor(j + 1, new ItemStack(item));
                    }
                }
            }
        }

        if (this.rand.nextFloat() < (this.worldObj.difficultySetting == EnumDifficulty.HARD ? 0.05F : 0.01F))
        {
            int i = this.rand.nextInt(3);
            if (i == 0){
                this.setCurrentItemOrArmor(0, new ItemStack(Items.iron_sword));
            }
            else{
                this.setCurrentItemOrArmor(0, new ItemStack(Items.iron_shovel));
            }
        }
    }
}

 

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.