Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] vehicle entity
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
brok4d

[1.16.4] vehicle entity

By brok4d, Tuesday at 05:41 PM in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

brok4d    0

brok4d

brok4d    0

  • Tree Puncher
  • brok4d
  • Members
  • 0
  • 3 posts
Posted Tuesday at 05:41 PM

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



}

 

  • Quote

Share this post


Link to post
Share on other sites

WindRunner7    1

WindRunner7

WindRunner7    1

  • Tree Puncher
  • WindRunner7
  • Members
  • 1
  • 3 posts
Posted yesterday at 02:33 PM

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. 

  • Quote

Share this post


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.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Centmap
      Forge Mods Folder

      By Centmap · Posted 1 minute ago

      so i created a "1.16.5" folder in the folder "mod" as usual but it doesn't use the mods. Can anyone help me ?
    • Skyriis
      [SOLVED][1.16.5] Adding a Button to KeyBindings

      By Skyriis · Posted 41 minutes ago

      That worked.   Here is my solution @SubscribeEvent public static void onOpenGui(final GuiScreenEvent.InitGuiEvent.Post event) { if (!(event.getGui() instanceof ControlsScreen)) return; final ControlsScreen controlsScreen = (ControlsScreen) event.getGui(); final KeyBindingList replacement = new KeyBindingListReplacement(controlsScreen, event.getGui().getMinecraft()); final KeyBindingList old = ObfuscationReflectionHelper.getPrivateValue(ControlsScreen.class, controlsScreen, "field_146494_r"); controlsScreen.getEventListeners().remove(old); ObfuscationReflectionHelper.setPrivateValue(ControlsScreen.class, controlsScreen, replacement, "field_146494_r"); try { Method addChildMethod = ObfuscationReflectionHelper.findMethod(Screen.class, "func_230481_d_", IGuiEventListener.class); addChildMethod.setAccessible(true); addChildMethod.invoke(controlsScreen, replacement); addChildMethod.setAccessible(false); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } }  
    • DrCowiber
      Failed To Start Minecraft Server

      By DrCowiber · Posted 1 hour ago

      im using this run.sh file, which contains: java -Xmx6G -Xms6G -jar minecraft_server.1.16.5.jar --nogui Edit: When I first posted about this I was using the serverRun.jar, which the first log file I posted is what the output was
    • Tez
      [1.15.2] Couln't not resolve dependency: net.minecraftforge:forge:1.15.2-31.2.0:userdev

      By Tez · Posted 1 hour ago

      I'm new to mod coding so i've watch tutorial in youtube in setup workspace step i got this error , i've try many solutions to fix but it still not working try update gradle to 6.8.3 but still not working try update java and still not working too here's my stacktrace: Stacktrace
    • diesieben07
      Failed To Start Minecraft Server

      By diesieben07 · Posted 1 hour ago

      Please show how exactly you are starting the server.
  • Topics

    • Centmap
      0
      Forge Mods Folder

      By Centmap
      Started 1 minute ago

    • Skyriis
      8
      [SOLVED][1.16.5] Adding a Button to KeyBindings

      By Skyriis
      Started 22 hours ago

    • DrCowiber
      8
      Failed To Start Minecraft Server

      By DrCowiber
      Started 20 hours ago

    • Tez
      0
      [1.15.2] Couln't not resolve dependency: net.minecraftforge:forge:1.15.2-31.2.0:userdev

      By Tez
      Started 1 hour ago

    • Mysterious minecrafter
      1
      game keeps crashing while initializings

      By Mysterious minecrafter
      Started 3 hours ago

  • Who's Online (See full list)

    • GermanBucket
    • Centmap
    • smitokyo
    • xBenjihdx
    • sleepier
    • Tavi007
    • Zeher_Monkey
    • K1llM3Pl5
    • Uncreative
    • Skyriis
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] vehicle entity
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community