You need to add @EventBusSubscriber(<modid>) above the class, and make sure it is registered in your main class, or change the method to static. Also it might be better to fire it from LivingSpawnEvent (this is what it is called in 1.15, might be something different in 1.12), since that is only called when an entity spawns, rather than any time one gets loaded (also only applies to living entities).
Thanks, It worked perfectly. I replicated the same code for the skeleton, so that the skeleton spawn with diamond armor and a bow enchanted with punch 2. When I tested it diamond armor was perfect but the bow wasn't enchanted.
Here's my class:
package johan24.opmobs.init;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@EventBusSubscriber
public class SkeletonArchers
{
@SubscribeEvent
public static void giveArmor(LivingSpawnEvent event)
{
if (!(event.getEntity() instanceof EntitySkeleton))
{
return;
}
EntitySkeleton skeleton = (EntitySkeleton) event.getEntity();
ItemStack bow = new ItemStack(Items.BOW);
bow.addEnchantment(Enchantments.PUNCH, 2);
skeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, bow);
skeleton.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.DIAMOND_HELMET));
skeleton.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.DIAMOND_CHESTPLATE));
skeleton.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.DIAMOND_LEGGINGS));
skeleton.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.DIAMOND_BOOTS));
}
}
I thought it was a problem with the bow ItemStack, I tested by changing EntityEquipmentSlot.MAINHAND with EntityEquipmentSlot.OFFHAND and it worked!
And I also want the creepers to be charged when they naturally spawn. I am using the same code above except the diamond gear. I don't know what to do next.
For enchanting there should be a method in ItemStack called addEnchantment or something like that which will allow you to add enchantments to the item stack.
If you want it to be enchanted randomly like normally, you can use something like EnchantmentHelper.addRandomEnchantment (this is what it is called in 1.15).
For the creeper, I'm not certain what the method is called in 1.12.2, but there should be a method in EntityCreeper that allows you to set it to a charged creeper.
I searched through the EntityCreeper class but could not find anything related to creeper Charging can you at least tell me the name of the method in 1.15 so I can find something related to it in 1.12.2 EntityCreeper class
In 1.15, you can use the method readAdditional, which takes a CompoundNBT (called NBTTagCompound in 1.12), and set a boolean with the key "powered" to true on the NBT.
Hello, I want zombies to spawn with full diamond armor and a diamond axe when they spawn naturally in the world I created a class for this
and when I tested it didn't work
Here's my class
Please help me with this and correct my mistake.
You need to add @EventBusSubscriber(<modid>) above the class, and make sure it is registered in your main class, or change the method to static. Also it might be better to fire it from LivingSpawnEvent (this is what it is called in 1.15, might be something different in 1.12), since that is only called when an entity spawns, rather than any time one gets loaded (also only applies to living entities).
Uncrafting Table (1.15.2): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/3032965-uncrafting-table
Ruins of Humanity (mod, no longer being developed): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/2898701-1-12-2-wip-early-alpha-ruins-of-humanity
Thanks, It worked perfectly. I replicated the same code for the skeleton, so that the skeleton spawn with diamond armor and a bow enchanted with punch 2. When I tested it diamond armor was perfect but the bow wasn't enchanted.
Here's my class:
I thought it was a problem with the bow ItemStack, I tested by changing EntityEquipmentSlot.MAINHAND with EntityEquipmentSlot.OFFHAND and it worked!
But I, want it in the skeleton's Main Hand.
Please Help
And I also want the creepers to be charged when they naturally spawn. I am using the same code above except the diamond gear. I don't know what to do next.
Please help.
BUMP!
Please help me.
For enchanting there should be a method in ItemStack called addEnchantment or something like that which will allow you to add enchantments to the item stack.
If you want it to be enchanted randomly like normally, you can use something like EnchantmentHelper.addRandomEnchantment (this is what it is called in 1.15).
For the creeper, I'm not certain what the method is called in 1.12.2, but there should be a method in EntityCreeper that allows you to set it to a charged creeper.
Uncrafting Table (1.15.2): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/3032965-uncrafting-table
Ruins of Humanity (mod, no longer being developed): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/2898701-1-12-2-wip-early-alpha-ruins-of-humanity
I searched through the EntityCreeper class but could not find anything related to creeper Charging can you at least tell me the name of the method in 1.15 so I can find something related to it in 1.12.2 EntityCreeper class
In 1.15, you can use the method readAdditional, which takes a CompoundNBT (called NBTTagCompound in 1.12), and set a boolean with the key "powered" to true on the NBT.
Uncrafting Table (1.15.2): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/3032965-uncrafting-table
Ruins of Humanity (mod, no longer being developed): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/2898701-1-12-2-wip-early-alpha-ruins-of-humanity
Sorry for the late reply.
In 1.12.2 I found a method called readEntityFromNBT but I exactly don't know what to do.
what should I type in there instead of compound?
In addition I saw saw something called a DataParameter called POWERED in the creeper class but it was private.
What should I do?
Yeah that looks like the method that should do what you want. Just create a new NBTTagCompound, and set a boolean with true to the key "powered".
So like
Uncrafting Table (1.15.2): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/3032965-uncrafting-table
Ruins of Humanity (mod, no longer being developed): https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/2898701-1-12-2-wip-early-alpha-ruins-of-humanity
Thanks, with your help I was able to complete the class for the creeper.
However, the skeleton did not spawn with the punch II bow. I fixed the problem by changing the LivingSpawnEvent
to EntityJoinWorldEvent and it worked perfectly.
I changed it for zombies and creepers too and works fine.
Thanks for the help you have provided me.