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



}

 

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. 

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.