Hello community! I have been trying to work on my mob, which has proven rather troublesome. My issue is in the title; it doesn't work. Here's the code:
Why do you do all of the potion stuff in event handlers? The potion classes have their own methods for this stuff! Rendering related things can probably stay in there, but for the rest, go look up some tutorials or something. Oh and you don't need 3 separate methods for the LivingUpdateEvent... Just put it in 1!
So where's the code from the first post? I'm guessing the reason for it not working is in that class so I'd need to see that.
tasks.addTask(1, new EntityAISwimming(this));
tasks.addTask(2, new AIDODPunch(this));
tasks.addTask(2, new AIHealDarkness(this));
tasks.addTask(2, new AIEffectPotion(this));
this.tasks.addTask(3, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
tasks.addTask(4, new EntityAIWander(this, 0.8D));
tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8F));
tasks.addTask(6, new EntityAILookIdle(this));
targetTasks.addTask(7, new EntityAIHurtByTarget(this, false));
this.targetTasks.addTask(8, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
@SideOnly(Side.CLIENT)
public float getShadowSize()
{
return this.height / 8.0F;
}
/**
* Returns the sound this mob makes while it's alive.
*/
protected String getLivingSound()
{
return "mob.wither.idle";
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mob.wither.hurt";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mob.wither.death";
}
/**
* Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
*/
public int getTotalArmorValue()
{
return 8;
}
/**
* 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 p_70628_1_, int p_70628_2_)
{
this.dropItem(TUOMItems.darkMace, 1);
this.dropItem(TUOMItems.dopalHelmet, 1);
this.dropItem(TUOMItems.dopalChestplate, 1);
this.dropItem(TUOMItems.dopalLeggings, 1);
this.dropItem(TUOMItems.dopalBoots, 1);
if (!this.worldObj.isRemote)
{
Iterator iterator = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.boundingBox.expand(50.0D, 100.0D, 50.0D)).iterator();
Unfortunately I'm not familiar with AnimationAPI, however why haven't you put that code from the first post in the entity? I'm presuming that animation class is basically to do with rendering the entity like a render class? So you should probably put the code in the entity's onLivingUpdate() (I think it's called that) instead.
Ah thank you very much! I think if I were to do it only in the Animation class, I would have to send a packet that would notify the game to run the code as well as the animation. Thank you, this helps me a lot!
Hello community! I have been trying to work on my mob, which has proven rather troublesome. My issue is in the title; it doesn't work. Here's the code:
private EntityDarkOpalDemon demon;
if (!demon.worldObj.isRemote && demon.getAnimTick() < 2)
{
Iterator iterator = demon.worldObj.getEntitiesWithinAABB(EntityPlayer.class, demon.boundingBox.expand(10.0D, 10.0D, 10.0D)).iterator();
while (iterator.hasNext())
{
EntityPlayer entityplayer = (EntityPlayer)iterator.next();
(( EntityPlayer)entity).addPotionEffect(new PotionEffect(TUOM.darkPotion.id, 100, 1, false));
//Debug
System.out.println("Potion Activated");
}
}
}
[url ="http://www.minecraftforum.net/topic/1066990-hardcore-ender-expansion"]
[I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
[url=http://www.minecraftnoobtest.com/test.php][/url]
To take the test, check out
[url=http://www.minecraftnoobtest.com/test.php]http://minecraftnoobtest.com/test.php[/url]
What doesn't work about it? Do you have a crash report?
Nothing happens. No crash, it's just that it doesn't do anything.
[url ="http://www.minecraftforum.net/topic/1066990-hardcore-ender-expansion"]
[I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
[url=http://www.minecraftnoobtest.com/test.php][/url]
To take the test, check out
[url=http://www.minecraftnoobtest.com/test.php]http://minecraftnoobtest.com/test.php[/url]
So do you see the "Potion Activated" prints in the console? Also can you post your potion class?
I do not;
Potion Event Handler:
package com.tuom.theultimateoremod.events;
import com.tuom.theultimateoremod.main.TUOM;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.EntityViewRenderEvent.FogColors;
import net.minecraftforge.client.event.EntityViewRenderEvent.RenderFogEvent;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
public class PotionEvent {
@SubscribeEvent
public void onEntityUpdate(LivingUpdateEvent e){
if(e.entityLiving.isPotionActive(TUOM.darkPotion)){
if(e.entityLiving.getActivePotionEffect(TUOM.darkPotion).getDuration() == 0 ){
e.entityLiving.removePotionEffect(TUOM.darkPotion.id);
return;
}
else {
e.entityLiving.attackEntityFrom(TUOM.darkDamage, .1F);
e.entityLiving.hurtResistantTime = 7;
}
}
}
public void onEntityUpdateEvent(LivingUpdateEvent event){
if( event.entityLiving.getActivePotionEffect(TUOM.lightPotion).getDuration() == 0){
event.entityLiving.removePotionEffect(TUOM.lightPotion.id);
return;
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled = true)
public void onEvent(EntityViewRenderEvent.FogDensity event){
if(true){
if(event.entity.isPotionActive(TUOM.darkPotion)){
event.density = 1F;
event.setCanceled(true);
}
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority=EventPriority.NORMAL)
public void onEvent(FogColors event){
if(event.entity.isPotionActive(TUOM.darkPotion)){
event.red = -1F;
event.green = -1F;
event.blue = -1F;
}
}
@SubscribeEvent
public void onEvent(LivingUpdateEvent event){
if(event.entityLiving.isPotionActive(TUOM.lightPotion)){
if(event.entityLiving.motionY >= .000000001F){
event.entityLiving.motionY = -1F;
}
}
}
@SubscribeEvent
public void onEvent(FOVUpdateEvent event){
if(event.entity.isPotionActive(TUOM.lightPotion)){
event.newfov = 1F;
}
}
/**
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority=EventPriority.NORMAL)
public void onEvent(RenderGameOverlayEvent event){
if(event.entityLiving.isPotionActive(TUOM.darkPotion)){
}
**/
}
TUOM:
darkPotion = new DarkEffect(25, true, 0).setIconIndex(0, 0).setPotionName("potion.darkEffect").func_111184_a(SharedMonsterAttributes.movementSpeed, "91AEAA56-376B-4498-935B-2F7F68070635", -0.40000000298023224D, 2);;
[url ="http://www.minecraftforum.net/topic/1066990-hardcore-ender-expansion"]
[I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
[url=http://www.minecraftnoobtest.com/test.php][/url]
To take the test, check out
[url=http://www.minecraftnoobtest.com/test.php]http://minecraftnoobtest.com/test.php[/url]
Why do you do all of the potion stuff in event handlers? The potion classes have their own methods for this stuff! Rendering related things can probably stay in there, but for the rest, go look up some tutorials or something. Oh and you don't need 3 separate methods for the LivingUpdateEvent... Just put it in 1!
So where's the code from the first post? I'm guessing the reason for it not working is in that class so I'd need to see that.
I'll do the potion stuff later. I doubt it'll be much help to you (unless you are familiar with AnimationAPI) , but here it is:
AIEffectPotion:
package com.tuom.theultimateoremod.entities.dopaldemon.ai;
import java.util.Iterator;
import com.tuom.theultimateoremod.entities.dopaldemon.EntityDarkOpalDemon;
import com.tuom.theultimateoremod.main.TUOM;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import thehippomaster.AnimationAPI.AIAnimation;
public class AIEffectPotion extends AIAnimation {
private EntityDarkOpalDemon entity;
public AIEffectPotion(EntityDarkOpalDemon test)
{
super(test);
entity = test;
}
public int getAnimID()
{
return 3;
}
public boolean isAutomatic()
{
return true;
}
public int getDuration()
{
return 100;
}
private EntityDarkOpalDemon demon;
private EntityLiving attackTarget;
public void startExecuting()
{
super.startExecuting();
attackTarget = EntityDarkOpalDemon.getAttackTarget;
}
public void updateTask(World world, int x, int y, int z, Entity entity) {
if (!demon.worldObj.isRemote && demon.getAnimTick() < 2)
{
Iterator iterator = demon.worldObj.getEntitiesWithinAABB(EntityPlayer.class, demon.boundingBox.expand(10.0D, 10.0D, 10.0D)).iterator();
while (iterator.hasNext())
{
EntityPlayer entityplayer = (EntityPlayer)iterator.next();
(( EntityPlayer)entity).addPotionEffect(new PotionEffect(TUOM.darkPotion.id, 100, 1, false));
//Debug
System.out.println("Potion Activated");
}
}
}
}
Main Entity Code:
package com.tuom.theultimateoremod.entities.dopaldemon;
import java.util.Iterator;
import com.tuom.theultimateoremod.entities.dopaldemon.ai.AIDODPunch;
import com.tuom.theultimateoremod.entities.dopaldemon.ai.AIDeathAnim;
import com.tuom.theultimateoremod.entities.dopaldemon.ai.AIEffectPotion;
import com.tuom.theultimateoremod.entities.dopaldemon.ai.AIHealDarkness;
import com.tuom.theultimateoremod.main.TUOM;
import com.tuom.theultimateoremod.main.TUOMItems;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
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.ai.attributes.AttributeModifier;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
import thehippomaster.AnimationAPI.AnimationAPI;
import thehippomaster.AnimationAPI.IAnimatedEntity;
import thehippomaster.AnimationExample.AIHeadBang;
import thehippomaster.AnimationExample.AIShakeHead;
public class EntityDarkOpalDemon extends EntityMob implements IBossDisplayData, IAnimatedEntity
{
public static EntityLiving getAttackTarget;
public int animTick;
public int deathTicks;
private int animID;
public EntityDarkOpalDemon(World p_i1738_1_) {
super(p_i1738_1_);
this.setHealth(this.getMaxHealth());
this.setSize(4F, 9F);
this.isImmuneToFire = true;
tasks.addTask(1, new EntityAISwimming(this));
tasks.addTask(2, new AIDODPunch(this));
tasks.addTask(2, new AIHealDarkness(this));
tasks.addTask(2, new AIEffectPotion(this));
this.tasks.addTask(3, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
tasks.addTask(4, new EntityAIWander(this, 0.8D));
tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8F));
tasks.addTask(6, new EntityAILookIdle(this));
targetTasks.addTask(7, new EntityAIHurtByTarget(this, false));
this.targetTasks.addTask(8, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
this.experienceValue = 50;
}
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(2100.0D);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.20000000298023224D);
this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(100.0D);
this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.2D);
}
public boolean isAIEnabled()
{
return true;
}
@SideOnly(Side.CLIENT)
public float getShadowSize()
{
return this.height / 8.0F;
}
/**
* Returns the sound this mob makes while it's alive.
*/
protected String getLivingSound()
{
return "mob.wither.idle";
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mob.wither.hurt";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mob.wither.death";
}
/**
* Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
*/
public int getTotalArmorValue()
{
return 8;
}
/**
* 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 p_70628_1_, int p_70628_2_)
{
this.dropItem(TUOMItems.darkMace, 1);
this.dropItem(TUOMItems.dopalHelmet, 1);
this.dropItem(TUOMItems.dopalChestplate, 1);
this.dropItem(TUOMItems.dopalLeggings, 1);
this.dropItem(TUOMItems.dopalBoots, 1);
if (!this.worldObj.isRemote)
{
Iterator iterator = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.boundingBox.expand(50.0D, 100.0D, 50.0D)).iterator();
while (iterator.hasNext())
{
EntityPlayer entityplayer = (EntityPlayer)iterator.next();
entityplayer.triggerAchievement(TUOM.achievementDark);
}
}
}
public void onLivingUpdate(){
super.onLivingUpdate();
if(this.ticksExisted % 50 == 0){
this.heal(12F);
if(this.getAttackTarget() != null)
switch (this.rand.nextInt(15))
{
case 0:
AnimationAPI.sendAnimPacket(this, 1);
this.setAnimID(1);
System.out.println("Punch");
break;
case 1:
AnimationAPI.sendAnimPacket(this, 3);
this.setAnimID(3);
System.out.println("Potion Invoke");
}
}
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
{
if (!super.attackEntityFrom(p_70097_1_, p_70097_2_))
{
return false;
}
else
{
EntityLivingBase entitylivingbase = this.getAttackTarget();
if (entitylivingbase == null && this.getEntityToAttack() instanceof EntityLivingBase)
{
entitylivingbase = (EntityLivingBase)this.getEntityToAttack();
}
if (entitylivingbase == null && p_70097_1_.getEntity() instanceof EntityLivingBase)
{
entitylivingbase = (EntityLivingBase)p_70097_1_.getEntity();
}
}
return true;
}
/**
* Makes the entity despawn if requirements are reached
*/
protected void despawnEntity()
{
this.entityAge = 0;
}
@SideOnly(Side.CLIENT)
public int getBrightnessForRender(float f)
{
return 15728880;
}
protected void fall(float p_70069_1_) {}
@Override
public void setAnimID(int id) {
animID = id;
}
@Override
public void setAnimTick(int tick) {
animTick = tick;
}
@Override
public int getAnimID() {
return animID;
}
@Override
public int getAnimTick() {
return animTick;
}
public void onUpdate(){
super.onUpdate();
if(animID != 0) animTick++;
}
public boolean attackEntityAsMob(Entity entity) {
if(animID == 0) AnimationAPI.sendAnimPacket(this, 1);
return true;
}
protected void addRandomArmor()
{
this.setCurrentItemOrArmor(0, new ItemStack(TUOMItems.darkMace));
}
/**
* handles entity death timer, experience orb and particle creation
*/
protected void onDeathUpdate()
{
++this.deathTicks;
if(this.deathTicks >= 1)
{
this.worldObj.spawnParticle("largesmoke", this.posX - 2.2D, this.posY + 10D, this.posZ + 1D, 0.0D, 1.0D, 0.0D);
this.worldObj.spawnParticle("largesmoke", this.posX + 2.2D, this.posY + 10D, this.posZ + 1D, 0.0D, 1.0D, 0.0D);
this.worldObj.spawnParticle("portal", this.posX + 2.2D, this.posY + 10D, this.posZ + 1D, 0.0D, 0.0D, 0.0D);
}
if (this.deathTicks >= 180 && this.deathTicks <= 200)
{
float f = (this.rand.nextFloat() - 0.5F) * 8.0F;
float f1 = (this.rand.nextFloat() - 0.5F) * 4.0F;
float f2 = (this.rand.nextFloat() - 0.5F) * 8.0F;
this.worldObj.spawnParticle("hugeexplosion", this.posX + (double)f, this.posY + 2.0D + (double)f1, this.posZ + (double)f2, 0.0D, 0.0D, 0.0D);
}
int i;
int j;
if (!this.worldObj.isRemote)
{
if (this.deathTicks > 150 && this.deathTicks % 5 == 0)
{
i = 1200;
while (i > 0)
{
j = EntityXPOrb.getXPSplit(i);
i -= j;
this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
}
}
}
if (this.deathTicks == 200 && !this.worldObj.isRemote)
{
i = 2000;
while (i > 0)
{
j = EntityXPOrb.getXPSplit(i);
i -= j;
this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
}
this.setDead();
}
}
}
[url ="http://www.minecraftforum.net/topic/1066990-hardcore-ender-expansion"]
[I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
[url=http://www.minecraftnoobtest.com/test.php][/url]
To take the test, check out
[url=http://www.minecraftnoobtest.com/test.php]http://minecraftnoobtest.com/test.php[/url]
Unfortunately I'm not familiar with AnimationAPI, however why haven't you put that code from the first post in the entity? I'm presuming that animation class is basically to do with rendering the entity like a render class? So you should probably put the code in the entity's onLivingUpdate() (I think it's called that) instead.
Ah thank you very much! I think if I were to do it only in the Animation class, I would have to send a packet that would notify the game to run the code as well as the animation. Thank you, this helps me a lot!
[url ="http://www.minecraftforum.net/topic/1066990-hardcore-ender-expansion"]
[I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
[url=http://www.minecraftnoobtest.com/test.php][/url]
To take the test, check out
[url=http://www.minecraftnoobtest.com/test.php]http://minecraftnoobtest.com/test.php[/url]
Yeah I think you're right. That's alright It helps to keep code to do with things in the relevant class.