Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] vehicle entity


Recommended Posts

Hello good, I am trying to move the entity of the vehicle, almost everything is ready but it does not move, someone can help me.

package com.brok.brokmod.client.render.entity;

import net.minecraft.block.BlockState;
import net.minecraft.entity.*;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.IPacket;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkHooks;

import javax.annotation.Nonnull;


public class CarBrokEntity extends CreatureEntity{


	public CarBrokEntity(EntityType<? extends CreatureEntity> type, World worldIn) {
		super(type, worldIn);
		experienceValue = 0;
		setNoAI(true);
		enablePersistence();


	}
	@Override
	public void travel(@Nonnull Vector3d pos) {
		LivingEntity entity = this;
		float forward = entity.moveForward;
		float strafe = 0;
		pos = new Vector3d (strafe, 0 ,forward);

		if (this.isBeingRidden()) {

			entity.rotationYaw = this.rotationYaw;
			entity.prevRotationYaw = this.rotationYaw;
			entity.rotationPitch = this.rotationPitch * 0.5F;
			this.setRotation(entity.rotationYaw, entity.rotationPitch);
			entity.renderYawOffset = this.rotationYaw;
			entity.rotationYawHead = this.rotationYaw;
			entity.stepHeight = 1.0F;
			this.move(MoverType.PLAYER, pos);
			super.travel(pos);
			entity.prevLimbSwingAmount = this.limbSwingAmount;
			double d1 = 1.0D;
			double d0 = 1.0D;
			float f1 = MathHelper.sqrt(d1 * d1 + d0 * d0) * 4.0F;
			if (f1 > 1.0F) f1 = 1.0F;
			entity.limbSwingAmount += (f1 - this.limbSwingAmount) * 0.4F;
			entity.limbSwing += this.limbSwingAmount;
			return;
		}
		entity.stepHeight = 0.5F;
		super.travel(pos);
	}


	@Nonnull
	@Override
	public ActionResultType func_230254_b_(@Nonnull PlayerEntity sourcePlayer, @Nonnull Hand hand) {

		ActionResultType resultType = ActionResultType.func_233537_a_(this.world.isRemote());
		super.func_230254_b_(sourcePlayer, hand);
		sourcePlayer.startRiding(this);

		return resultType;
	}
	@Override
	public boolean canDespawn(double distanceToClosestPlayer) {
		return false;
	}

	@Nonnull
	@Override
	public IPacket<?> createSpawnPacket() {
		return NetworkHooks.getEntitySpawningPacket(this);
	}

	@OnlyIn(Dist.CLIENT)
	public static AttributeModifierMap.MutableAttribute mutableAttributeCarBrok(){
		return CreatureEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 10.0D)
				.createMutableAttribute(Attributes.ATTACK_DAMAGE, 2.0D)
				.createMutableAttribute(Attributes.ATTACK_SPEED, 1.0D)
				.createMutableAttribute(Attributes.ATTACK_KNOCKBACK, 1.0D)
				.createMutableAttribute(Attributes.MOVEMENT_SPEED, 1.0D);
		
	}
	@Nonnull
	@Override
	public CreatureAttribute getCreatureAttribute() {
		return CreatureAttribute.UNDEFINED;
	}

	@Override
	protected int getExperiencePoints(@Nonnull PlayerEntity player) {

		return 1 + this.world.rand.nextInt(5);
	}
	@Override
	public void playStepSound(@Nonnull BlockPos pos, @Nonnull BlockState blockIn) {

		this.playSound(SoundEvents.BLOCK_METAL_STEP, 0.25F, 1.0F);
	}

	@Override
	public SoundEvent getHurtSound(@Nonnull DamageSource ds) {

		return SoundEvents.BLOCK_METAL_BREAK;
	}

	@Override
	public SoundEvent getDeathSound() {

		return SoundEvents.BLOCK_METAL_BREAK;
	}
	@Override
	protected SoundEvent getAmbientSound() {

		return SoundEvents.AMBIENT_WARPED_FOREST_LOOP;
	}



}

 

Link to post
Share on other sites

You will need to override the travel method. There is a good example of this in the AbstractHorseEntity class.

public void travel(Vector3d travelVector) {
      if (this.isAlive()) {
         if (this.isBeingRidden() && this.canBeSteered() && this.isHorseSaddled()) {
            LivingEntity livingentity = (LivingEntity)this.getControllingPassenger();
            this.rotationYaw = livingentity.rotationYaw;
            this.prevRotationYaw = this.rotationYaw;
            this.rotationPitch = livingentity.rotationPitch * 0.5F;
            this.setRotation(this.rotationYaw, this.rotationPitch);
            this.renderYawOffset = this.rotationYaw;
            this.rotationYawHead = this.renderYawOffset;
            float f = livingentity.moveStrafing * 0.5F;
            float f1 = livingentity.moveForward;
            if (f1 <= 0.0F) {
               f1 *= 0.25F;
               this.gallopTime = 0;
            }

            if (this.onGround && this.jumpPower == 0.0F && this.isRearing() && !this.allowStandSliding) {
               f = 0.0F;
               f1 = 0.0F;
            }

            if (this.jumpPower > 0.0F && !this.isHorseJumping() && this.onGround) {
               double d0 = this.getHorseJumpStrength() * (double)this.jumpPower * (double)this.getJumpFactor();
               double d1;
               if (this.isPotionActive(Effects.JUMP_BOOST)) {
                  d1 = d0 + (double)((float)(this.getActivePotionEffect(Effects.JUMP_BOOST).getAmplifier() + 1) * 0.1F);
               } else {
                  d1 = d0;
               }

               Vector3d vector3d = this.getMotion();
               this.setMotion(vector3d.x, d1, vector3d.z);
               this.setHorseJumping(true);
               this.isAirBorne = true;
               net.minecraftforge.common.ForgeHooks.onLivingJump(this);
               if (f1 > 0.0F) {
                  float f2 = MathHelper.sin(this.rotationYaw * ((float)Math.PI / 180F));
                  float f3 = MathHelper.cos(this.rotationYaw * ((float)Math.PI / 180F));
                  this.setMotion(this.getMotion().add((double)(-0.4F * f2 * this.jumpPower), 0.0D, (double)(0.4F * f3 * this.jumpPower)));
               }

               this.jumpPower = 0.0F;
            }

            this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;
            if (this.canPassengerSteer()) {
               this.setAIMoveSpeed((float)this.getAttributeValue(Attributes.MOVEMENT_SPEED));
               super.travel(new Vector3d((double)f, travelVector.y, (double)f1));
            } else if (livingentity instanceof PlayerEntity) {
               this.setMotion(Vector3d.ZERO);
            }

            if (this.onGround) {
               this.jumpPower = 0.0F;
               this.setHorseJumping(false);
            }

            this.func_233629_a_(this, false);
         } else {
            this.jumpMovementFactor = 0.02F;
            super.travel(travelVector);
         }
      }
   }

 

Since your entity doesn't move on it's own and doesn't jump you can remove a good chunk of this but it should get you started. 

Link to post
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.

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.