Jump to content

Custom Projectile Entity doesnt move


herar123

Recommended Posts

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;
	}
}

 

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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