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
[shadow=red,left][font=arial][glow=red,4,400]Ok, so I am wondering how I can make a truck. So, I made code for it and it works, but it doesnt move. It rotates and everything, but it stays stationary. Why does it do that? How do I fix it? Please help.
[/glow]
Here is my code for the Entity:
package com.camp.entity;

[/font][/shadow]

import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class EntityTruck extends EntityMob // this to make mob hostile
{
  public boolean stationary;
  public EntityTruck(World par1World)
  {
    super(par1World);
    isImmuneToFire = false;
  }
  protected void applEntityAttributes() {
      super.applyEntityAttributes();
      this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20000.0d);
      this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4f);
      this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0f);
      this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(100f);
      this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0f);

  }
  protected boolean canDespawn()
  {
    return false;
  }
  public boolean interact(EntityPlayer entityplayer)
  {
    if (riddenByEntity == null || riddenByEntity == entityplayer)
    {
      entityplayer.mountEntity(this);
      return true;
    }
    else
    {
      return false;
    }
  }
  protected boolean isMovementCeased()
  {
    return stationary;
  }
  public void moveEntity(double d, double d1, double d2)
  {
    if (riddenByEntity != null)
    {
      this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw;
      this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
      this.setRotation(this.rotationYaw, this.rotationPitch);
      this.rotationYawHead = this.renderYawOffset = this.rotationYaw;
      stationary = true;
      motionX += riddenByEntity.motionX * 2F; // * 0.20000000000000001D;
      motionZ += riddenByEntity.motionZ * 2F; // * 0.20000000000000001D;
      if (isCollidedHorizontally)
      {
        isJumping = true;
      }
      else
      {
        isJumping = false;
      }
      super.moveEntity(motionX, motionY, motionZ);
    }
    else
    {
      stationary = false;
      super.moveEntity(d, d1, d2);
    }
  }
  public void onUpdate()
  {
    super.onUpdate();
    if (riddenByEntity != null) //check if there is a rider
    {
      //currentTarget = this;
      this.randomYawVelocity = 0; //try not to let the horse control where to look.
      this.rotationYaw = riddenByEntity.rotationYaw;
    }
  }
  protected boolean isAIEnabled() //Allow your AI task to work?
  {
    return true;
  }
}

[shadow=red,left][/shadow]

I AM SUS

  • Author

[glow=red,20,200]Oh... Well I dont know any other way of making it move, I have never made one before. If I put a solid number there, it will move, but only in one direction and non-controllable. I was thinking that I could use keybindings, but I have no idea how to do that.[/glow]

I AM SUS

[glow=red,20,200]Oh... Well I dont know any other way of making it move, I have never made one before. If I put a solid number there, it will move, but only in one direction and non-controllable. I was thinking that I could use keybindings, but I have no idea how to do that.[/glow]

First of all why do you write in red and second - think of what you need. Youll need a speed and the propper calculations hint - have a look at minecrafts entity boat class

  • Author

[glow=red,20,200] I tried the keybinding, and it doesnt work. Also, I couldnt find it in the EntityBoat class. I have no idea what I am doing. If anyone knows how to help me, please tell me! [/glow]

I AM SUS

Nobody is going to program the whole mod for you. So please try to search for the answer in the classes full of working examples forge is providing you. (E.g. EntityBoat, EntityPig, EntityHorse - names may be slightly different though with a bit of effort easy to find).

 

A few tips are already given for a possible solution. You need some way of keybinding. And the Entity that needs to recieve the motion is the Entity the player is riding, not the Player itself.

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

No need for keybindings...

Just set the entity's

[b]moveStrafing[/b]

and

[b]moveForward[/b]

fields to the same value as the riding entity's

moveStrafing

and

moveForward

.

Do that in the

onLivingUpdate

method of your entity (after the super call), check if it's ridden by anything of course (

[b]riddenByEntity[/b]

is not

null

).

 

To steer it, you'd need to set the

[b]rotationYaw[/b]

and

[b]rotationYawHead[/b]

fields of your entity to the ones of the riding one. Do it right before setting the move* fields.

Also override

[b]canBeSteered()[/b]

and return true.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

No need for keybindings...

Just set the entity's

[b]moveStrafing[/b]

and

[b]moveForward[/b]

fields to the same value as the riding entity's

moveStrafing

and

moveForward

.

Do that in the

onLivingUpdate

method of your entity (after the super call), check if it's ridden by anything of course (

[b]riddenByEntity[/b]

is not

null

).

 

To steer it, you'd need to set the

[b]rotationYaw[/b]

and

[b]rotationYawHead[/b]

fields of your entity to the ones of the riding one. Do it right before setting the move* fields.

Also override

[b]canBeSteered()[/b]

and return true.

Wow, I have to say you've got some of the best explanations. Very thorough, tells you where to look, and at the same time isn't spoonfeeding. Not sure you can get any better than that.  :P

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

  • Author

No need for keybindings...

Just set the entity's

[b]moveStrafing[/b]

and

[b]moveForward[/b]

fields to the same value as the riding entity's

moveStrafing

and

moveForward

.

Do that in the

onLivingUpdate

method of your entity (after the super call), check if it's ridden by anything of course (

[b]riddenByEntity[/b]

is not

null

).

 

To steer it, you'd need to set the

[b]rotationYaw[/b]

and

[b]rotationYawHead[/b]

fields of your entity to the ones of the riding one. Do it right before setting the move* fields.

Also override

[b]canBeSteered()[/b]

and return true.

Wow, I have to say you've got some of the best explanations. Very thorough, tells you where to look, and at the same time isn't spoonfeeding. Not sure you can get any better than that.  :P

Dude, this isnt a praise area.

I AM SUS

Ok, but there is no moveForward field in the riding entity. Or a moveStrafing.

I say this only one more time - before you start messing up your code - PLAN THE WHOLE THING ON PAPER! And the move straffing field is not in the entitity itself, it is in the ridingEntity. We will not write your mod for you, try figuring it out. We will help you if you run in some problems, but youll have to do the main part of it on your own.

Ok, but there is no moveForward field in the riding entity. Or a moveStrafing.

And the move straffing field is not in the entitity itself, it is in the ridingEntity.

I'd say it is...

https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/de/sanandrew/mods/enderstuffp/entity/living/EntityEnderMiss.java#L591-L592

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • 3 weeks later...
  • Author

Sorry it took me so long to respond, here is my most recent updated code. Also, I am not asking you to code my entire mod, this is only MY FIRST MOD!!! Please, just tell me how to do it and then I will know. Here it is...

 

package com.camp.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class EntityTruck extends EntityMob // this to make mob hostile
{
  public boolean stationary;
  public EntityTruck(World par1World)
  {
    super(par1World);
    isImmuneToFire = false;
  }
  
  protected boolean canDespawn()
  {
    return false;
  }
  public boolean interact(EntityPlayer entityplayer)
  {
    if (riddenByEntity == null || riddenByEntity == entityplayer)
    {
      entityplayer.mountEntity(this);
      return true;
    }
    else
    {
      return false;
    }
  }
  protected boolean isMovementCeased()
  {
    return stationary;
  }
  public void moveEntity(double d, double d1, double d2)
  {
    if (riddenByEntity != null)
    {
      EntityPlayer player = (EntityPlayer) this.riddenByEntity;
      this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw;
      this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
      this.setRotation(this.rotationYaw, this.rotationPitch);
      this.rotationYawHead = player.rotationYawHead;
      stationary = false;
      motionX += riddenByEntity.motionX * 10; // * 0.20000000000000001D;
      motionZ += riddenByEntity.motionZ * 10; // * 0.20000000000000001D;
      //this.moveStrafing = player.moveStrafing;
      //this.moveForward = player.moveForward;
      if (isCollidedHorizontally)
      {
        isJumping = true;
      }
      else
      {
        isJumping = false;
      }
      super.moveEntity(motionX, motionY, motionZ);
    }
    else
    {
      stationary = false;
      super.moveEntity(d, d1, d2);
    }
  }
  public void onUpdate()
  {
    super.onUpdate();
    if (riddenByEntity != null) //check if there is a rider
    {
      //currentTarget = this;
      this.randomYawVelocity = 0; //try not to let the horse control where to look.
      this.rotationYaw = riddenByEntity.rotationYaw;
    }
  }
  protected boolean isAIEnabled() //Allow your AI task to work?
  {
    return true;
  }
}

I AM SUS

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.