Jump to content

Recommended Posts

Posted

Hey, during my modding progress i run in to someissues with my entites when it is collided with a wall and then drives away again, and i dismount the player, then the player is dismounted at the position where the car is collided . Maybe i didn't understand entities properly yet. Here is my code: can somebody help me fix it(maybe also on skype Name: ItsAMysterious(TheEmeraldMinors)

 

 

 

package de.ItsAMysterious.mods.reallifemod.core.entities.cars;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.world.World;

 

import org.lwjgl.input.Mouse;

import org.lwjgl.util.vector.Vector3f;

 

import de.ItsAMysterious.mods.reallifemod.api.entity.EntitySeat;

import de.ItsAMysterious.mods.reallifemod.core.gui.GuiVehicle;

 

public class EntityVehicle extends Entity {

/*

* Vehicle Data

*/

public double fuelvalue;

public double maxfuel;

public Vector3f color = new Vector3f(1, 1, 1);

public int numPassengers = 5;

public double minspeed;

public double maxspeed;

public double currentspeed;

public double width, length;

public boolean isBraking;

public boolean hasDriver;

public double health;

public double maxhealth;

public double acceleration;

public EntitySeat[] seats;

public GuiVehicle gui;

 

/*

* Motion

*/

public double velocityX;

public double velocityY;

public double velocityZ;

public double vehicleYaw;

public double vehicleX;

public double vehicleY;

public double vehicleZ;

public double vehiclePitch;

public double deltasteer;

public double wheelrotation;

 

public EntityVehicle(World world) {

super(world);

}

 

@Override

protected void entityInit() {

dataWatcher.addObject(17, new Integer(0));

dataWatcher.addObject(18, new Integer(1));

dataWatcher.addObject(19, new Float(0.0F));

}

 

@Override

protected void readEntityFromNBT(NBTTagCompound compound) {

NBTTagList colorlist = compound.getTagList("COLOR", 6);

setColor(new Vector3f(colorlist.func_150308_e(0),

colorlist.func_150308_e(1), colorlist.func_150308_e(2)));

this.fuelvalue = compound.getDouble("FUELAMMOUNT");

this.maxfuel = compound.getDouble("MaxFuel");

}

 

@Override

protected void writeEntityToNBT(NBTTagCompound compound) {

compound.setTag("COLOR", newDoubleNBTList(new double[] { getColor().x,

getColor().y, getColor().z }));

compound.setDouble("FUELAMMOUNT", this.fuelvalue);

compound.setDouble("MaxFuel", this.maxfuel);

}

 

/*----------------------------------------------------------------------

/ Vehicle-Specification

/---------------------------------------------------------------------*/

 

public void setBounds(double width, double length) {

this.width = width;

this.length = length;

}

 

public void setSpeedMinMax(double min, double max) {

this.minspeed = min;

this.maxspeed = max;

}

 

public boolean hasDriver() {

return this.riddenByEntity != null;

}

 

public Vector3f getColor() {

return this.color;

}

 

public void setColor(Vector3f color) {

this.color = color;

}

 

/**

* MOVEMENT METHODS

*/

 

public void move() {

double R = 0;

double k = 0;

if (this.deltasteer != 0) {

R = 5 / this.deltasteer;

k = 1 / R;

}

wheelrotation += currentspeed * 20;

double angleVelocity = currentspeed * k;

 

if (currentspeed < maxspeed&&currentspeed>minspeed) {

currentspeed += acceleration;

}

 

rotationYaw += angleVelocity;

motionX = Math.sin(Math.toRadians(rotationYaw)) * currentspeed;

motionZ = Math.cos(Math.toRadians(rotationYaw)) * currentspeed;

this.moveEntity(motionX, motionY, motionZ);

if (!(this.worldObj.isRemote && (this.worldObj.blockExists(

(int) (this.posX), (int) posY, (int) (this.posZ)) || !this.worldObj

.getChunkFromBlockCoords((int) this.posX, (int) this.posZ).isChunkLoaded))) {

this.motionY = 0.0;

} else {

if (this.worldObj.blockExists((int) (posX), (int) posY - 1,

(int) (posZ))) {

this.motionY += 0.1D;

}

if (this.posY > 0.0D) {

this.motionY = -0.1D;

} else {

this.motionY = 0.0D;

}

this.motionY *= 9.800000190734863D;

}

if(acceleration==0){

if (currentspeed < -0.025) {

currentspeed += 0.025;

}

 

if (currentspeed > 0.0025) {

currentspeed -= 0.025;

}

}

}

 

protected void brake() {

if (currentspeed < -0.025) {

currentspeed *= 0.925;

}else{

if (currentspeed > 0.0025) {

currentspeed *= 0.981;

} else

currentspeed = 0;

}

 

}

 

public void moveSeats() {

/*

* for (int i = 0; i < numPassengers; i++) { if (seats != null &&

* seats != null) { // seats.driveable=this;

* seats.updatePosition(); double r =

* Math.sqrt(LittleFunctions.square(seats.offsetX) +

* LittleFunctions.square(seats.offsetY) +

* LittleFunctions.square(seats.offsetZ)); double sx, sy, sz; double

* phi = Math.sin(seats.offsetZ / r);// sin // phi!! double lambda =

* rotationPitch; sx = r * Math.cos(phi) * Math.cos(lambda); sy = r *

* Math.sin(lambda) * Math.cos(phi); sz = r * Math.sin(phi);

* seats.setPosition(posX + sx, posY + sy, posZ + sz); } }

*/

}

 

/*----------------------------------------------------------------------

* Basic entity methods

---------------------------------------------------------------------*/

 

public void onUpdate() {

super.onUpdate();

if (getTimeSinceHit() > 0) {

setTimeSinceHit(getTimeSinceHit() - 1);

}

 

if (getDamageTaken() > 0.0F) {

setDamageTaken(getDamageTaken() - 1.0F);

}

// if(Math.abs(deltasteer)<45)

// deltasteer +=-Minecraft.getMinecraft().mouseHelper.deltaX*0.25;

 

// Positioning for startup

prevPosX = posX;

prevPosY = posY;

prevPosZ = posZ;

boundingBox.calculateXOffset(getBoundingBox(), motionX);

boundingBox.calculateYOffset(getBoundingBox(), motionY);

boundingBox.calculateZOffset(getBoundingBox(), motionZ);

if(isCollidedHorizontally){

worldObj.spawnParticle("smoke", posX+Math.sin(Math.toRadians(rotationYaw)*boundingBox.minX), posY, posZ+Math.cos(Math.toRadians(rotationYaw)*boundingBox.minZ+boundingBox.maxZ/2), 0, 0, 0);

}

 

}

 

@Override

public boolean interactFirst(EntityPlayer player) {

return true;

}

 

@Override

public void setVelocity(double p_70016_1_, double p_70016_3_,

double p_70016_5_) {

velocityX = (float) (motionX = p_70016_1_);

velocityY = (float) (motionY = p_70016_3_);

velocityZ = (float) (motionZ = p_70016_5_);

}

 

public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_,

double p_70056_5_, float p_70056_7_, float p_70056_8_,

int p_70056_9_) {

vehicleX = p_70056_1_;

vehicleY = p_70056_3_;

vehicleZ = p_70056_5_;

vehicleYaw = (double) p_70056_7_;

vehiclePitch = (double) p_70056_8_;

motionX = velocityX;

motionY = velocityY;

motionZ = velocityZ;

}

 

public void onCollideWithPlayer(EntityPlayer player) {

if (hasDriver() && player != riddenByEntity)

player.setHealth((float) (player.getHealth() - currentspeed * 5));

}

 

    public void applyEntityCollision(Entity entity){

    super.applyEntityCollision(entity);

    entity.addVelocity(motionX, motionY, motionZ);

    if(entity instanceof EntityLivingBase)

    ((EntityLivingBase)entity).setHealth((float) (((EntityLivingBase)entity).getHealth()-currentspeed/0.3*2));

    }

 

public AxisAlignedBB getCollisionBox(Entity entity) {

return entity.boundingBox.getBoundingBox(-1, 0, 0, 1, 1, 7);

}

 

/**

* returns the bounding box for this entity

*/

public AxisAlignedBB getBoundingBox() {

return this.boundingBox;

}

 

public boolean canBePushed() {

return !isDead;

}

 

public void setDamageTaken(float p_70266_1_) {

dataWatcher.updateObject(19, Float.valueOf(p_70266_1_));

}

 

public float getDamageTaken() {

return dataWatcher.getWatchableObjectFloat(19);

}

 

/**

* Sets the time to count down from since the last time entity was hit.

*/

public void setTimeSinceHit(int p_70265_1_) {

dataWatcher.updateObject(17, Integer.valueOf(p_70265_1_));

}

 

/**

* Gets the time since the last hit.

*/

public int getTimeSinceHit() {

return dataWatcher.getWatchableObjectInt(17);

}

 

/**

* Sets the forward direction of the entity.

*/

public void setForwardDirection(int p_70269_1_) {

dataWatcher.updateObject(18, Integer.valueOf(p_70269_1_));

}

 

/**

* Gets the forward direction of the entity.

*/

public int getForwardDirection() {

return dataWatcher.getWatchableObjectInt(18);

}

 

/*

* Util Methods

*/

 

public Vector3f getPointForEntity(Vector3f point){

return new Vector3f((float)(posX+Math.sin(Math.toRadians(rotationYaw))*point.x),(float)

posX+Math.cos(Math.toRadians(rotationYaw))*point.x,(float)

posX+Math.sin(Math.toRadians(rotationYaw))*point.x);

}

 

}

 

 

 

Posted

Entity movement is different from other Minecraft aspects. Entity movement has to be done on both client and server, instead only on the server. Making the entity moe on both sides resolves the lagging behind issue, and maybe the other ones too.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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



×
×
  • Create New...

Important Information

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