Posted April 14, 20223 yr 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
April 14, 20223 yr 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
April 14, 20223 yr Author 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.
April 15, 20223 yr 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
April 15, 20223 yr Author 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 April 15, 20223 yr by Redman
April 15, 20223 yr looks okay for me, does the Entity hit box change (F3 + B shows the hit box), show your EntityRenderer please Edited April 15, 20223 yr by Luis_ST
April 15, 20223 yr Author 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....
April 16, 20223 yr 18 hours ago, Redman said: 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 which value did you use as new size?
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.