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.

Featured Replies

Posted

I am implementing a custom projectile that simply goes in a straight line.

Nearly everything about my custom projectile works, except the rotation. I want the projectile to rotate in the direction it is going, like an arrow. This is my source code below. 

public class CustomProjectileEntity extends Projectile implements GeoAnimatable {

    private double shooterX;
    private double shooterY;
    private double shooterZ;
  
    // Constructor is placed here; shooterX, shooterY, and shooterZ are initialized
  
    public void shoot(LivingEntity target, float velocity) {
        double xDir = target.getX() - this.shooterX;
        double yDir = target.getY() - this.shooterY;
        double zDir = target.getZ() - this.shooterZ;
        this.shoot(xDir, yDir, zDir, velocity, 0.0f);
    }

    public void tick() {
        super.tick();
      
        // ...
      
        Vec3 vec3 = this.getDeltaMovement();
        double newX = this.getX() + vec3.x;
        double newY = this.getY() + vec3.y;
        double newZ = this.getZ() + vec3.z;
        this.setDeltaMovement(vec3);
        // this.updateRotation(); // no need because projectile rotation is already initialized in Projectile::shoot!
        this.setPos(newX, newY, newZ);
    }
  
  	// other methods ...

}

You can also see that I created this custom entity with GeckoLib. Other than the code above, is there anything I need to change in the Renderer class?

public class CustomProjectileRenderer extends GeoEntityRenderer<CustomProjectileEntity> {

    public CustomProjectileRenderer(EntityRendererProvider.Context renderManager) {
        super(renderManager, new CustomProjectileModel());
        this.shadowRadius = 0.0f;
    }

    public @NotNull ResourceLocation getTextureLocation(@NotNull CustomProjectileEntity instance) {
        return new ResourceLocation(ExampleMod.MODID, "textures/entity/custom_projectile_texture.png");
    }
  
    // SOLUTION: override GeoEntityRenderer::actuallyRender
      @Override
    public void actuallyRender(PoseStack poseStack, CustomProjectileEntity animatable, BakedGeoModel model, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
        poseStack.mulPose(Axis.YP.rotationDegrees(animatable.getYRot()));
        poseStack.mulPose(Axis.XP.rotationDegrees(-animatable.getXRot()));
        super.actuallyRender(poseStack, animatable, model, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
    }

}

 

Edited by LeeCrafts

  • Author

Solved. I just had to override GeoEntityRenderer::actuallyRender and apply the rotations there. Super.actuallyRender has to be called afterwards (not before).

I think that the reason why I had to do this manually is because my CustomProjectileEntity is not a LivingEntity. I looked at the code in the GeoEntityRenderer class, and its rendering methods apply rotations to entity that are LivingEntities. Kinda explains why the custom mob I had also created with GeckoLib had no issue rotating.

And there's no need to call updateRotation() because the projectile's rotation is already initialized in Projectile::shoot.

Edited by LeeCrafts

  • LeeCrafts changed the title to [1.19.3, SOLVED] Custom projectile does not rotate

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.