Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10] Entity Stats
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Thornack

[1.7.10] Entity Stats

By Thornack, August 29, 2015 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Thornack    3

Thornack

Thornack    3

  • Dragon Slayer
  • Thornack
  • Members
  • 3
  • 622 posts
Posted August 29, 2015

Hi everyone,

 

So I have a system of stats where I calculate them when an entity is spawned into the world. Then these stats are persistent afterwards but differ from one instance of my entity to another (i introduce randomness to simulate genetic diversity basically). For my stats I have attack, defense, maxHp, currentHP, maxSpeed, and currentSpeed. Now I know that Minecraft has

 

SharedMonsterAttributes.attackDamage
SharedMonsterAttributes.followRange
SharedMonsterAttributes.knockbackResistence
SharedMonsterAttributes.maxHealth
and
SharedMonsterAttributes.movementSpeed

 

I need to set my stats to be the same as minecrafts stats. ie if i calculate HP to be = 10 then minecraft HP should also be 10 or 5 full hearts since from what I understand 1 heart = 2HP? My stats should determine what the minecraft stats are.

 

What would be the best way of doing this, Ive heard of using attribute modifiers but im not really sure I understand the concept of how to use them.

Does anyone have any useful info on this concept, This may seem trivial but i want to make sure i do it properly so I dont get any weird behaviours where my entity calculated stats differ from minecraft stats some of the time in unpredictable ways.

 

Also, as a side how do you set armour amount i havent been able to find that out yet.

  • Quote

Share this post


Link to post
Share on other sites

Thornack    3

Thornack

Thornack    3

  • Dragon Slayer
  • Thornack
  • Members
  • 3
  • 622 posts
Posted August 29, 2015

Some more info,

I have a player and he has a party from which he can spawn entities in his party and swap places with them (literally he morphs into the entity and the entity morphs into him) The models swap, the positions swap, and everything works great on dedicated server and client and integrated server where other players can see the swap occur and the player essentially becomes the party member he chose to morph into. Now I need their stats to be set properly and then I need to trigger their swapping correctly inside my morph method (that part will be easy once I set them properly).

 

so far I tried setting my stats for the player when he morphs in the following way.

 

Pseudocode as my morph function is complicated but essentially I do the following

...
if(shouldBeMorphed){
                        player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(morphEntity.stats.maxHP);
		player.setHealth(morphEntity.stats.currentHP);
		player.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(morphEntity.stats.currentAtt);
                        //then I send a packet so that the speed can be changed client side only as all of the above occurs server side only

}
...

 

Is this the proper way to do this or should I use attribute modifiers and if so how do you go about using those correctly.

  • Quote

Share this post


Link to post
Share on other sites

WitherBoss2000    2

WitherBoss2000

WitherBoss2000    2

  • Tree Puncher
  • WitherBoss2000
  • Members
  • 2
  • 25 posts
Posted August 30, 2015

When you calculate your attributes for the entity, do you store them as a variable? If so,you can write after the fact that the stats are calculated:

 

protected void applyEntityAttributes() {

    super.applyEntityAttributes();

    this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(<whatever you used as your variable>);

}

The code above will make the stats the same as calculated. Repeat the line beginning with this. for each attribute. Also, look at the give command whenever you make a sword that increases your speed. Then, for your morphing, I think that is one of the ways to do it, but maybe instead of doing that, try:

 

public static <name of mob class> mobOne; //Put this after the class declaration line.

 

int mobMaxHealth = mobOne.getEntityAttribute(SharedMonsterAttributes.maxHealth); //put the following in the if statement

player.setHealth(mobMaxHealth);

 

Try that, if the second part doesnt work, I have never tried to change the Player health, but I know it is stored as NBT data. Try it, you dont have to use it, but hopefully that works.

 

  • Quote

I AM SUS

Share this post


Link to post
Share on other sites

Thornack    3

Thornack

Thornack    3

  • Dragon Slayer
  • Thornack
  • Members
  • 3
  • 622 posts
Posted August 30, 2015

My code above works except for speed. I know I ave to set it on client side but whenever my player sprints the speed is reset. I need a way to fix this.

 

player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(myCalculatedValue); <- works but it resets itself when you sprint

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      whenever I join a server it shows me this error

      By diesieben07 · Posted 7 minutes ago

      1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • diesieben07
      Cant Get a Config File Working 1.16.5

      By diesieben07 · Posted 8 minutes ago

      Git is not the right way to store worlds or other large files.   There is no such line in the repository you posted. I used the debugger and put a breakpoint in the FMLCommonSetupEvent handler. Then I used evaluate expression and ArmorConfig.COMMON.enableOakWood.get() was false, as expected.
    • gamer650xd
      whenever I join a server it shows me this error

      By gamer650xd · Posted 12 minutes ago

      crash-2021-01-16_21.37.09-client.txt
    • Bailym
      Cant Get a Config File Working 1.16.5

      By Bailym · Posted 13 minutes ago

      I initially removed the .gitignore because i wanted to preserve the world saves, ill add it back in with the necessary exceptions.   Just to clarify. If you set enableOakWood to false in extraarmor-common.toml the line    System.out.println(ArmorConfig.COMMON.enableOakWood.get()); //Always True   returns false as expected? As i'm not getting the same behavior
    • gamer650xd
      whenever I join a server it shows me this error

      By gamer650xd · Posted 16 minutes ago

      internal exception: com.google.common.util.concurrent.UncheckedExecutionException:net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Minecraft Forge (forge)   crash-2021-01-16_21.37.09-client.txt
  • Topics

    • gamer650xd
      2
      whenever I join a server it shows me this error

      By gamer650xd
      Started 16 minutes ago

    • Bailym
      11
      Cant Get a Config File Working 1.16.5

      By Bailym
      Started 1 hour ago

    • e2rifia
      4
      (1.16.2) How do I use onPlayerTick?

      By e2rifia
      Started 3 hours ago

    • kiou.23
      11
      [1.16] Custom Sign won't render

      By kiou.23
      Started 9 hours ago

    • Ipsissimus418
      1
      [1.16.4] WorldTickEvent Concurrent Access Exception

      By Ipsissimus418
      Started 41 minutes ago

  • Who's Online (See full list)

    • Talp1
    • LeoBeliik
    • diesieben07
    • Kikoz
    • Beethoven92
    • Pl00py_R
    • Bailym
    • gamer650xd
    • vemerion
    • e2rifia
    • KickPotato
    • Boetam
    • Babatunde
    • Linky132
    • Lellian
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10] Entity Stats
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community