Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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

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

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

  • 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 by Redman

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

show your EntityRenderer please

Edited by Luis_ST

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

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.