Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5]Setting a projectile's size with an argument / changing a projectile size on instantiation


Redman
 Share

Recommended Posts

Hi, i'm trying to make a projectile that could be "charged", that is the item would be clicked and then released, and on release the projectile would spawn with a different size, naturally the longer the item's clicked the bigger the projectile size.

pseudo code would look like that:

releaseUsing(item, world, entity,time){
   //code 
   projectile = new Projectile(size);
   projectile.shoot();
}

but given entity registrations require the attribute "sized(f, f)" ENTITY_TYPES.register("projectile", ()-> {return EntityType.Builder.<Projectile>of(Projectile::new, EntityClassification.MISC).sized(0.25f,0.25f))) is it even possible to change it?

Slimes can "change" size (like there's only one registration of this entity with a size (2,2) ) and they have a method "setSize": https://pastebin.com/hqqvEQRq is it possible to adapt it to a projectile for example ? or are projectileEntities hard coded ? i'm confused

Link to comment
Share on other sites

first of all you need a EntityDataAccessor for the size similar to the Slime
define the EntityDataAccessor in #defineSynchedData via SynchedEntityData#define
then create a method which sets the value of the EntityDataAccessor inside the method you also need to call #reapplyPosition and #refreshDimensions
now to resize the Entity itself you need to override #getDimensions call super and scale the super value based on the EntityDataAccessor value

this was the Entity part but you also need to change the Entity rendering
inside your EntityRenderer you overwrite scale, im not 100% sure but i think you can simply scale the MatrixStack

  • Like 1
Link to comment
Share on other sites

2 hours ago, Luis_ST said:

first of all you need a EntityDataAccessor for the size similar to the Slime
define the EntityDataAccessor in #defineSynchedData via SynchedEntityData#define
then create a method which sets the value of the EntityDataAccessor inside the method you also need to call #reapplyPosition and #refreshDimensions
now to resize the Entity itself you need to override #getDimensions call super and scale the super value based on the EntityDataAccessor value

this was the Entity part but you also need to change the Entity rendering
inside your EntityRenderer you overwrite scale, im not 100% sure but i think you can simply scale the MatrixStack

Thanks a lot! 
By the way, out of curiosity, do I need to respawn the entity, or does it change the size of the already existing entity? Also, someone advised me to use "this.setBoundingBox(this.getBoundingBox().inflate(scale));" what's the difference between the two solutions? Outside of the fact that the bounding box method increases by a flat number.

Link to comment
Share on other sites

15 hours ago, Redman said:

By the way, out of curiosity, do I need to respawn the entity, or does it change the size of the already existing entity?

the code works for all Entities, if the code you use to change the size is backward compatible means if you change the size somewhere where it's possible to have an old Entity

15 hours ago, Redman said:

Also, someone advised me to use "this.setBoundingBox(this.getBoundingBox().inflate(scale));" what's the difference between the two solutions? Outside of the fact that the bounding box method increases by a flat number.

I'm not sure about that either, but #setBoundingBox bypasses EntityEvent.Size which means your entity would always resize even if another mod canceled the event

Link to comment
Share on other sites

Posted (edited)
3 hours ago, Luis_ST said:

the code works for all Entities, if the code you use to change the size is backward compatible means if you change the size somewhere where it's possible to have an old Entity

I'm not sure about that either, but #setBoundingBox bypasses EntityEvent.Size which means your entity would always resize even if another mod canceled the event

I tried, it doesn't work, can you see why ? https://pastebin.com/RDLkWQPb, i'm sure i've missed something.

edit: wrong code
https://pastebin.com/BxTGGC64

Edited by Redman
Link to comment
Share on other sites

3 hours ago, Luis_ST said:

looks okay for me, does the Entity hit box change (F3 + B shows the hit box),

show your EntityRenderer please

I haven't made one yet, i'm just checking by printing things in terminal for now. here's what I get :https://pastebin.com/DHv5Nqqk, as you can see the dimensions and hitbox size don't change, before and after I use setSize() it's annoying cause I don't know why.

worst case I can still have multiple projectile registrations that would be "big" "medium" "small" etc, it's just less organic and optimized than having one variable size....

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

 Share



×
×
  • Create New...

Important Information

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