Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

 

I AM SUS

Posted

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

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.

Announcements



×
×
  • Create New...

Important Information

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