š“pothicon
š“pothicon
Explore posts from servers
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 1/18/2025 in #java-help
Converting int array to byte array
I am attempting to convert an array of ints to a byte array to store in a file which will later be read and converted back into an int array. these are my conversion methods:
public static byte[] intArrayToByteArray(int[] intArr) {
byte[] byteArr = new byte[intArr.length*4];
for (int i = 0; i < intArr.length; i++) {
int val = intArr[i];
byteArr[(i*4)] = (byte) (val >> 24);
byteArr[(i*4)+1] = (byte) (val >> 16);
byteArr[(i*4)+2] = (byte) (val >> 8);
byteArr[(i*4)+3] = (byte) (val);
}
return byteArr;
}
public static int[] byteArrayToIntArray(byte[] byteArr) {
int[] intArr = new int[byteArr.length/4];
for (int i = 0; i < intArr.length; i++) {
intArr[i] = (byteArr[i*4] & 0xFF << 24) | (byteArr[(i*4)+1] & 0xFF << 16) | (byteArr[(i*4)+2] & 0xFF << 8) | (byteArr[(i*4)+3] & 0xFF);
}
return intArr;
}
public static byte[] intArrayToByteArray(int[] intArr) {
byte[] byteArr = new byte[intArr.length*4];
for (int i = 0; i < intArr.length; i++) {
int val = intArr[i];
byteArr[(i*4)] = (byte) (val >> 24);
byteArr[(i*4)+1] = (byte) (val >> 16);
byteArr[(i*4)+2] = (byte) (val >> 8);
byteArr[(i*4)+3] = (byte) (val);
}
return byteArr;
}
public static int[] byteArrayToIntArray(byte[] byteArr) {
int[] intArr = new int[byteArr.length/4];
for (int i = 0; i < intArr.length; i++) {
intArr[i] = (byteArr[i*4] & 0xFF << 24) | (byteArr[(i*4)+1] & 0xFF << 16) | (byteArr[(i*4)+2] & 0xFF << 8) | (byteArr[(i*4)+3] & 0xFF);
}
return intArr;
}
14 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 1/13/2025 in #java-help
vmaVirtualFree
I have chunk data that is being alloacted to memory with VMA, and I need to occasionally free the allocation of some chunks. The method to do this takes an "allocation" long as an argument, but im not sure what i am supposed to actually be giving it.
5 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 12/11/2024 in #java-help
Unallocating direct buffer
No description
18 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 12/10/2024 in #java-help
Making an object that can be various types?
I have a byte[] and a short[] used for the same thing. I want to switch from using the byte[] and short[] based on the maximum value needed, which changes occasionally. My idea is to have an Object that is swapped between referencing the byte[] or the short[] as needed. The part I can't figure out is casting the Object to the array type its referencing. I tried this to alter the contents of the array the object is referencing:
((array.getClass())(array))[pos] = ...
((array.getClass())(array))[pos] = ...
but it just says "the result of getClass() is unused" (aka it isnt trying to cast the Object with the result like i want it to)
29 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 12/7/2024 in #java-help
Increasing max stack size
No description
11 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 11/23/2024 in #java-help
Unpacking packed int
I came up with these methods to pack and unpack ints:
public static int packInts(int first4, int last4) {
return (first4 << 16) | last4;
}
public static Vector2i unpackInt(int all8) {
return new Vector2i(all8 << 16, all8 >> 16);
}
public static int packInts(int first4, int last4) {
return (first4 << 16) | last4;
}
public static Vector2i unpackInt(int all8) {
return new Vector2i(all8 << 16, all8 >> 16);
}
However when I unpack the packed int I get an unepxected result. For example if I pack (3, 2) then unpack it I get (131072, 3)
11 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 11/11/2024 in #java-help
Removing roll from camera matrix
I have a camera class which is just this:
import org.joml.*;

public class Camera {
public Matrix4f viewMatrix = new Matrix4f().setTranslation(new Vector3f(100, 200, 100));

public void rotate(float x, float y) {
viewMatrix.rotateXYZ(x, y, 0);
}
public void move(float x, float y, float z) {
viewMatrix.translate(x, y, z);
}
}
import org.joml.*;

public class Camera {
public Matrix4f viewMatrix = new Matrix4f().setTranslation(new Vector3f(100, 200, 100));

public void rotate(float x, float y) {
viewMatrix.rotateXYZ(x, y, 0);
}
public void move(float x, float y, float z) {
viewMatrix.translate(x, y, z);
}
}
and it works, but I want to eliminate the roll from the matrix somehow.
199 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 10/27/2024 in #java-help
Figuring out path to resources in built jar
Im currently doing this to read my shader files:
Utils.readFile("src/main/resources/assets/base/shaders/scene.vert")
Utils.readFile("src/main/resources/assets/base/shaders/scene.vert")
and it works when just testing in intellij, but if i build the jar it no longer works as the src/main/resources part of the path doesnt exist. Any solutions?
11 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 8/2/2024 in #java-help
Repositioning objects to stay in the same position relative to each other when rotated.
No description
10 replies
DHDistant Horizons
Created by š“pothicon on 6/22/2024 in #help-me
Ignore non-colliding blocks setting not working
No description
4 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 6/14/2024 in #java-help
Implementing Desmos Function into Java
No description
78 replies
DHDistant Horizons
Created by š“pothicon on 4/10/2024 in #help-me
Blocks tinting incorrectly in LOD chunks
No description
100 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 3/9/2024 in #java-help
Get progress of int between two other ints.
I have three integers, min, max, and value. Value is always between min and max, but I need to figure out how to get a double that represents how "far along" the value is from min to max. For example: Min: 0 Max: 100 Value: 69 would return 0.69 as it is 69% between 0 and 100.
I just need help on the math required for this.
6 replies
DHDistant Horizons
Created by š“pothicon on 2/16/2024 in #help-me
URI scheme is not "file" (preventing game from opening)
No description
14 replies
JCHJava Community | Help. Code. Learn.
Created by š“pothicon on 1/7/2024 in #java-help
Unable to get list of list.
No description
56 replies
DHDistant Horizons
Created by š“pothicon on 12/27/2023 in #help-me
LOD chunks randomly stop loading
No description
10 replies
DHDistant Horizons
Created by š“pothicon on 11/17/2023 in #bug-report
Timeout
No description
5 replies