Solved maxHealth above 20 with 10 displayed hearts

Discussion in 'Plugin Development' started by silthus, Jul 22, 2013.

Thread Status:
Not open for further replies.
  1. Offline



    I am trying to set the maxHealth of a player to 1000 and keep the normal 10 hearts displayed. But it currently displays 500 hearts which fill out a lot of the screen ^^.

    How can I set the health of a player/entity to a higher max value without modifying the hearts display?

    Solution: entity.setScaledHealth(20)
  2. Offline


    Perhaps what you can do is, store their extra health separately, and deduct from it until it is gone, then deduct from their actual health?
  3. Offline


    No idea. Maybe just change the damage things deal to a Lower percentage and it will appear as if they have more health
  4. Offline


    Well of course that would be the "obvious" solution, but in my case also the most complicated one and will be a source of lots and lots of bugs.
    Currently it is good that I use the internal Minecraft health system because other plugins can rely on the set health.
  5. Offline


    I feel this is client side and cannot be fixed. Perhaps, though, you can send a packet with their health instead. Sort of like my suggestion above. If they have over ten, say they have ten, and if less, say what they have. This way it could also be used by other plugins.

    I don't know packets though :D (or how to not send the normal health)
  6. Offline


    Untested and may not work, protocollib needed
    1. private ProtocolManager manager;
    3. @Override
    4. public void onLoad() {
    5. manager = ProtocolLibrary.getProtocolManager();
    6. }
    8. @Override
    9. public void onEnable(){
    10. plugin = this;
    11. manager.addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE,
    12. Packets.Server.UPDATE_HEALTH) {
    14. @Override
    15. public void onPacketSending(PacketEvent event) {
    16. PacketContainer packet = event.getPacket();
    17. byte id = 0x08;
    18. if (event.getPacketID() == id) {
    19. float health = packet.getFloat().read(0);
    20. /*let's say you allowing 60 health max, so you will need divide sent health by 60/20 which is 3*/
    21. packet.getFloat().write(0, (float)(health / 3));
    22. }
    23. }
    24. });
    25. }
    Comphenix and silthus like this.
  7. Offline


    rsod thanks that did the job
  8. Offline


    So with the new Bukkit API Changes there is now the possiblity to setHealthScale(20) in order to only Display a total of 10 hearts.
Thread Status:
Not open for further replies.

Share This Page