Jump to content

Recommended Posts

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



}

 

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

×
×
  • Create New...

Important Information

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