Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Strange problems with vectors


Recommended Posts

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;



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?

Link to comment
Share on other sites

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


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.

Link to comment
Share on other sites

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;



public boolean foundVehicle;


private int vehicleID;


public EntityWheel(World worldIn) {


setSize(1F, 1F);

stepHeight = 1;



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


parent = entityVehicle;

vehicleID = entityVehicle.getEntityId();

ID = id;





public void initPosition() {

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


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


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;





    public void fall(float k, float l)


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


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

if(i > 0){}

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




protected void entityInit() {




protected void readEntityFromNBT(NBTTagCompound tags)


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





protected void writeEntityToNBT(NBTTagCompound tags)





public void onUpdate() {

if (worldObj.isRemote && !foundVehicle) {

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


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

foundVehicle = true;

parent.wheels[iD] = this;



if (parent == null)



if (!addedToChunk)








public void writeSpawnData(ByteBuf data) {






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







Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.


  • Create New...

Important Information

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