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

Hello,

I have created my own projectile, with a custom model, and use geckolib to render it. However I am not able to get it to move. It has a deltaMovement, but getPos() always gives the same values and its rendered on the same spot.
Ive tried using .shoot or change have its movement changed in its tick() method but nothing seems to work.
Im probably missing one line of code important to get projectiles to move.

Thank you

 

public class RocketProjectile extends Projectile implements IAnimatable {
	private boolean hasTarget = false;
	private boolean followEntity;
	private LivingEntity targetE;
	private Vec3 targetV;
	private int delay = 20;
	private int particle = 0;
	
	private int test = 0;

	public RocketProjectile(EntityType<? extends Projectile> entity, Level level) {
		super(entity, level);
	}

	@Override
	protected void defineSynchedData() {
	}
	
	public void setTarget(Vec3 pos) {
		followEntity = false;
		targetV = pos;
		hasTarget = true;
	}
	
	public void setTarget(LivingEntity target) {
		followEntity = true;
		targetE = target;
		hasTarget = true;
	}

	@Override
	public void tick() {
		super.tick();
		if(!hasTarget) {
			try {
				targetE = level.getNearestPlayer(this, 100f);
				if(targetE!=null) hasTarget = true; followEntity = true;
			} catch(Exception e) {}
		} else if(delay > -1){
			delay--;
		}
		if(hasTarget && delay < 0) {
			Vec3 target;
			if(followEntity) {
				target = targetE.getEyePosition();
			} else {
				target = targetV;
			}
			Vec3 dir = target.subtract(this.getPosition(1f)).normalize();
			if(!level.isClientSide()) this.setDeltaMovement(dir.multiply(1,1,1));
		}
	}

	@Override
	protected void onHitBlock(BlockHitResult p_37258_) {
		super.onHitBlock(p_37258_);
		
	}
	
	@Override
	protected void onHitEntity(EntityHitResult p_37259_) {
		super.onHitEntity(p_37259_);
		
	}

	@Override
	protected void readAdditionalSaveData(CompoundTag p_20052_) {
		
	}

	@Override
	protected void addAdditionalSaveData(CompoundTag p_20139_) {
		
	}

	@Override
	public Packet<?> getAddEntityPacket() {
		return NetworkHooks.getEntitySpawningPacket(this);
	}

	//geckolib
	private final AnimationFactory factory = new AnimationFactory(this);
		
	@Override
	public void registerControllers(AnimationData data) {
		data.addAnimationController(new AnimationController<RocketProjectile>(this, "empty", 0, this::empty));
	}
	
	private <E extends IAnimatable> PlayState empty(AnimationEvent<E> event) {
		return PlayState.CONTINUE;
	}

	@Override
	public AnimationFactory getFactory() {
		return factory;
	}
}

 

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.