Posted October 29, 201213 yr 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(); } http://i.imgur.com/Hppni.png[/img]
October 29, 201213 yr 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.
October 29, 201213 yr 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 } http://i.imgur.com/Hppni.png[/img]
October 29, 201213 yr 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.
October 29, 201213 yr 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! http://i.imgur.com/Hppni.png[/img]
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.