Jump to content

Recommended Posts

Posted

Hey there, for my mod i load the wheelpositions of a vehicle from a textfile. The line that parses the text to a Vector3f is this:

if (line.startsWith("wheelPositions: ")) {

				for (int i = 0; i < 4; i++) {
					String posVector = line.split(":")[1].split(",")[i].trim();
					Vector3f position = new Vector3f();
					position.x = Float.parseFloat(posVector.split("/")[0]);
					position.y = Float.parseFloat(posVector.split("/")[1]);
					position.z = Float.parseFloat(posVector.split("/")[2]);
					wheelPositions[i] = position;
					System.out.println(wheelPositions[i]);
				}

			}

 

Now, my problem is, that when i look at the positions the first three are 1.0,1.0,1.0 and only the last vector holds the correct values from the file. Is this problem in the parsing code or somewhere else?

Posted

If you're going to use multiple values from a string split, you should store returned array in a local variable and reference that instead of calling

String#split

once per value.

 

Doing this will also allow you to step through the code in a debugger and see what the values for each position are before they're parsed into floats.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I found out, that the values are prperly set in the vectors. The problem is, that the wheels are at the wrong position somehow.

This is my EntityWheel class:

 

 

package itsamysterious.mods.reallifemod.core.vehicles;

 

import javax.vecmath.Vector3d;

 

import org.lwjgl.util.vector.Vector3f;

 

import io.netty.buffer.ByteBuf;

import net.minecraft.entity.Entity;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

public class EntityWheel extends Entity implements IEntityAdditionalSpawnData {

public EntityDriveable parent;

public int ID;

 

@SideOnly(Side.CLIENT)

public boolean foundVehicle;

 

private int vehicleID;

 

public EntityWheel(World worldIn) {

super(worldIn);

setSize(1F, 1F);

stepHeight = 1;

}

 

public EntityWheel(World worldIn, EntityDriveable entityVehicle, int id) {

this(worldIn);

parent = entityVehicle;

vehicleID = entityVehicle.getEntityId();

ID = id;

 

initPosition();

}

 

public void initPosition() {

Vector3f wheelVector = parent.axes.findLocalVectorGlobally(parent.getFile().wheelPositions[iD]);

if(ID==0||ID==3)

setPosition(parent.posX - wheelVector.x, parent.posY + wheelVector.y, parent.posZ - wheelVector.z);

if(ID==1||ID==2)

setPosition(parent.posX + wheelVector.x, parent.posY + wheelVector.y, parent.posZ + wheelVector.z);

System.out.println("Positon is: "+ posX+","+posY+","+posZ);

stepHeight = 1F;

 

prevPosX = posX;

prevPosY = posY;

prevPosZ = posZ;

}

 

 

@Override

    public void fall(float k, float l)

    {

if(parent == null || k <= 0)

return;

int i = MathHelper.ceiling_float_int(k - 3F);

if(i > 0){}

//parent.attackPart(parent.getFile().wheelPositions[iD], DamageSource.fall, i);

}

 

@Override

protected void entityInit() {

}

 

@Override

protected void readEntityFromNBT(NBTTagCompound tags)

{

System.out.println("Now setting dead");

setDead();

}

 

@Override

protected void writeEntityToNBT(NBTTagCompound tags)

{

}

 

@Override

public void onUpdate() {

if (worldObj.isRemote && !foundVehicle) {

if (!(worldObj.getEntityByID(vehicleID) instanceof EntityDriveable))

return;

parent = (EntityDriveable) worldObj.getEntityByID(vehicleID);

foundVehicle = true;

parent.wheels[iD] = this;

}

 

if (parent == null)

return;

 

if (!addedToChunk)

worldObj.spawnEntityInWorld(this);

 

}

 

 

 

@Override

public void writeSpawnData(ByteBuf data) {

data.writeInt(vehicleID);

data.writeInt(ID);

}

 

@Override

public void readSpawnData(ByteBuf data) {

vehicleID = data.readInt();

ID = data.readInt();

if (worldObj.getEntityByID(vehicleID) instanceof EntityDriveable)

parent = (EntityDriveable) worldObj.getEntityByID(vehicleID);

if (parent != null)

setPosition(posX, posY, posZ);

}

 

public Vector3d getPositionVectorFloat() {

return new Vector3d(posX, posY, posZ);

}

 

public double getSpeedXZ() {

return Math.sqrt(motionX + motionX * motionZ * motionZ);

}

 

}

 

 

 

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.