Using Geckolib animated model for ranged Item projectile

Started by Techno573 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Using Geckolib animated model for ranged Item projectile

In short, I want to make a ranged item that shoots a projectile that has a geckolib animated model. Is it possible to do this? If yes, how can I do it?

Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes, this is possible. Hereā€¦
Fri, 10/20/2023 - 02:13

Yes, this is possible. Here is what I am using (fabric mappings). I based my code off the code in the Snow Golem. In summary, you need an item representing the projectile, an entity class which extends ThrownItemEntity and implements GeoEntity, as well as the normal classes for Geckolib animated models such as models, renderers, textures, etc.

 

I am still working on this myself. One thing that I am struggling with is figuring out how to rotate the model's MatrixStack witout the game crashing. I will post here when I figure that out.

 

public class BlueBlasterBoltEntity extends ThrownItemEntity implements GeoEntity {
  protected final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

  public BlueBlasterBoltEntity(EntityType<? extends BlueBlasterBoltEntity> entityType, World world) {
    super((EntityType<? extends ThrownItemEntity>) entityType, world);
  }

  public BlueBlasterBoltEntity(World world, LivingEntity owner) {
    super((EntityType<? extends ThrownItemEntity>) EntityRegistry.BLUE_BLASTER_BOLT, owner, world);
  }

  public BlueBlasterBoltEntity(EntityType<? extends ThrownItemEntity> entityType, double d, double e, double f,
      World world) {
    super(entityType, d, e, f, world);
  }

  @Override
  public AnimatableInstanceCache getAnimatableInstanceCache() {
    return this.cache;
  }

  @Override
  public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
  }

  @Override
  protected Item getDefaultItem() {
    return ItemRegistry.BLUE_BLASTER_BOLT_ITEM;
  }

  @Override
  protected void onEntityHit(EntityHitResult entityHitResult) {
    super.onEntityHit(entityHitResult);
    Entity entity = entityHitResult.getEntity();
    int damage = Team.areSameTeam(entity, this.getOwner()) ? 0 : 1;
    entity.damage(this.getDamageSources().thrown(this, this.getOwner()), damage);
  }

  @Override
  protected void onCollision(HitResult hitResult) {
    super.onCollision(hitResult);
    World world = this.getWorld();
    if (!world.isClient) {
      world.sendEntityStatus(this, EntityStatuses.PLAY_DEATH_SOUND_OR_ADD_PROJECTILE_HIT_PARTICLES);
      this.discard();
    }
  }
}