Jump to content

1.10.2 How to make your entity get a potion effect from damage sources.


TheRPGAdventurer

Recommended Posts

Rather than making the entity immune to fire, I would hook into the LivingEvent.LivingHurtEvent. This way you can cancel all fire damage for your entity like you want, but you can also apply potion effects if the DamageSource is fire damage.

 

For instance:

 

@SubscribeEvent
public void handleFirePotion(LivingEvent.LivingHurtEvent event) {
  if (event.getSource().isFireDamage() && event.getEntityLiving() instanceof EntityNetherDragon) {
    event.getEntityLiving().addPotionEffect(new PotionEffect(...));
    event.setCanceled(true);
  }
}

 

Fill in the PotionEffect's constructor as needed, of course.

Edited by IceMetalPunk
Gave example

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

Rather than making the entity immune to fire, I would hook into the LivingEvent.LivingHurtEvent. This way you can cancel all fire damage for your entity like you want, but you can also apply potion effects if the DamageSource is fire damage.

 

For instance:

 


@SubscribeEvent
public void handleFirePotion(LivingEvent.LivingHurtEvent event) {
  if (event.getSource().isFireDamage() && event.getEntityLiving() instanceof EntityNetherDragon) {
    event.getEntityLiving().addPotionEffect(new PotionEffect(...));
    event.setCanceled(true);
  }
}

 

Fill in the PotionEffect's constructor as needed, of course.

Where do I put these btw, is it in the nether dragon class or in the main mod class?

Link to comment
Share on other sites

Just now, IceMetalPunk said:

Neither. Look up how to create and use event handlers with Forge; they'll come in very useful for you in the future :)

Question, how do skeletons handle it's spawning, cause wither skeletons and ordinary skeletons are spawned in different Dimensions. Does Minecraft have a main class also?

Link to comment
Share on other sites

6 minutes ago, TheRPGAdventurer said:

Question, how do skeletons handle it's spawning, cause wither skeletons and ordinary skeletons are spawned in different Dimensions. Does Minecraft have a main class also?

Yes, but that's not where you should be looking for spawning data. For spawning of custom entities, you should be using the Forge method EntityRegistry.addSpawn(entityClass, weightedProb, min, max, typeOfCreature, biomes).
 

So for instance, to add your NetherDragon to the Nether, spawning in groups of 1 to 3 often, keeping in mind the Nether's biome is called HELL, you'd do something like this:

 

EntityRegistry.addSpawn(EntityNetherDragon.class, 1.0f, 1, 3, EnumCreatureType.MONSTER, Biomes.HELL);

 

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

Yes, but that's not where you should be looking for spawning data. For spawning of custom entities, you should be using the Forge method EntityRegistry.addSpawn(entityClass, weightedProb, min, max, typeOfCreature, biomes).
 

So for instance, to add your NetherDragon to the Nether, spawning in groups of 1 to 3 often, keeping in mind the Nether's biome is called HELL, you'd do something like this:

 


EntityRegistry.addSpawn(EntityNetherDragon.class, 1.0f, 1, 3, EnumCreatureType.MONSTER, Biomes.HELL);

 

Ok here's my problem, My dragon has a main class called EntityTameableDragon, and it is separated into 6 different breeds Sapphire,Jade,Amethyst,END(ender dragon) the nether dragon is one of them, and each breed has it's own class, and all the breeds has an enum called EnumDragonBreed.class,  much like the skeleton, The problem is when I use the code below, it just spawns it with the default breed called END which is the ender dragon, what I want to achieve is to spawn the "gem" type dragons in the overworld extreme hills and spawn the nether dragon in the nether and the end can only be obtained by killing the ender dragon(vanilla) and hatching the dragon egg. this mod is not really mine, it's from dragon mounts mod and I'm trying to revive it.

EntityRegistry.addSpawn(EntityTameableDragon.class, 1.0f, 1, 3, EnumCreatureType.MONSTER, Biomes.HELL);
Link to comment
Share on other sites

4 minutes ago, TheRPGAdventurer said:

Ok here's my problem, My dragon has a main class called EntityTameableDragon, and it is separated into 6 different breeds Sapphire,Jade,Amethyst,END(ender dragon) the nether dragon is one of them, and each breed has it's own class, and all the breeds has an enum called EnumDragonBreed.class,  much like the skeleton, The problem is when I use the code below, it just spawns it with the default breed called END which is the ender dragon, what I want to achieve is to spawn the "gem" type dragons in the overworld extreme hills and spawn the nether dragon in the nether and the end can only be obtained by killing the ender dragon(vanilla) and hatching the dragon egg. this mod is not really mine, it's from dragon mounts mod and I'm trying to revive it.


EntityRegistry.addSpawn(EntityTameableDragon.class, 1.0f, 1, 3, EnumCreatureType.MONSTER, Biomes.HELL);

The EntityLiving class contains a method called onInitialSpawn which is called the first time an entity spawns and never again for that instance of the entity. You can override that to check the biome the entity is currently in and set the data accordingly.

Edited by IceMetalPunk
  • Like 1

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

The EntityLiving class contains a method called onInitialSpawn which is called the first time an entity spawns and never again for that instance of the entity. You can use that to check the biome the entity is currently in and set the data accordingly.

So you mean like the onInitialSpawn will set what breeds to use and then forge will now use it instead of using the default breed?

Link to comment
Share on other sites

No... onInitialSpawn is just a method that will be called on your entity whenever it spawns in the world. It's up to you to put the code in that method to check the biome, set the breed data, and do whatever else you need your entity to do whenever it spawns.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

No... onInitialSpawn is just a method that will be called on your entity whenever it spawns in the world. It's up to you to put the code in that method to check the biome, set the breed data, and do whatever else you need your entity to do whenever it spawns.

Do I still have to use the GameRegistry Forge Method?

Edited by TheRPGAdventurer
Wrong Grammar
Link to comment
Share on other sites

Which method of GameRegsitry, and for what?

 

It seems perhaps there are basic concepts of both Java and Forge that you aren't quite familiar with. I'd suggest starting smaller, with some more basic mods and watching/reading tutorials on how to make a basic mod first. Once you're comfortable with that, then move on to larger projects like trying to update an existing dragon-taming mod.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

Which method of GameRegsitry, and for what?

 

It seems perhaps there are basic concepts of both Java and Forge that you aren't quite familiar with. I'd suggest starting smaller, with some more basic mods and watching/reading tutorials on how to make a basic mod first. Once you're comfortable with that, then move on to larger projects like trying to update an existing dragon-taming mod.

also I found a bug in the original mod when he sets his biomes for which his egg will change breeds the mob will also spawn.

Link to comment
Share on other sites

Just now, TheRPGAdventurer said:

also I found a bug in the original mod when he sets his biomes for which his egg will change breeds the mob will also spawn.

 

Just now, IceMetalPunk said:

Which method of GameRegsitry, and for what?

 

It seems perhaps there are basic concepts of both Java and Forge that you aren't quite familiar with. I'd suggest starting smaller, with some more basic mods and watching/reading tutorials on how to make a basic mod first. Once you're comfortable with that, then move on to larger projects like trying to update an existing dragon-taming mod.

Ok it worked but the problem is I can only set it on two breeds but how do I do it? https://pastebin.com/FXfuWZvE

Link to comment
Share on other sites

Just now, IceMetalPunk said:

The EntityLiving class contains a method called onInitialSpawn which is called the first time an entity spawns and never again for that instance of the entity. You can override that to check the biome the entity is currently in and set the data accordingly.

also what does weightProbability do?

Link to comment
Share on other sites

You can set it to as many breeds as you want. Remember that you can use "else if" statements in Java.

weightedProb determines the chance that this particular mob will spawn instead of a different mob that can spawn in the same biome. So for instance, if your dragon could spawn, or a skeleton could spawn, giving your dragon a higher weightedProb makes it more likely the game will spawn your dragon instead of a skeleton.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

You can set it to as many breeds as you want. Remember that you can use "else if" statements in Java.

weightedProb determines the chance that this particular mob will spawn instead of a different mob that can spawn in the same biome. So for instance, if your dragon could spawn, or a skeleton could spawn, giving your dragon a higher weightedProb makes it more likely the game will spawn your dragon instead of a skeleton.

Now I found my mistake, I only used else without if.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

You can set it to as many breeds as you want. Remember that you can use "else if" statements in Java.

weightedProb determines the chance that this particular mob will spawn instead of a different mob that can spawn in the same biome. So for instance, if your dragon could spawn, or a skeleton could spawn, giving your dragon a higher weightedProb makes it more likely the game will spawn your dragon instead of a skeleton.

I just copy pasted this from the skeleton, if (biome instanceof BiomeHills && this.worldObj.canSeeSky(new BlockPos(this)) && this.rand.nextInt(6) != 0)
        {this.setBreedType(EnumDragonBreed.RUBY);

what does  && this.rand.nextInt(6) != 0 do.

Link to comment
Share on other sites

5 minutes ago, TheRPGAdventurer said:

I just copy pasted this from the skeleton, if (biome instanceof BiomeHills && this.worldObj.canSeeSky(new BlockPos(this)) && this.rand.nextInt(6) != 0)
        {this.setBreedType(EnumDragonBreed.RUBY);

what does  && this.rand.nextInt(6) != 0 do.

&& means "and". this.rand is a random number generator, which all Entities have. nextInt(int X) is a method of Java's random number generators that generates a random integer from 0 to X-1. != means "not equal to". So this uses the entity's random number generator to pick a random integer from 0 to 5 and check that it's not 0. Which means it creates a 5/6 chance of the condition being true, and a 1/6 chance of it being false. In other words, in this case, 5/6 of the dragons in the hills will be Ruby type, while 1/6 will not.

Edited by IceMetalPunk
  • Like 1

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

 

Just now, IceMetalPunk said:

&& means "and". this.rand is a random number generator, which all Entities have. nextInt(int X) is a method of Java's random number generators that generates a random integer from 0 to X-1. != means "not equal to". So this uses the entity's random number generator to pick a random integer from 0 to 5 and check that it's not 0. Which means it creates a 5/6 chance of the condition being true, and a 1/6 chance of it being false. In other words, in this case, 5/6 of the dragons in the hills will be Ruby type, while 1/6 will not.

what if I put != 5 here is the enumDragonBreed class https://pastebin.com/gvrSag9r

Link to comment
Share on other sites

Just now, TheRPGAdventurer said:

 

what if I put != 5 here is the enumDragonBreed class https://pastebin.com/gvrSag9r

It'd be the same thing. Picking a random integer between 0 and 5 gives you a 1/6 chance of picking any particular one of those numbers; if you're checking that it hasn't picked just one of them, the value you choose to compare against doesn't matter, it will still be the same 1/6 chance of being false.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

It'd be the same thing. Picking a random integer between 0 and 5 gives you a 1/6 chance of picking any particular one of those numbers; if you're checking that it hasn't picked just one of them, the value you choose to compare against doesn't matter, it will still be the same 1/6 chance of being false.

the reason I try to put != 5 because it still spawns with the default breed called END. here is the OnInitialSpawn Method, https://pastebin.com/LAipzhK6

Edited by TheRPGAdventurer
forgot something
Link to comment
Share on other sites

1 minute ago, TheRPGAdventurer said:

the reason I try to put != 5 because it still spawns with the default breed called END.

That entire line is all evaluated before deciding whether it should use the Ruby type.

 if (biome instanceof BiomeHills && this.worldObj.canSeeSky(new BlockPos(this)) && this.rand.nextInt(6) != 0)

 

Which means if it spawns outside the hills biome, if there are any blocks above it when it spawns (so it can't see the sky directly), or if there happens to be a 1/6 chance on the random number result.... if any of those things are true, it won't use the Ruby type. So you might want to check all those conditions with some console output (using, for instance, the System.out.println() method) to see which is failing.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Just now, IceMetalPunk said:

That entire line is all evaluated before deciding whether it should use the Ruby type.

 if (biome instanceof BiomeHills && this.worldObj.canSeeSky(new BlockPos(this)) && this.rand.nextInt(6) != 0)

 

Which means if it spawns outside the hills biome, if there are any blocks above it when it spawns (so it can't see the sky directly), or if there happens to be a 1/6 chance on the random number result.... if any of those things are true, it won't use the Ruby type. So you might want to check all those conditions with some console output (using, for instance, the System.out.println() method) to see which is failing.

Dude side note, it does spawn but the problem is it spawns every breed in the overworld except nether and ruby, my problem is that END still spawns aside with others and I can't see any rubies. 

Link to comment
Share on other sites

Just now, IceMetalPunk said:

That entire line is all evaluated before deciding whether it should use the Ruby type.

 if (biome instanceof BiomeHills && this.worldObj.canSeeSky(new BlockPos(this)) && this.rand.nextInt(6) != 0)

 

Which means if it spawns outside the hills biome, if there are any blocks above it when it spawns (so it can't see the sky directly), or if there happens to be a 1/6 chance on the random number result.... if any of those things are true, it won't use the Ruby type. So you might want to check all those conditions with some console output (using, for instance, the System.out.println() method) to see which is failing.

If i put == 0 will it include 0?

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.