Jump to content

[1.7.10] No mob-tutorial availabe beyond basic cloning existing mobs?


Recommended Posts

Posted

Hello

 

First off: I am new to Java but I am programming PHP for years now, using object oriented frameworks. Now I thought experimenting with mods in minecraft could be a good way to learn a bit of a different language. So I started with a tutorial and everything worked fine, I created my own mob and also played around a little, giving it different abilities that I took from other mob classes. But while experimenting I also noticed that one can not simply clone a villager and make him attacking but also it seems not to be easily possible to give a mob villager abilities like opening doors or navigate inside a house...

 

Anyhow, my problem now lays here: I want to mod a mob, that creates rogues to the game. They would roam the world and attack random entities but not always kill them. I want them also to test for the attacked's health and if the health is low, occassionally not killing the player/entity but robbing them by taking one or more items from their inventory. (Is that even possible?) Amount of items taken could be random and success of robbing too, like throwing a dice in a RPG. In return for the player, this mob when defeated would not only drop the same item-class but random values and if the player has been robbed before, there would be a chance for the next defeated rogue to drop that item so the player has a chance to get it back...

 

So, I created a first copy of the player's avatar, giving it another texture and let it run. The issue I stubmled on was, that I can not seem to get it spawn randomly like other mobs do. I tried two methods I read in the wiki:

 

In the Entity class I tried this

 

@EventHandler
    public void init(FMLInitializationEvent event)
    {
        int id =0;
        EntityRegistry.registerModEntity(EntityTutMob.class, "TutMob", id, this, 80, 1, true);//id is an internal mob id, you can start at 0 and continue adding them up.
        id++;
        EntityRegistry.addSpawn(EntityTutMob.class, 1, 10, 20, EnumCreatureType.creature);//change the values to vary the spawn rarity, biome, etc. 

        LanguageRegistry.instance().addStringLocalization("entity.TutMob.name", "en_US","YourMobName");//set a more readable name for the entity in given language
       
    }

 

That doesn't throw an error but also does not spawn a mob anywhere.

 

Also this in my MainRegistry class does not work

 

/**
 * Loads during
 * @param event
 */
public void load(FMLInitializationEvent event)
{
     EntityRegistry.registerModEntity(EntityTutMob.class, "TutMob", EntityRegistry.findGlobalUniqueEntityId(), this, 80, 1, true);//id is an internal mob id, you can start at 0 and continue adding them up.
     
     EntityRegistry.addSpawn(EntityTutMob.class, 2, 3, 5, EnumCreatureType.creature);//change the values to vary the spawn rarity, biome, etc. 
     LanguageRegistry.instance().addStringLocalization("entity.TutMob.name", "en_US","YourMobName");//set a more readable name for the entity in given language
}

 

Same, no error, no crash but also no spawn elsewhere.

Both methods in the wiki are for older versions I assume, as eclipse also tells me about LanguageRegistry.instance().addStringLocalization being deprecated.

Spawning them with eggs works fine however.

I seem to fail finding a tutorial where it is explained for 1.7.10 how to spawn mobs automatically in world and where to set if they spawn at night or daytime.

 

The next thing I didnt find yet is how to get a mob to use a weapon from its inventory. My mob supposed to randomly use swords/tools or even bows for attacking. Also the propability for a mob entity to attack a player would be it's attack strength. So the mob would turn passive when the player has a better sword than the mob entity. Possible?

 

Also I would like to get a hint for ability to read a player's health and inventory and "steal" an item from it. I assume I just have to access a method from the player's inventory class, but is that even possible from the mod classes without adding code to the minecraft core classes?

 

Any links, tips or hints are appreciated even if a similar question was asked already, please point

Thank you

Posted

Oh and I forgot another question I had: How can I spawn mobs with randomly selected textures? I tried to put the textures in render and wrote a method that selects the texture randomly, but that just causes textures flickering randomly on the same body. It's a cool effect as it could also be used for animated textures but nevertheless I would first like to change textures statically random on each spawn.

Posted

All of those things are possible. FML initialization events are supposed to go in your main mod class - they don't belong in your entity class. Once you have it in the right place, your spawn rates should work.

 

You also should not be using global entity ID - use the EntityRegistry#registerModEntity method only, and if you need a spawn egg, create your own.

 

Randomly assigned textures can be done through the entity class, by assigning each entity a random value when it is spawned, using either DataWatcher or IEntityAdditionalSpawnData to inform the client side what the value is so you can use it in rendering. Be sure to also save the mob's type to and from NBT, so it has the same texture when you re-load.

 

For checking health - assuming you are using attackEntityAsMob method or something similar, you have an Entity parameter that is the entity being attacked; check if (entity instanceof EntityLivingBase), then you can cast to check its health:

EntityLivingBase living = (EntityLivingBase) entity;
float ratio = living.getHealth() / living.getMaxHealth();

 

Same for checking a player's inventory - check if the entity being attacked is an instance of EntityPlayer, then cast accordingly and run through the player's inventory until you find whatever you are looking for.

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.