Jump to content

Recommended Posts

Posted

I've been trying this for a while now. I've looked at skeleton and zombie code, but it calls the addArmor method on spawn with an egg though.

 

Do I need to call the method myself outside of the entity code?

Kain

Posted

If you want to apply armor to a vanilla mob during spawn, use the LivingSpawnEvent.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

I'm overriding that method and adding the armor, but it seems to only be called when I spawn with a spawn egg. If I spawn it naturally, nothing happens.

 

@Override
public IEntityLivingData onSpawnWithEgg(IEntityLivingData par1EntityLivingData) {
	super.onSpawnWithEgg(par1EntityLivingData);
	this.tasks.addTask(4, this.aiArrowAttack);
	this.addRandomArmor();
	this.enchantEquipment();
	return par1EntityLivingData;
}

@Override
protected void addRandomArmor() {
	super.addRandomArmor();
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(4, new ItemStack(Items.leather_helmet));
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(3, new ItemStack(Items.leather_chestplate));
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(2, new ItemStack(Items.leather_leggings));
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(1, new ItemStack(Items.leather_boots));
	this.setCurrentItemOrArmor(0, new ItemStack(Items.bow));
}

Kain

Posted

You could call your addRandomArmor() method within the entityInit() method.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Already tried that, error.

 

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[12:43:46] [server thread/WARN]: Skipping Entity with id 24

at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:233)
at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:173)
at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:79)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)
Caused by: java.lang.NullPointerException
at net.minecraft.entity.EntityLiving.setCurrentItemOrArmor(EntityLiving.java:832)
at realmoffera.entity.EntityGoblinArcherRF.addRandomArmor(EntityGoblinArcherRF.java:72)
at realmoffera.entity.EntityGoblinArcherRF.entityInit(EntityGoblinArcherRF.java:51)
at net.minecraft.entity.Entity.<init>(Entity.java:286)
at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:203)
at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:98)
at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:44)
at net.minecraft.entity.monster.EntityMob.<init>(EntityMob.java:21)
at realmoffera.entity.EntityGoblinArcherRF.<init>(EntityGoblinArcherRF.java:35)
... 19 more
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:233)
at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:173)
at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:79)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)
Caused by: java.lang.NullPointerException
at net.minecraft.entity.EntityLiving.setCurrentItemOrArmor(EntityLiving.java:832)
at realmoffera.entity.EntityGoblinArcherRF.addRandomArmor(EntityGoblinArcherRF.java:75)
at realmoffera.entity.EntityGoblinArcherRF.entityInit(EntityGoblinArcherRF.java:51)
at net.minecraft.entity.Entity.<init>(Entity.java:286)
at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:203)
at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:98)
at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:44)
at net.minecraft.entity.monster.EntityMob.<init>(EntityMob.java:21)
at realmoffera.entity.EntityGoblinArcherRF.<init>(EntityGoblinArcherRF.java:35)
... 19 more

Kain

Posted

Already tried that, error.

 

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[12:43:46] [server thread/WARN]: Skipping Entity with id 24

at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:233)
at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:173)
at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:79)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)
Caused by: java.lang.NullPointerException
at net.minecraft.entity.EntityLiving.setCurrentItemOrArmor(EntityLiving.java:832)
at realmoffera.entity.EntityGoblinArcherRF.addRandomArmor(EntityGoblinArcherRF.java:72)
at realmoffera.entity.EntityGoblinArcherRF.entityInit(EntityGoblinArcherRF.java:51)
at net.minecraft.entity.Entity.<init>(Entity.java:286)
at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:203)
at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:98)
at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:44)
at net.minecraft.entity.monster.EntityMob.<init>(EntityMob.java:21)
at realmoffera.entity.EntityGoblinArcherRF.<init>(EntityGoblinArcherRF.java:35)
... 19 more
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:233)
at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:173)
at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:79)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)
Caused by: java.lang.NullPointerException
at net.minecraft.entity.EntityLiving.setCurrentItemOrArmor(EntityLiving.java:832)
at realmoffera.entity.EntityGoblinArcherRF.addRandomArmor(EntityGoblinArcherRF.java:75)
at realmoffera.entity.EntityGoblinArcherRF.entityInit(EntityGoblinArcherRF.java:51)
at net.minecraft.entity.Entity.<init>(Entity.java:286)
at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:203)
at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:98)
at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:44)
at net.minecraft.entity.monster.EntityMob.<init>(EntityMob.java:21)
at realmoffera.entity.EntityGoblinArcherRF.<init>(EntityGoblinArcherRF.java:35)
... 19 more

 

can I see your code (after manipulating the entityInit method)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted
package realmoffera.entity;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
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.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import realmoffera.UtilRF;
import realmoffera.world.WorldSavedDataRF;

public class EntityGoblinArcherRF extends EntityMob implements IRangedAttackMob {
private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);

public EntityGoblinArcherRF(World world) {
	super(world);
	this.tasks.addTask(1, new EntityAISwimming(this));
	this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
	this.tasks.addTask(6, new EntityAILookIdle(this));
	this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
	this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
	if(world != null && !world.isRemote) {
		this.setCombatTask();
	}
	this.setSize(0.6F, 1.8F);
}

@Override
protected void entityInit() {
	super.entityInit();
	this.addRandomArmor();
	this.enchantEquipment();
}

@Override
public IEntityLivingData onSpawnWithEgg(IEntityLivingData par1EntityLivingData) {
	super.onSpawnWithEgg(par1EntityLivingData);
	this.tasks.addTask(4, this.aiArrowAttack);
	//this.addRandomArmor();
	//this.enchantEquipment();
	return par1EntityLivingData;
}

@Override
protected void addRandomArmor() {
	super.addRandomArmor();
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(4, new ItemStack(Items.leather_helmet));
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(3, new ItemStack(Items.leather_chestplate));
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(2, new ItemStack(Items.leather_leggings));
	if(UtilRF.getChance(1, 3))
		this.setCurrentItemOrArmor(1, new ItemStack(Items.leather_boots));
	this.setCurrentItemOrArmor(0, new ItemStack(Items.bow));
}

@Override
protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(80.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.24000000417232513D);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(0D);
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
}

@Override
protected boolean isAIEnabled() {
	return true;
}

public void setCombatTask() {
	this.tasks.removeTask(this.aiAttackOnCollide);
	this.tasks.removeTask(this.aiArrowAttack);
	this.tasks.addTask(4, this.aiArrowAttack);
}

@Override
protected int getExperiencePoints(EntityPlayer player) {
	return super.getExperiencePoints(player);
}

@Override
public void onLivingUpdate() {
	if(!worldObj.isRemote && !WorldSavedDataRF.forWorld(worldObj).isPostDragon()) {
		this.damageEntity(DamageSource.magic, 1000);
	} else if(!worldObj.isRemote && WorldSavedDataRF.forWorld(worldObj).isPostDragon()) {
	}
	super.onLivingUpdate();
}

@Override
public boolean attackEntityFrom(DamageSource dmgSrc, float par2) {
	if(this.isBurning() && UtilRF.getChance(1, 5) && dmgSrc.getEntity() instanceof EntityLiving) {
		dmgSrc.getEntity().setFire(UtilRF.getRandomIntegerBetween(5, 10));
	}
	return super.attackEntityFrom(dmgSrc, par2);
}

@Override
public EnumCreatureAttribute getCreatureAttribute() {
	return EnumCreatureAttribute.UNDEAD;
}

protected Item getDropItem() {
	return Items.arrow;
}

protected void dropFewItems(boolean par1, int par2) {
	int j;
	int k;
	j = this.rand.nextInt(3 + par2);
	for(k = 0; k < j; ++k) {
		this.dropItem(Items.arrow, 1);
	}
}

@Override
public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2) {
	EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float) (14 - this.worldObj.difficultySetting.getDifficultyId() * 4));
	int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
	int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
	entityarrow.setDamage((double) (par2 * 2.0F) + this.rand.nextGaussian() * 0.25D + (double) ((float) this.worldObj.difficultySetting.getDifficultyId() * 0.11F));
	if(i > 0) {
		entityarrow.setDamage(entityarrow.getDamage() + (double) i * 0.5D + 0.5D);
	}
	if(j > 0) {
		entityarrow.setKnockbackStrength(j);
	}
	if(EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0) {
		entityarrow.setFire(100);
	}
	this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
	this.worldObj.spawnEntityInWorld(entityarrow);
}

public double getYOffset() {
	return super.getYOffset() - 0.5D;
}
}

Kain

Posted

How about you outsource the custom code within addRandomArmor() to a new method (like addCustomArmor()), call that method in addRandomArmor and also in entityInit() (whilst removing the addRandomArmor() from entityInit())

Seems like the super implementation of addRandomArmor() executes a bunch of code which could possibly cause a NPE during entity construction.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.