Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

knokko

Members
  • Joined

  • Last visited

Everything posted by knokko

  1. You probably got an error in you console, show it!
  2. What solved your problem? motionY ?
  3. I think you can better use setInteger and getInteger instead of setTag and getTag. And can you show the whole class code?
  4. You are using an !world.Isremote check, this makes it only works on server. But I think moving the player is client, so remove that first and test it again. And try player.motionY = 1;
  5. here is a part of my working eventhandler. this may help you. @SubscribeEvent public void onEntityDrop(LivingDropsEvent event) { if(event.entityLiving instanceof EntityCow) { event.entityLiving.dropItem(EnderpowerItems.blood, r.nextInt(3)); } I should change EntityCow to EntityMob.
  6. I believe world.playerEntities will give you all the players in the world. you will have to convert the list into players and use this: player.posX... You could play sounds at all players that way. Ask me if you don't know how to get the player instance.
  7. hello, I want to use fireworks in my mod. But I don't know how to make it. I have found a method called "makeFireworks(double, double , double, double, double, double, nbt)", but it didn't work for me. I have tried to summon the fireworksrocket too. I found 2 constructors to summon it. new EntityFireworkRocket(world) and new EntityFireworks(world, double, double, double, itemstack) But I am not going to summon it with an Item. And if I use the (world) constructor, I can't get it explode. Does anybody know how I can create fireworks succesfully?
  8. first, use "system.out.println("The event is fired")" to test the event is fired or not. second, use a class in your parameter, not a method!
  9. replace it with your arrow ITEM or with "Items.arrow".
  10. hello guys, I have found a problem with my mob. If I come to the end with my mob, the game crashes with the next error. "java.lang.IllegalArgumentException: Invalid UUID string: ". It points directly at this method: public void getSummoner() { if(summonerId != null && summonerUUID == null){ summonerUUID = UUID.fromString(summonerId); } if(summonerUUID != null && summoner == null){ summoner = worldObj.func_152378_a(summonerUUID); } if(summonerUUID != null){ summonerId = summonerUUID.toString(); } if(summoner != null && summonerUUID == null){ summonerUUID = summoner.getUniqueID(); } } And the rule that is marked is: "summonerUUID = UUID.fromString(summonerId);". Here is the whole class but I don't think you will need it: public class EntityUndeadMage extends EntityAnimal{ /** * The summoner is the player that has summoned this mob. * This mob is programmed to help the summoner. */ public EntityPlayer summoner; /** * The player name of the summoner. */ public String summonerName; public UUID summonerUUID; /** * The type of magic this mob uses. * 0 = healing * 1 = mixed * 2 = offensive */ public int mageType; double movementSpeed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue(); /** * The current mana the mob has */ public int mobMana; /** * The time this mob can't cast spells. */ public int manaCooldown; public String summonerId; /** * returns true if the mob should follow the summoner. * returns false if the mob should keep on the place where it is. */ public boolean guardSummoner = true; public int fightType; public Entity lastAttacker; public EntityLivingBase target; /** * A required constructor for a mob. * * Do not use this constructor to summon this mob. * Use the constructor world, summoner, mageType, x, y, z. * @param world */ public EntityUndeadMage(World world) { super(world); this.setSize(0.9F, 1.8F); } /** * * @param world - The world the mob has to spawn. * @param summoner - The player that summons this mob. * @param mageType - The type of magic this mob will use. 0 = positive 1 = mixed 2 = offensive * @param x - The X location the mob has to spawn. * @param y - The Y location the mob has to spawn. * @param z - The Z location the mob has to spawn. */ public EntityUndeadMage(World world, EntityPlayer summoner, int mageType, double x, double y, double z){ super(world); this.setSize(0.6F, 1.8F); setPosition(x, y, z); prevPosX = x; prevPosY = y; prevPosZ = z; this.summoner = summoner; this.mageType = mageType; } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } /** * The base attributes of this mob. */ protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return null; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.zombie.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.zombie.hurt"; } protected void func_145780_a(int x, int y, int z, Block block) { this.playSound("mob.zombie.step", 0.15F, 1.0F); } /** * Returns the volume for the sounds this mob makes. */ protected float getSoundVolume() { return 0.4F; } protected Item getDropItem() { return Items.bone; } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ protected void dropFewItems(boolean hitbyplayer, int lootinglevel) { int j = this.rand.nextInt(3) + this.rand.nextInt(1 + lootinglevel); int k; for (k = 0; k < j; ++k) { this.dropItem(Items.bone, 1); } j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + lootinglevel); for (k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Items.skull, 1); } else { this.dropItem(Items.skull, 1); } } } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public EntityUndeadMage createChild(EntityAgeable ageable) { return new EntityUndeadMage(this.worldObj); } public void onUpdate(){ super.onUpdate(); updateMana(); getSummoner(); if(summoner != null){ useMagic(); if(guardSummoner){ followSummoner(); } } } public void getSummoner() { if(summonerId != null && summonerUUID == null){ summonerUUID = UUID.fromString(summonerId); } if(summonerUUID != null && summoner == null){ summoner = worldObj.func_152378_a(summonerUUID); } if(summonerUUID != null){ summonerId = summonerUUID.toString(); } if(summoner != null && summonerUUID == null){ summonerUUID = summoner.getUniqueID(); } } public void useMagic() { if(mageType == 0){ useHealingMagic(); } if(mageType == 1){ useMixedMagic(); } if(mageType == 2){ useOffensiveMagic(); } } public void useOffensiveMagic() { } public void useMixedMagic() { System.out.println(this.target); List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.getLastAttacker() != null && fightType == 0){ this.target = partner.getLastAttacker(); if(!this.target.isPotionActive(2) && mobMana >= 200){ this.target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } if(this.target != null && fightType == 0){ if(!this.target.isPotionActive(2) && mobMana >= 200){ this.target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } public void useHealingMagic() { if(summoner.isBurning() && !summoner.isPotionActive(12) && mobMana >= 200){ summoner.addPotionEffect(new PotionEffect(12, 40)); mobMana -= 200; worldObj.spawnParticle("flame", posX, posY, posZ, 0D, 0D, 0D); } List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.summoner == summoner){ if(partner.isBurning() && !partner.isPotionActive(12)){ if(mobMana >= 200){ partner.addPotionEffect(new PotionEffect(12, 40)); mobMana -= 200; } } if(partner.getHealth() >= 11 && partner.getHealth() <= 19 && !partner.isPotionActive(10) && mobMana >= 20){ partner.addPotionEffect(new PotionEffect(10, 100)); mobMana -= 20; } if(partner.fallDistance >= 4 && mobMana >= 100){ partner.fallDistance = 0; mobMana -= 100; } if(partner.getHealth() <= 10 && partner.getHealth() >= 6 && mobMana >= 100 && !partner.isPotionActive(10)){ partner.addPotionEffect(new PotionEffect(10, 100, 1)); mobMana -= 100; } if(partner.getHealth() <= 10 && partner.getHealth() >= 6 && partner.isPotionActive(10) && mobMana >= 100){ partner.heal(1F); mobMana -= 100; } if(partner.getHealth() <= 5 && partner.getHealth() >= 1 && mobMana >= 500 && !partner.isPotionActive(10)){ partner.addPotionEffect(new PotionEffect(10, 100, 2)); mobMana -= 500; } if(partner.getHealth() <= 5 && partner.getHealth() >= 1 && mobMana >= 1000){ mobMana -= 1000; partner.heal(5F); } } } if(summoner.getHealth() >= 11 && summoner.getHealth() <= 19 && !summoner.isPotionActive(10) && mobMana >= 20){ summoner.addPotionEffect(new PotionEffect(10,100)); mobMana -= 20; } if(summoner.fallDistance >= 4 && mobMana >= 100){ summoner.fallDistance = 0; mobMana -= 100; } if(summoner.getHealth() <= 10 && summoner.getHealth() >= 6 && !summoner.isPotionActive(10) && mobMana >= 100){ summoner.addPotionEffect(new PotionEffect(10, 10, 1)); mobMana -= 100; } if(summoner.getHealth() <= 10 && summoner.getHealth() >= 6 && summoner.isPotionActive(10) && mobMana >= 100){ summoner.heal(1F); mobMana -= 100; } if(summoner.getHealth() <= 5 && summoner.getHealth() >= 1 && !summoner.isPotionActive(10) && mobMana >= 500){ summoner.addPotionEffect(new PotionEffect(10, 100, 2)); mobMana -= 500; } if(summoner.getHealth() <= 5 && summoner.getHealth() >= 1 && mobMana >= 1000){ mobMana -= 1000; summoner.heal(5F); } } public void updateMana() { if(mobMana <= 5000){ mobMana += 1; } if(mobMana >= 5001){ mobMana = 5000; } if(manaCooldown >= 1){ manaCooldown -= 1; } if(manaCooldown <= 0){ manaCooldown = 0; } } public void followSummoner() { if(summoner != null){ if(summoner.posX >= posX + 5){ moveEntity(movementSpeed , 0, 0); } else if(summoner.posX <= posX - 5){ moveEntity(-1 * movementSpeed, 0, 0); } if(summoner.posZ >= posZ + 5){ moveEntity(0, 0, movementSpeed); } else if(summoner.posZ <= posZ - 5){ moveEntity(0, 0, -1 * movementSpeed); } if(this.onGround && summoner.posY >= posY + 2){ moveEntity(0, 3.0, 0); } if(summoner.posX >= posX + 16 || summoner.posX <= posX - 16 ||summoner.posY >= posY + 16 || summoner.posY <= posY - 16 || summoner.posZ >= posZ + 16|| summoner.posZ <= posZ - 16){ if(summoner.onGround || summoner.handleWaterMovement()){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } if(summoner.posX >= posX + 100 || summoner.posX <= posX - 100 || summoner.posZ >= posZ + 100 || summoner.posZ <= posZ - 100){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } } public void writeEntityToNBT(NBTTagCompound nbt){ super.writeEntityToNBT(nbt); if(summoner != null){ nbt.setString("summonerUUID", summonerId); } nbt.setInteger("mobMana", mobMana); nbt.setBoolean("guardSummoner", guardSummoner); nbt.setInteger("mageType", mageType); nbt.setInteger("fightType", fightType); } public void readEntityFromNBT(NBTTagCompound nbt){ super.readEntityFromNBT(nbt); mobMana = nbt.getInteger("mobMana"); summonerId = nbt.getString("summonerUUID"); guardSummoner = nbt.getBoolean("guardSummoner"); mageType = nbt.getInteger("mageType"); fightType = nbt.getInteger("fightType"); } public boolean interact(EntityPlayer player){ if(!worldObj.isRemote){ if(player == summoner){ System.out.println(summoner); System.out.println(summonerUUID); System.out.println(summonerId); ItemStack currentItem = player.inventory.getCurrentItem(); if(currentItem != null){ if(currentItem.getItem() == EnderpowerItems.positiveSpellBook && mageType != 0){ mageType = 0; player.addChatMessage(new ChatComponentTranslation("I am now a healing mage.")); } if(currentItem.getItem() == EnderpowerItems.mixedSpellBook && mageType != 1){ mageType = 1; player.addChatMessage(new ChatComponentTranslation("I am now a mixed mage.")); } if(currentItem.getItem() == EnderpowerItems.offensiveSpellBook && mageType != 2){ mageType = 2; player.addChatMessage(new ChatComponentTranslation("I am now an offensive mage.")); } if(currentItem.getItem() == Items.wooden_sword || currentItem.getItem() == Items.stone_sword || currentItem.getItem() == Items.iron_sword || currentItem.getItem() == Items.golden_sword || currentItem.getItem() == Items.diamond_sword){ if(fightType == 0 && mageType != 0){ fightType = 1; player.addChatMessage(new ChatComponentTranslation("I will attack every mob that attacks you or you attack.")); } } } if(currentItem == null && guardSummoner == true && !worldObj.isRemote){ guardSummoner = false; player.addChatMessage(new ChatComponentTranslation("I will guard it here.")); } else if(currentItem == null && guardSummoner == false && !worldObj.isRemote){ guardSummoner = true; player.addChatMessage(new ChatComponentTranslation("I will follow you now.")); } } } return super.interact(player); } public boolean attackEntityFrom(DamageSource damage, float f){ lastAttacker = damage.getEntity(); return super.attackEntityFrom(damage, f); } }
  11. I think I have found the solution. I have used a trick on LivingHurtEvent. Here is the code of the event, it is in the initializationEvent. please say it if I am doing something stupid. @SubscribeEvent public void hurtEvent(LivingHurtEvent event){ if(event.entityLiving instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer) event.entityLiving; World world = event.entityLiving.worldObj; List UndeadMages = world.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(player.posX - 20, 0, player.posZ - 20, player.posX + 20, 260, player.posZ + 20)); for(int u = 0; u < UndeadMages.size(); ++u){ EntityUndeadMage mage = (EntityUndeadMage) UndeadMages.get(u); if(player == mage.summoner && event.source.getEntity() != null){ mage.target = (EntityLivingBase) event.source.getEntity(); } } } }
  12. I believe summoning lightning at a player is easier. int px = worldObj.getClosestPlayerToEntity(this, 64).posX; That gives you the x position of the player. Do the same with the other positions of the player (posY and posZ); worldObj.addWeatherEffect(new EntityLightningBolt(worldObj, px, py, pz)); you could use that in your onUpdate() method.
  13. I have put the livinghurtevent in my mob class. But now it is a little bit crazy. If my livinghurtevent asks what the target is, it gets the last one who attacked me. But if I ask it in another method, it says there is no target. here is the new part of the code: @SubscribeEvent public void hurtEvent(LivingHurtEvent event){ if(event.entityLiving == summoner && event.source.getEntity() != null){ if(event.source.getEntity() instanceof EntityLivingBase){ this.target = (EntityLivingBase) event.source.getEntity(); System.out.println(this.target); } } } Here is the updated version of the whole class: import java.util.List; import java.util.UUID; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import enderpower.items.EnderpowerItems; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityCow; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; import net.minecraftforge.event.entity.living.LivingHurtEvent; public class EntityUndeadMage extends EntityAnimal{ /** * The summoner is the player that has summoned this mob. * This mob is programmed to help the summoner. */ public EntityPlayer summoner; /** * The player name of the summoner. */ public String summonerName; public UUID summonerUUID; /** * The type of magic this mob uses. * 0 = healing * 1 = mixed * 2 = offensive */ public int mageType; double movementSpeed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue(); /** * The current mana the mob has */ public int mobMana; /** * The time this mob can't cast spells. */ public int manaCooldown; public String summonerId; /** * returns true if the mob should follow the summoner. * returns false if the mob should keep on the place where it is. */ public boolean guardSummoner = true; public int fightType; public Entity lastAttacker; public EntityLivingBase target; /** * A required constructor for a mob. * * Do not use this constructor to summon this mob. * Use the constructor world, summoner, mageType, x, y, z. * @param world */ public EntityUndeadMage(World world) { super(world); this.setSize(0.9F, 1.8F); } /** * * @param world - The world the mob has to spawn. * @param summoner - The player that summons this mob. * @param mageType - The type of magic this mob will use. 0 = positive 1 = mixed 2 = offensive * @param x - The X location the mob has to spawn. * @param y - The Y location the mob has to spawn. * @param z - The Z location the mob has to spawn. */ public EntityUndeadMage(World world, EntityPlayer summoner, int mageType, double x, double y, double z){ super(world); this.setSize(0.6F, 1.8F); setPosition(x, y, z); prevPosX = x; prevPosY = y; prevPosZ = z; this.summoner = summoner; this.mageType = mageType; } @SubscribeEvent public void hurtEvent(LivingHurtEvent event){ if(event.entityLiving == summoner && event.source.getEntity() != null){ if(event.source.getEntity() instanceof EntityLivingBase){ this.target = (EntityLivingBase) event.source.getEntity(); System.out.println(this.target); } } } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } /** * The base attributes of this mob. */ protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return null; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.zombie.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.zombie.hurt"; } protected void func_145780_a(int x, int y, int z, Block block) { this.playSound("mob.zombie.step", 0.15F, 1.0F); } /** * Returns the volume for the sounds this mob makes. */ protected float getSoundVolume() { return 0.4F; } protected Item getDropItem() { return Items.bone; } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ protected void dropFewItems(boolean hitbyplayer, int lootinglevel) { int j = this.rand.nextInt(3) + this.rand.nextInt(1 + lootinglevel); int k; for (k = 0; k < j; ++k) { this.dropItem(Items.bone, 1); } j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + lootinglevel); for (k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Items.skull, 1); } else { this.dropItem(Items.skull, 1); } } } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public EntityUndeadMage createChild(EntityAgeable ageable) { return new EntityUndeadMage(this.worldObj); } public void onUpdate(){ super.onUpdate(); updateMana(); getSummoner(); if(summoner != null){ useMagic(); if(guardSummoner){ followSummoner(); } } } public void getSummoner() { if(summonerId != null && summonerUUID == null){ summonerUUID = UUID.fromString(summonerId); } if(summonerUUID != null && summoner == null){ summoner = worldObj.func_152378_a(summonerUUID); } if(summonerUUID != null){ summonerId = summonerUUID.toString(); } if(summoner != null && summonerUUID == null){ summonerUUID = summoner.getUniqueID(); } } public void useMagic() { if(mageType == 0){ useHealingMagic(); } if(mageType == 1){ useMixedMagic(); } if(mageType == 2){ useOffensiveMagic(); } } public void useOffensiveMagic() { } public void useMixedMagic() { System.out.println(this.target); List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.getLastAttacker() != null && fightType == 0){ this.target = partner.getLastAttacker(); if(!this.target.isPotionActive(2) && mobMana >= 200){ this.target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } if(this.target != null && fightType == 0){ if(!this.target.isPotionActive(2) && mobMana >= 200){ this.target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } public void useHealingMagic() { if(summoner.isBurning() && !summoner.isPotionActive(12) && mobMana >= 200){ summoner.addPotionEffect(new PotionEffect(12, 40)); mobMana -= 200; worldObj.spawnParticle("flame", posX, posY, posZ, 0D, 0D, 0D); } List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.summoner == summoner){ if(partner.isBurning() && !partner.isPotionActive(12)){ if(mobMana >= 200){ partner.addPotionEffect(new PotionEffect(12, 40)); mobMana -= 200; } } if(partner.getHealth() >= 11 && partner.getHealth() <= 19 && !partner.isPotionActive(10) && mobMana >= 20){ partner.addPotionEffect(new PotionEffect(10, 100)); mobMana -= 20; } if(partner.fallDistance >= 4 && mobMana >= 100){ partner.fallDistance = 0; mobMana -= 100; } if(partner.getHealth() <= 10 && partner.getHealth() >= 6 && mobMana >= 100 && !partner.isPotionActive(10)){ partner.addPotionEffect(new PotionEffect(10, 100, 1)); mobMana -= 100; } if(partner.getHealth() <= 10 && partner.getHealth() >= 6 && partner.isPotionActive(10) && mobMana >= 100){ partner.heal(1F); mobMana -= 100; } if(partner.getHealth() <= 5 && partner.getHealth() >= 1 && mobMana >= 500 && !partner.isPotionActive(10)){ partner.addPotionEffect(new PotionEffect(10, 100, 2)); mobMana -= 500; } if(partner.getHealth() <= 5 && partner.getHealth() >= 1 && mobMana >= 1000){ mobMana -= 1000; partner.heal(5F); } } } if(summoner.getHealth() >= 11 && summoner.getHealth() <= 19 && !summoner.isPotionActive(10) && mobMana >= 20){ summoner.addPotionEffect(new PotionEffect(10,100)); mobMana -= 20; } if(summoner.fallDistance >= 4 && mobMana >= 100){ summoner.fallDistance = 0; mobMana -= 100; } if(summoner.getHealth() <= 10 && summoner.getHealth() >= 6 && !summoner.isPotionActive(10) && mobMana >= 100){ summoner.addPotionEffect(new PotionEffect(10, 10, 1)); mobMana -= 100; } if(summoner.getHealth() <= 10 && summoner.getHealth() >= 6 && summoner.isPotionActive(10) && mobMana >= 100){ summoner.heal(1F); mobMana -= 100; } if(summoner.getHealth() <= 5 && summoner.getHealth() >= 1 && !summoner.isPotionActive(10) && mobMana >= 500){ summoner.addPotionEffect(new PotionEffect(10, 100, 2)); mobMana -= 500; } if(summoner.getHealth() <= 5 && summoner.getHealth() >= 1 && mobMana >= 1000){ mobMana -= 1000; summoner.heal(5F); } } public void updateMana() { if(mobMana <= 5000){ mobMana += 1; } if(mobMana >= 5001){ mobMana = 5000; } if(manaCooldown >= 1){ manaCooldown -= 1; } if(manaCooldown <= 0){ manaCooldown = 0; } } public void followSummoner() { if(summoner != null){ if(summoner.posX >= posX + 5){ moveEntity(movementSpeed , 0, 0); } else if(summoner.posX <= posX - 5){ moveEntity(-1 * movementSpeed, 0, 0); } if(summoner.posZ >= posZ + 5){ moveEntity(0, 0, movementSpeed); } else if(summoner.posZ <= posZ - 5){ moveEntity(0, 0, -1 * movementSpeed); } if(this.onGround && summoner.posY >= posY + 2){ moveEntity(0, 3.0, 0); } if(summoner.posX >= posX + 16 || summoner.posX <= posX - 16 ||summoner.posY >= posY + 16 || summoner.posY <= posY - 16 || summoner.posZ >= posZ + 16|| summoner.posZ <= posZ - 16){ if(summoner.onGround || summoner.handleWaterMovement()){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } if(summoner.posX >= posX + 100 || summoner.posX <= posX - 100 || summoner.posZ >= posZ + 100 || summoner.posZ <= posZ - 100){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } } public void writeEntityToNBT(NBTTagCompound nbt){ super.writeEntityToNBT(nbt); if(summoner != null){ nbt.setString("summonerUUID", summonerId); } nbt.setInteger("mobMana", mobMana); nbt.setBoolean("guardSummoner", guardSummoner); } public void readEntityFromNBT(NBTTagCompound nbt){ super.readEntityFromNBT(nbt); mobMana = nbt.getInteger("mobMana"); summonerId = nbt.getString("summonerUUID"); guardSummoner = nbt.getBoolean("guardSummoner"); } public boolean interact(EntityPlayer player){ if(!worldObj.isRemote){ if(player == summoner){ System.out.println(summoner); System.out.println(summonerUUID); System.out.println(summonerId); ItemStack currentItem = player.inventory.getCurrentItem(); if(currentItem != null){ if(currentItem.getItem() == EnderpowerItems.positiveSpellBook && mageType != 0){ mageType = 0; player.addChatMessage(new ChatComponentTranslation("I am now a healing mage.")); } if(currentItem.getItem() == EnderpowerItems.mixedSpellBook && mageType != 1){ mageType = 1; player.addChatMessage(new ChatComponentTranslation("I am now a mixed mage.")); } if(currentItem.getItem() == EnderpowerItems.offensiveSpellBook && mageType != 2){ mageType = 2; player.addChatMessage(new ChatComponentTranslation("I am now an offensive mage.")); } if(currentItem.getItem() == Items.wooden_sword || currentItem.getItem() == Items.stone_sword || currentItem.getItem() == Items.iron_sword || currentItem.getItem() == Items.golden_sword || currentItem.getItem() == Items.diamond_sword){ if(fightType == 0 && mageType != 0){ fightType = 1; player.addChatMessage(new ChatComponentTranslation("I will attack every mob that attacks you or you attack.")); } } } if(currentItem == null && guardSummoner == true && !worldObj.isRemote){ guardSummoner = false; player.addChatMessage(new ChatComponentTranslation("I will guard it here.")); } else if(currentItem == null && guardSummoner == false && !worldObj.isRemote){ guardSummoner = true; player.addChatMessage(new ChatComponentTranslation("I will follow you now.")); } } } return super.interact(player); } public boolean attackEntityFrom(DamageSource damage, float f){ lastAttacker = damage.getEntity(); return super.attackEntityFrom(damage, f); } }
  14. Maybe it will help to show your main class. I do not think somebody can do something bad with your class.
  15. I have used attackEntityFrom() in the mobs own class, the other methods didn't work. And I am not shure I can use LivingHurtEvent for the player. But I can't edit EntityPlayer so I don't know how to get the last attacker.
  16. Getting the last attacker of my mob was really easy. But now the difficult part, getting the last mob that attacked the summoner... But now everybody can see how the code works. I hope somebody knows something that works.
  17. I have seen the options you have said. I am now going to test them. Here is the whole class code in case of I could have made the problem. But the class is really big for a mob... public class EntityUndeadMage extends EntityAnimal{ /** * The summoner is the player that has summoned this mob. * This mob is programmed to help the summoner. */ public EntityPlayer summoner; /** * The player name of the summoner. */ public String summonerName; public UUID summonerUUID; /** * The type of magic this mob uses. * 0 = healing * 1 = mixed * 2 = offensive */ public int mageType; double movementSpeed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue(); /** * The current mana the mob has */ public int mobMana; /** * The time this mob can't cast spells. */ public int manaCooldown; public String summonerId; /** * returns true if the mob should follow the summoner. * returns false if the mob should keep on the place where it is. */ public boolean guardSummoner = true; public int fightType; /** * A required constructor for a mob. * * Do not use this constructor to summon this mob. * Use the constructor world, summoner, mageType, x, y, z. * @param world */ public EntityUndeadMage(World world) { super(world); this.setSize(0.9F, 1.8F); } /** * * @param world - The world the mob has to spawn. * @param summoner - The player that summons this mob. * @param mageType - The type of magic this mob will use. 0 = positive 1 = mixed 2 = offensive * @param x - The X location the mob has to spawn. * @param y - The Y location the mob has to spawn. * @param z - The Z location the mob has to spawn. */ public EntityUndeadMage(World world, EntityPlayer summoner, int mageType, double x, double y, double z){ super(world); this.setSize(0.6F, 1.8F); setPosition(x, y, z); prevPosX = x; prevPosY = y; prevPosZ = z; this.summoner = summoner; this.mageType = mageType; } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } /** * The base attributes of this mob. */ protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.35); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return null; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.zombie.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.zombie.hurt"; } protected void func_145780_a(int x, int y, int z, Block block) { this.playSound("mob.zombie.step", 0.15F, 1.0F); } /** * Returns the volume for the sounds this mob makes. */ protected float getSoundVolume() { return 0.4F; } protected Item getDropItem() { return Items.bone; } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ protected void dropFewItems(boolean hitbyplayer, int lootinglevel) { int j = this.rand.nextInt(3) + this.rand.nextInt(1 + lootinglevel); int k; for (k = 0; k < j; ++k) { this.dropItem(Items.bone, 1); } j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + lootinglevel); for (k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Items.skull, 1); } else { this.dropItem(Items.skull, 1); } } } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public EntityUndeadMage createChild(EntityAgeable ageable) { return new EntityUndeadMage(this.worldObj); } public void onUpdate(){ super.onUpdate(); updateMana(); getSummoner(); if(summoner != null){ useMagic(); if(guardSummoner){ followSummoner(); } } } public void getSummoner() { if(summonerId != null && summonerUUID == null){ summonerUUID = UUID.fromString(summonerId); } if(summonerUUID != null && summoner == null){ summoner = worldObj.func_152378_a(summonerUUID); } if(summonerUUID != null){ summonerId = summonerUUID.toString(); } if(summoner != null && summonerUUID == null){ summonerUUID = summoner.getUniqueID(); } } public void useMagic() { if(mageType == 0){ useHealingMagic(); } if(mageType == 1){ useMixedMagic(); } if(mageType == 2){ useOffensiveMagic(); } } public void useOffensiveMagic() { } public void useMixedMagic() { List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); EntityLivingBase target; for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.getLastAttacker() != null && fightType == 0){ target = partner.getLastAttacker(); if(!target.isPotionActive(2) && mobMana >= 200){ target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } if(summoner.getLastAttacker() != null && fightType == 0){ target = summoner.getLastAttacker(); if(!target.isPotionActive(2) && mobMana >= 200){ target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } public void useHealingMagic() { if(summoner.isBurning() && !summoner.isPotionActive(12) && mobMana >= 200){ summoner.addPotionEffect(new PotionEffect(12, 40)); mobMana -= 200; worldObj.spawnParticle("flame", posX, posY, posZ, 0D, 0D, 0D); } List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.summoner == summoner){ if(partner.isBurning() && !partner.isPotionActive(12)){ if(mobMana >= 200){ partner.addPotionEffect(new PotionEffect(12, 40)); mobMana -= 200; } } if(partner.getHealth() >= 11 && partner.getHealth() <= 19 && !partner.isPotionActive(10) && mobMana >= 20){ partner.addPotionEffect(new PotionEffect(10, 100)); mobMana -= 20; } if(partner.fallDistance >= 4 && mobMana >= 100){ partner.fallDistance = 0; mobMana -= 100; } if(partner.getHealth() <= 10 && partner.getHealth() >= 6 && mobMana >= 100 && !partner.isPotionActive(10)){ partner.addPotionEffect(new PotionEffect(10, 100, 1)); mobMana -= 100; } if(partner.getHealth() <= 10 && partner.getHealth() >= 6 && partner.isPotionActive(10) && mobMana >= 100){ partner.heal(1F); mobMana -= 100; } if(partner.getHealth() <= 5 && partner.getHealth() >= 1 && mobMana >= 500 && !partner.isPotionActive(10)){ partner.addPotionEffect(new PotionEffect(10, 100, 2)); mobMana -= 500; } if(partner.getHealth() <= 5 && partner.getHealth() >= 1 && mobMana >= 1000){ mobMana -= 1000; partner.heal(5F); } } } if(summoner.getHealth() >= 11 && summoner.getHealth() <= 19 && !summoner.isPotionActive(10) && mobMana >= 20){ summoner.addPotionEffect(new PotionEffect(10,100)); mobMana -= 20; } if(summoner.fallDistance >= 4 && mobMana >= 100){ summoner.fallDistance = 0; mobMana -= 100; } if(summoner.getHealth() <= 10 && summoner.getHealth() >= 6 && !summoner.isPotionActive(10) && mobMana >= 100){ summoner.addPotionEffect(new PotionEffect(10, 10, 1)); mobMana -= 100; } if(summoner.getHealth() <= 10 && summoner.getHealth() >= 6 && summoner.isPotionActive(10) && mobMana >= 100){ summoner.heal(1F); mobMana -= 100; } if(summoner.getHealth() <= 5 && summoner.getHealth() >= 1 && !summoner.isPotionActive(10) && mobMana >= 500){ summoner.addPotionEffect(new PotionEffect(10, 100, 2)); mobMana -= 500; } if(summoner.getHealth() <= 5 && summoner.getHealth() >= 1 && mobMana >= 1000){ mobMana -= 1000; summoner.heal(5F); } } public void updateMana() { if(mobMana <= 5000){ mobMana += 1; } if(mobMana >= 5001){ mobMana = 5000; } if(manaCooldown >= 1){ manaCooldown -= 1; } if(manaCooldown <= 0){ manaCooldown = 0; } } public void followSummoner() { if(summoner != null){ if(summoner.posX >= posX + 5){ moveEntity(movementSpeed , 0, 0); } else if(summoner.posX <= posX - 5){ moveEntity(-1 * movementSpeed, 0, 0); } if(summoner.posZ >= posZ + 5){ moveEntity(0, 0, movementSpeed); } else if(summoner.posZ <= posZ - 5){ moveEntity(0, 0, -1 * movementSpeed); } if(this.onGround && summoner.posY >= posY + 2){ moveEntity(0, 3.0, 0); } if(summoner.posX >= posX + 16 || summoner.posX <= posX - 16 ||summoner.posY >= posY + 16 || summoner.posY <= posY - 16 || summoner.posZ >= posZ + 16|| summoner.posZ <= posZ - 16){ if(summoner.onGround || summoner.handleWaterMovement()){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } if(summoner.posX >= posX + 100 || summoner.posX <= posX - 100 || summoner.posZ >= posZ + 100 || summoner.posZ <= posZ - 100){ setPosition(summoner.posX, summoner.posY, summoner.posZ); } } } public void writeEntityToNBT(NBTTagCompound nbt){ super.writeEntityToNBT(nbt); if(summoner != null){ nbt.setString("summonerUUID", summonerId); } nbt.setInteger("mobMana", mobMana); nbt.setBoolean("guardSummoner", guardSummoner); } public void readEntityFromNBT(NBTTagCompound nbt){ super.readEntityFromNBT(nbt); mobMana = nbt.getInteger("mobMana"); summonerId = nbt.getString("summonerUUID"); guardSummoner = nbt.getBoolean("guardSummoner"); } public boolean interact(EntityPlayer player){ if(!worldObj.isRemote){ if(player == summoner){ System.out.println(summoner); System.out.println(summonerUUID); System.out.println(summonerId); ItemStack currentItem = player.inventory.getCurrentItem(); if(currentItem != null){ if(currentItem.getItem() == EnderpowerItems.positiveSpellBook && mageType != 0){ mageType = 0; player.addChatMessage(new ChatComponentTranslation("I am now a healing mage.")); } if(currentItem.getItem() == EnderpowerItems.mixedSpellBook && mageType != 1){ mageType = 1; player.addChatMessage(new ChatComponentTranslation("I am now a mixed mage.")); } if(currentItem.getItem() == EnderpowerItems.offensiveSpellBook && mageType != 2){ mageType = 2; player.addChatMessage(new ChatComponentTranslation("I am now an offensive mage.")); } if(currentItem.getItem() == Items.wooden_sword || currentItem.getItem() == Items.stone_sword || currentItem.getItem() == Items.iron_sword || currentItem.getItem() == Items.golden_sword || currentItem.getItem() == Items.diamond_sword){ if(fightType == 0 && mageType != 0){ fightType = 1; player.addChatMessage(new ChatComponentTranslation("I will attack every mob that attacks you or you attack.")); } } } if(currentItem == null && guardSummoner == true && !worldObj.isRemote){ guardSummoner = false; player.addChatMessage(new ChatComponentTranslation("I will guard it here.")); } else if(currentItem == null && guardSummoner == false && !worldObj.isRemote){ guardSummoner = true; player.addChatMessage(new ChatComponentTranslation("I will follow you now.")); } } } return super.interact(player); } }
  18. I have tested it myself. I have tested it on a zombie. My mob froze the zombie when I hit it. Not when the zombie attacked me. Here is the code for it: You only see this part because I don't think you need the whole code. The method use mixed magic is called every tick if the mage is the right mage. public void useMixedMagic() { List partners = worldObj.getEntitiesWithinAABB(EntityUndeadMage.class, AxisAlignedBB.getBoundingBox(summoner.posX - 20, summoner.posY - 20, summoner.posZ - 20, summoner.posX + 20, summoner.posY + 20, summoner.posZ + 20)); EntityLivingBase target; for (int j = 0; j < partners.size(); ++j){ EntityUndeadMage partner = (EntityUndeadMage) partners.get(j); if(partner.getLastAttacker() != null && fightType == 0){ target = partner.getLastAttacker(); if(!target.isPotionActive(2) && mobMana >= 200){ target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } } if(summoner.getLastAttacker() != null && fightType == 0){ target = summoner.getLastAttacker(); if(!target.isPotionActive(2) && mobMana >= 200){ target.addPotionEffect(new PotionEffect(2, 100, 5)); mobMana -= 200; } } }
  19. hello guys, I am trying to get the mob that has attacked a player the last time. I have used player.getLastAttacker(). But that was the mob that was last attacked by the player. Does anybody know how I can get the mob that has last attacked the player?
  20. You can give a player a potion effect using this method: player.addPotionEffect(new PotionEffect(id, ticks, amplifier)); I use this often.
  21. I hope I understand you good and you want to give the item a nicer name. Create a package called "assets.yourmodid.lang" in src/main/resources. create a file in the new package called "en_US.lang". write in the .lang file "item.THEUNLOCALIZEDNAME.name = the nice name". I believe you can find items this way: ItemRegister.itemname
  22. Thank you, these methods worked, my mob remembers now who has summoned him. And I have directly used something to restore my if I go dead.
  23. What do you want? Modders need to have more info if you want help. I don't even know what you want to do.
  24. I have copied some stuff from EntityTameAble and that did not work. The codes are hardly readable so it is really difficult to find what I need to add. I do not extend it because I ONLY need to save the players UUID to NBT. Now I am saving the player name and I have some time until name changes will be allowed.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.