I am developing a mod, and I want to add a warrior that will randomly wield random custom weapons from my mod. Like for instance, when spawned, this warrior would have a chance of spawning with one of my custom weapons. Say I spawn two warriors, one has a weapon called Venomstrike, the other has a Runic Axe. How would I do this? Don't worry, I know how to code the entity, but I want to know what classes I should extend and what methods should be used. Thanks for the help!
Override EntityLiving#setEquipmentBasedOnDifficulty to generate random equipment for the entity when it first spawns.
EntityMob is probably the best class to extend for hostile mobs.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks, but not exactly what I need. Let my define some things for you. First, I am modding in Eclipse for Minecraft 1.8.9. Second, I would like for my warrior to hold random CUSTOM weapons, not any ordinary thing like zombies and skeletons in the game. Is it possible to create an array of custom weapons that a method can draw from....? Third, I do want my warrior to attack hostile mobs, ie Endermen, zombies, skeletons, etc. Thanks anyway though
Thanks, but not exactly what I need. Let my define some things for you. First, I am modding in Eclipse for Minecraft 1.8.9. Second, I would like for my warrior to hold random CUSTOM weapons, not any ordinary thing like zombies and skeletons in the game. Is it possible to create an array of custom weapons that a method can draw from....? Third, I do want my warrior to attack hostile mobs, ie Endermen, zombies, skeletons, etc. Thanks anyway though
Answers to your questions: yes, yes, yes, and yes.
If you know Java at all, it is absolutely possible to make an array of items that you made. (Preferably do this after initializing them with perhaps a static Item[] in the entity class)
In 1.8.9, add these 2 AI tasks to make your entity target whatever mob you specify (this example targets EntityZombie) :
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityZombie.class, 1.0D, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityZombie.class, true));
Look at the code for the zombie pigman to see how it adds a gold sword on spawn. If setEquipmentBasedOnDifficulty is a 1.9+ thing, use onInitialSpawn.
Edit: here is a link to my GolemBase class so you have an example to work off of. I extend EntityCreature there. Looking at that, I also remembered that you can add this to attack all creatures that implement IMob:
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector));
Answers to your questions: yes, yes, yes, and yes.
If you know Java at all, it is absolutely possible to make an array of items that you made. (Preferably do this after initializing them with perhaps a static Item[] in the entity class)
In 1.8.9, add these 2 AI tasks to make your entity target whatever mob you specify (this example targets EntityZombie) :
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityZombie.class, 1.0D, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityZombie.class, true));
Look at the code for the zombie pigman to see how it adds a gold sword on spawn. If setEquipmentBasedOnDifficulty is a 1.9+ thing, use onInitialSpawn.
Edit: here is a link to my GolemBase class so you have an example to work off of. I extend EntityCreature there. Looking at that, I also remembered that you can add this to attack all creatures that implement IMob:
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector));
Thank you so much! Could you give a could example on how exactly to make the array, and what should I do? Thanks again though!
EDIT: This is not related to the subject, but could you tell me what exactly each paramater in this code block does?
Okay. I have another problem. I have registered my entity, rendered it, and it loads correctly with the tasks and stuff I set, but the model is a blank white rectangle that's about 75% of a block thin, and about the players height. I redid the model and everything, and the texture is set and in the right location. I just can't figure out what's wrong.
The javadocs of that comment can tell you more than I can. From memory, I think the parameters are (Class<? extends Entity> yourEntity, String name, int entityID, Object yourModInstance, int renderDistance, int updateFrequency, boolean sendVelocityUpdates) yourEntity: the class of your entity name: the name of your entity to use in the lang file and /summon entityID: usually starting at 0, MUST be unique for each entity you register for your mod. yourModInstance: an instance of the @Mod file, created as public static and with the @Mod.Instance annotation above it. renderDistance: number of blocks away that your entity will stop rendering. updateFrequency: use the passed value of the most similar class to yours. This is usually between 1-4 sendVelocityUpdates: pass true for fast-moving entities like EntityArrow. passing false will not harm performance for the average entity.
As for an array, I would declare a public static Item[] weapons in the entity class and do something like this after initializing items. Note that there are dozens of ways to create an array, and I'm customizing for my own laziness needs
public static void addItems() // or whatever
{
// add items
// let's pretend you have items magicSword, magicSpear, magicAxe
initWeaponArray(weapons, magicSword, magicSpear, magicAxe);
}
public static void initWeaponArray(Item[] iarray, Item... items)
{
iarray = items;
}
or
public static void addItems() // or whatever
{
// add items
// let's pretend you have items magicSword, magicSpear, magicAxe
weapons = new Item[3];
weapons[0] = magicSword;
weapons[1] = magicSpear;
weapons[2] = magicAxe;
}
or
public static void addItems() // or whatever
{
// add items
// let's pretend you have items magicSword, magicSpear, magicAxe
weapons = new Item[] {magicSword, magicSpear, magicAxe};
}
Okay. I have another problem. I have registered my entity, rendered it, and it loads correctly with the tasks and stuff I set, but the model is a blank white rectangle that's about 75% of a block thin, and about the players height. I redid the model and everything, and the texture is set and in the right location. I just can't figure out what's wrong.
That would be a rendering problem. Show us the render class and where you register it. You should be calling RenderingRegistry.registerEntityRenderingHandler from the FMLPreInitializationEvent, passing it something like this. Although that link is to a helper method, you should be able to figure it out.
Thank you so much! Okay as for the rendering, I do it in the client proxy here:
public class ClientProxy extends CommonProxy {
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public void registerRendering() {
RenderingRegistry.registerEntityRenderingHandler(EntityWarrior.class,
new RenderWarriorMob(Minecraft.getMinecraft().getRenderManager(), new ModelWarrior(), 0.5F));
}
RenderingRegistry.registerEntityRenderingHandler takes an IRenderFactory argument in 1.8+. The deprecated method you are using does not work.
Call something like this from preInit:
RenderingRegistry.registerEntityRenderingHandler(YourEntity.class, new IRenderFactory<YourEntity>()
{
@Override
public Render<? super YourEntity> createRenderFor(RenderManager manager)
{
return new YourRenderType(manager);
}
});
This will also require you to change your Rendering class header like this:
public class YourRenderType extends RenderLiving<YourEntity>
Fix all the errors by using YourEntity in method parameters. You can see how I do all this in my Render class and ClientProxy.
Look at those 2 links and you will hopefully figure out your rendering. Again, call this from the FMLPreInitializationEvent.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
", monospace">RenderingRegistry.registerEntityRenderingHandler takes an ", monospace">IRenderFactory argument in 1.8+. The deprecated method you are using does not work.
Call something like this from preInit:
RenderingRegistry.registerEntityRenderingHandler(YourEntity.class, new IRenderFactory<YourEntity>()
{
@Override
public Render<? super YourEntity> createRenderFor(RenderManager manager)
{
return new YourRenderType(manager);
}
});
This will also require you to change your Rendering class header like this:
public class YourRenderType extends RenderLiving<YourEntity>
Fix all the errors by using YourEntity in method parameters. You can see how I do all this in my Render class and ClientProxy.
Look at those 2 links and you will hopefully figure out your rendering. Again, call this from the ", monospace">FMLPreInitializationEvent.
If you had any idea how helpful this is, you would be dead. THANK YOU SO MUCH!!!! Also, apologies for being such a noob. I am just starting programming and java. So yeah
I am developing a mod, and I want to add a warrior that will randomly wield random custom weapons from my mod. Like for instance, when spawned, this warrior would have a chance of spawning with one of my custom weapons. Say I spawn two warriors, one has a weapon called Venomstrike, the other has a Runic Axe. How would I do this? Don't worry, I know how to code the entity, but I want to know what classes I should extend and what methods should be used. Thanks for the help!
Override EntityLiving#setEquipmentBasedOnDifficulty to generate random equipment for the entity when it first spawns.
EntityMob is probably the best class to extend for hostile mobs.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks, but not exactly what I need. Let my define some things for you. First, I am modding in Eclipse for Minecraft 1.8.9. Second, I would like for my warrior to hold random CUSTOM weapons, not any ordinary thing like zombies and skeletons in the game. Is it possible to create an array of custom weapons that a method can draw from....? Third, I do want my warrior to attack hostile mobs, ie Endermen, zombies, skeletons, etc. Thanks anyway though
Answers to your questions: yes, yes, yes, and yes.
If you know Java at all, it is absolutely possible to make an array of items that you made. (Preferably do this after initializing them with perhaps a static Item[] in the entity class)
In 1.8.9, add these 2 AI tasks to make your entity target whatever mob you specify (this example targets EntityZombie) :
Look at the code for the zombie pigman to see how it adds a gold sword on spawn. If setEquipmentBasedOnDifficulty is a 1.9+ thing, use onInitialSpawn.
Edit: here is a link to my GolemBase class so you have an example to work off of. I extend EntityCreature there. Looking at that, I also remembered that you can add this to attack all creatures that implement IMob:
Thank you so much! Could you give a could example on how exactly to make the array, and what should I do? Thanks again though!
EDIT: This is not related to the subject, but could you tell me what exactly each paramater in this code block does?
Okay. I have another problem. I have registered my entity, rendered it, and it loads correctly with the tasks and stuff I set, but the model is a blank white rectangle that's about 75% of a block thin, and about the players height. I redid the model and everything, and the texture is set and in the right location. I just can't figure out what's wrong.
The javadocs of that comment can tell you more than I can. From memory, I think the parameters are (Class<? extends Entity> yourEntity, String name, int entityID, Object yourModInstance, int renderDistance, int updateFrequency, boolean sendVelocityUpdates)
yourEntity: the class of your entity
name: the name of your entity to use in the lang file and /summon
entityID: usually starting at 0, MUST be unique for each entity you register for your mod.
yourModInstance: an instance of the @Mod file, created as public static and with the @Mod.Instance annotation above it.
renderDistance: number of blocks away that your entity will stop rendering.
updateFrequency: use the passed value of the most similar class to yours. This is usually between 1-4
sendVelocityUpdates: pass true for fast-moving entities like EntityArrow. passing false will not harm performance for the average entity.
As for an array, I would declare a public static Item[] weapons in the entity class and do something like this after initializing items. Note that there are dozens of ways to create an array, and I'm customizing for my own
lazinessneedsor
or
there's other ways too. Just google it.
That would be a rendering problem. Show us the render class and where you register it. You should be calling RenderingRegistry.registerEntityRenderingHandler from the FMLPreInitializationEvent, passing it something like this. Although that link is to a helper method, you should be able to figure it out.
Thank you so much! Okay as for the rendering, I do it in the client proxy here:
I do the registering in the Main class, here:
RenderingRegistry.registerEntityRenderingHandler takes an IRenderFactory argument in 1.8+. The deprecated method you are using does not work.
Call something like this from preInit:
This will also require you to change your Rendering class header like this:
Fix all the errors by using YourEntity in method parameters. You can see how I do all this in my Render class and ClientProxy.
Look at those 2 links and you will hopefully figure out your rendering. Again, call this from the FMLPreInitializationEvent.
If you had any idea how helpful this is, you would be dead. THANK YOU SO MUCH!!!! Also, apologies for being such a noob. I am just starting programming and java. So yeah