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.

Featured Replies

Posted

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();
}


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.

  • Author

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

}

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.

  • Author

 

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!

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...

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.