Jump to content

Recommended Posts

Posted

Hey,

 

how can i make that when mob is spawned it gain durability for example 100/100, when i hit it take some damage for example 2 than durability should be 98/100, and when i for example pick him with "SHIFT + Right Mouse Button" it comes to me as item which is spawning this mob and this item has mob durability in that case 98/100 and when i spawn him next time by this item it will have 98/100  hp and ofcourse when mob will have 0/100 will die?

 

 

Sorry for my english :)

Posted

Your English is mostly fine. Could do with some punctuation though.

 

The "Durability" you mention is actually the damage mob entities keep anyway, so no worries there. The real issue will be capturing that data to an item, and restoring it to the mob later.

 

Correct me if I am wrong (or if you miss the reference) but I am thinking of this as some sort of Pokeball. You remove the entity from the world with the initial rightclick (checking whether it has NO mob NBT data), saving the current health value (and probably mob type) to the NBT data of said item.

 

When later re-using that item (checking whether it has mob data), the mob should be spawned and its health loaded from the Item's NBT, which I assume at that point should be erased.

 

Tell me if that's a decent summary of your problem, because if so we can start cracking it step by step :)

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Posted

Is your 'Pokémon'-like entity already coded?

Do you have a spawn egg for your entity?

Do you understand how ItemStack NBT works?

 

If you can answer yes to all 3, then the solution should be pretty straightforward:

 

Basically, when you spawn the entity with your egg (or similar item), if the ItemStack has an NBTTagCompound and that tag has a key for 'health' (aka 'durability'), retrieve the value and set the entity's current health to that value after it is spawned.

 

When you snatch the entity into your Pokéball or whatever on right click, store the entity class/type just as the spawn eggs do, and add an NBTTagCompound with the entity's current health as a tag.

Posted

Check out some of my threads, as I do this in a few of them

 

What you are trying to accomplish isnt too difficult, Basically the order should go

 

1)Your Entity should have some sort of stats that set its base HP to be 100 (set this properly using shared attributes, look at #SharedMonsterAttributes.maxHealth) and use 

 @Override
public void writeEntityToNBT(NBTTagCompound nbt)
{ } 

  and

@Override
public void readEntityFromNBT(NBTTagCompound nbt)
{} 

to save all of that stuff properly etc etc ->

 

2)then when your throwable item hits the entity (use)

@Override
protected void onImpact(MovingObjectPosition movingItemPosition) {} 

store the entities NBT data in the Itemstacks NBT and set the entity to dead in the world, ->

 

3) then inside the onItemRightClick method for your item create a dummy instance of your entity

 EntityWhatever whatever = null;

and read the nbt data from your itemstack and "give that data" to your entity before spawning it in world.

 

whatever.readFromNBT(itemStack.stackTagCompound.getCompoundTag("caughtWhatever"));
			whatever.setPosition(x,y+1.5,z);
			whatever.isDead = false; 
                                if(!world.isRemote){                               
                                world.spawnEntityInWorld(whatever);
                                }

 

- pretty simple really. (Thank you Btn is) ---> that way ish :P

 

do all of your appropriate logic checks and all of that, and thats it.

 

Posted

If you use Thornack's method, you store a lot of potentially unnecessary data, but on the other hand, you do store everything about the entity (including any active potion effects, extended properties, etc.).

 

Depending on how your system works, that may be a bane or a boon.

 

Also, if you do it that way, it is very important to set the entity's position before/when you spawn it (as shown in Thornack's code example), otherwise it will spawn in its previous position.

Posted

Is your 'Pokémon'-like entity already coded?

Do you have a spawn egg for your entity?

Do you understand how ItemStack NBT works?

 

If you can answer yes to all 3, then the solution should be pretty straightforward:

 

Basically, when you spawn the entity with your egg (or similar item), if the ItemStack has an NBTTagCompound and that tag has a key for 'health' (aka 'durability'), retrieve the value and set the entity's current health to that value after it is spawned.

 

When you snatch the entity into your Pokéball or whatever on right click, store the entity class/type just as the spawn eggs do, and add an NBTTagCompound with the entity's current health as a tag.

 

Yes, Yes, Yes

 

Check out some of my threads, as I do this in a few of them

 

What you are trying to accomplish isnt too difficult, Basically the order should go

 

1)Your Entity should have some sort of stats that set its base HP to be 100 (set this properly using shared attributes, look at #SharedMonsterAttributes.maxHealth) and use 

 @Override
public void writeEntityToNBT(NBTTagCompound nbt)
{ } 

  and

@Override
public void readEntityFromNBT(NBTTagCompound nbt)
{} 

to save all of that stuff properly etc etc ->

 

2)then when your throwable item hits the entity (use)

@Override
protected void onImpact(MovingObjectPosition movingItemPosition) {} 

store the entities NBT data in the Itemstacks NBT and set the entity to dead in the world, ->

 

3) then inside the onItemRightClick method for your item create a dummy instance of your entity

 EntityWhatever whatever = null;

and read the nbt data from your itemstack and "give that data" to your entity before spawning it in world.

 

whatever.readFromNBT(itemStack.stackTagCompound.getCompoundTag("caughtWhatever"));
			whatever.setPosition(x,y+1.5,z);
			whatever.isDead = false; 
                                if(!world.isRemote){                               
                                world.spawnEntityInWorld(whatever);
                                }

 

- pretty simple really. (Thank you Btn is) ---> that way ish :P

 

do all of your appropriate logic checks and all of that, and thats it.

 

Ok i will try to do it in that way, it seems to me that this is the best option for me because i made something like car.

Posted

If you're not using an Item with #onItemRightClick, you can override the #interact method in your Entity class instead - this method is called when a player right-clicks on the entity, and you can then check if the interacting player is sneaking (i.e. they are holding SHIFT).

 

If neither of those work for you, you have a lot more work to do: subscribe to MouseEvent AND KeyInputEvent (to handle cases where players may have re-bound the use item key), listen for the use-item key (typically right-click), and then, since this is all on the client side, send a packet to the server to trigger your code.

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.

×
×
  • Create New...

Important Information

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