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

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?

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.

  • Author

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...

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.