Jump to content

Strange problems with vectors


ItsAMysteriousYT

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

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

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.

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;

 

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

}

 

}

 

 

 

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Situs Slot Bonus New Member 100 di Awal To Kecil 3x 7x Terbaru 2024 Daftar Disini >>> https://d6wx.short.gy/Link-Bonus-Bebas-IP Link Alternatif >>> https://c4b8.short.gy/hanyakamu Masih mencari Slot Bonus New Member 100 di awal to 7x terbaru tahun 2024 yang selalu memberikan update bonus new member 100 di depan di indonesia? idnslot menghadirkan situs dengan promo depo 25 bonus 25, bonus cashback, dan slot bonus 100 di depan to kecil untuk deposit pertamamu. Kami memberikan promo paling besar untuk kesejahteraan member dalam melakukan betting dari game gacor terlengkap yang di sediakan. Dengan adanya promosi slot bonus new member 100 to 3x 5x 7x 10x tentunya sangat menguntungkan kamu tahun 2024 ini. Sekian banyak situs dengan mengempurkan diri untuk memberikan kenyamanan kepada member tetapi idnslot login adalah situs satu-satunya yang langsung memberikan to rendah dari bonus new member 100 (slot game). Khusus pecinta slot bonus kamu hanya dengan minimal deposit 10rb saja bisa dapat jackpot terbesar. Berikut adalah game slot bonus new member 100 game paling gacor hari ini: Slot Bonus Mahjong Ways Slot Bonus Gates Of Olympus Slot Bonus Lucky Neko Slot Bonus Starlight Princess Slot Bonus PG Soft Slot Bonus Pragmatic Play
    • Situs Slot Bonus New Member 100 di Awal To Kecil 3x 7x Terbaru 2024 Daftar Disini >>> https://d6wx.short.gy/Link-Bonus-Bebas-IP Link Alternatif >>> https://c4b8.short.gy/hanyakamu Masih mencari Slot Bonus New Member 100 di awal to 7x terbaru tahun 2024 yang selalu memberikan update bonus new member 100 di depan di indonesia? pay4d menghadirkan situs dengan promo depo 25 bonus 25, bonus cashback, dan slot bonus 100 di depan to kecil untuk deposit pertamamu. Kami memberikan promo paling besar untuk kesejahteraan member dalam melakukan betting dari game gacor terlengkap yang di sediakan. Dengan adanya promosi slot bonus new member 100 to 3x 5x 7x 10x tentunya sangat menguntungkan kamu tahun 2024 ini. Sekian banyak situs dengan mengempurkan diri untuk memberikan kenyamanan kepada member tetapi pay4d login adalah situs satu-satunya yang langsung memberikan to rendah dari bonus new member 100 (slot game). Khusus pecinta slot bonus kamu hanya dengan minimal deposit 10rb saja bisa dapat jackpot terbesar. Berikut adalah game slot bonus new member 100 game paling gacor hari ini: Slot Bonus Mahjong Ways Slot Bonus Gates Of Olympus Slot Bonus Lucky Neko Slot Bonus Starlight Princess Slot Bonus PG Soft Slot Bonus Pragmatic Play
    • Situs Slot Bonus New Member 100 di Awal To Kecil 3x 7x Terbaru 2024 Daftar Disini >>> https://d6wx.short.gy/Link-Bonus-Bebas-IP Link Alternatif >>> https://c4b8.short.gy/hanyakamu Masih mencari Slot Bonus New Member 100 di awal to 7x terbaru tahun 2024 yang selalu memberikan update bonus new member 100 di depan di indonesia? Huat138 menghadirkan situs dengan promo depo 25 bonus 25, bonus cashback, dan slot bonus 100 di depan to kecil untuk deposit pertamamu. Kami memberikan promo paling besar untuk kesejahteraan member dalam melakukan betting dari game gacor terlengkap yang di sediakan. Dengan adanya promosi slot bonus new member 100 to 3x 5x 7x 10x tentunya sangat menguntungkan kamu tahun 2024 ini. Sekian banyak situs dengan mengempurkan diri untuk memberikan kenyamanan kepada member tetapi Naga Hoki88 login adalah situs satu-satunya yang langsung memberikan to rendah dari bonus new member 100 (slot game). Khusus pecinta slot bonus kamu hanya dengan minimal deposit 10rb saja bisa dapat jackpot terbesar. Berikut adalah game slot bonus new member 100 game paling gacor hari ini: Slot Bonus Mahjong Ways Slot Bonus Gates Of Olympus Slot Bonus Lucky Neko Slot Bonus Starlight Princess Slot Bonus PG Soft Slot Bonus Pragmatic Play
    • Did it crash before you added mods to the pack? If not, try readding the mods 1-2 at a time testing in between to find the broken/incompatible mod
  • Topics

×
×
  • Create New...

Important Information

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