Jump to content

Some weird boss health issue


Thor597

Recommended Posts

So, Im making a boss. And it has its health bar. So im using an interface to do some stuff to make it all work. However, when I spawn the boss it dies instantly.

 

Code in Entity File:


/** The maximum health of the Entity. */
protected int maxHealth = 250;

public int getMaxHealth()
{
	return this.maxHealth;
}

protected void entityInit()
{
	super.entityInit();
	this.dataWatcher.addObject(18, new Integer(this.maxHealth));
}

  public void onLivingUpdate()
    {
    	
    	if (!this.worldObj.isRemote)
        {
            this.dataWatcher.updateObject(18, Integer.valueOf(this.health));
        }
}

@SideOnly(Side.CLIENT)

    /**
     * Returns the health points of the dragon.
     */
    public int getBossHP()
    {
        return this.dataWatcher.getWatchableObjectInt(18);
    }

public int getBossMaxHP()
{
	return this.maxHealth;
}

 

AC_IArcticBoss:


package arcticraft.entities;

import net.minecraft.src.*;

public interface AC_IArcticBoss
{
public abstract int getBossHP();

    public abstract int getBossMaxHP();

    public abstract boolean isCurrentBoss();

    public abstract int getBossEntityID();

    public abstract String getBossTitle();

    public abstract Entity GetEntity();
}


Link to comment
Share on other sites

Do you have something like:

this.health = this.maxHealth

in your constructor somewhere?

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.

Link to comment
Share on other sites

Also, how can I get an instance of EntityPlayer in my onDeathUpdate because what I have now is

 

Minecraft.getMinecraft().thePlayer.addChatMessage

 

and the problem with that is that 1. It sends the message 2 times and 2. It will crash on the server so what I need is like

 

if(EntityPlayerInstance instanceof EntityPlayerMP)

{

    EntityPlayerInstance.addChatMessage

}

Link to comment
Share on other sites

Also, how can I get an instance of EntityPlayer in my onDeathUpdate because what I have now is

 

Minecraft.getMinecraft().thePlayer.addChatMessage

 

and the problem with that is that 1. It sends the message 2 times and 2. It will crash on the server so what I need is like

 

if(EntityPlayerInstance instanceof EntityPlayerMP)

{

    EntityPlayerInstance.addChatMessage

}

 

I'm using this in my Clay Soldiers Mod:

private void showChatMessageToAll(String msg) {
	Iterator<EntityPlayer> players = this.worldObj.playerEntities.iterator();
	while(players.hasNext()) {
		EntityPlayer player = players.next();
		if(getDistanceSqToEntity(player) < 32F)
			player.sendChatToPlayer(msg);
	}
}

 

Add this method in your entity and call it where you want. Be sure that this only gets called on the server with checking: worldObj.isRemote == false.

 

One note: this line:

if(getDistanceSqToEntity(player) < 32F)

checks if the players are within the range. If you want to send it to all players on the server, simply remove this line.

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.

Link to comment
Share on other sites

 

Iterator<EntityPlayer> players = this.worldObj.playerEntities.iterator();

		while(players.hasNext())
		{				
			EntityPlayer player = players.next();

			if(player instanceof EntityPlayerMP)
			{
				player.sendChatToPlayer("\247bNooo! SsSsSsStupid HumansSsSsSsSsSs, you will pay for what you've done!");
			}
		}

 

I altered it to this. Thank you!

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.



×
×
  • Create New...

Important Information

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