Skip to content

Instantly share code, notes, and snippets.

@omnituensaeternum
Created July 16, 2021 06:41
Show Gist options
  • Save omnituensaeternum/0e8d5499a52407e635d5741c144dfebf to your computer and use it in GitHub Desktop.
Save omnituensaeternum/0e8d5499a52407e635d5741c144dfebf to your computer and use it in GitHub Desktop.
Java method for random Minecraft coordinate generation
// This is a basic program on Java
//
// Try to modify and run it and check out
// the output in the terminal below
//
// Happy coding! :-)
import java.util.Random;
public class App {
public int min;
public int max;
public Random r = new Random();
//X:73728 - Z:36864
//Max +/- for X = 36864
//Max +/- for Z = 18432
public static void main(String[] args) {
App a = new App();
int in = 73728;
double c = 0.15;
int low = 1000;
int i = 10000;
while (i >= 0) {
System.out.println(a.randCoordGen(in,low,c));
i--;
}
}
public double randCoordGen(int axisSum, int lowerBound, double constraintPercentage) {
int max = axisSum;
int lower = lowerBound;
double constraint = constraintPercentage;
double vaildRange = 0;
if(constraint != 0.0 && constraint >= 0.15 && lower != 0) {
double bufferRange = max * constraint;
double baseVaildRange = max - bufferRange;
double curb = Math.round(Math.sqrt(bufferRange));
vaildRange = baseVaildRange - curb;
} else {
return 0;
}
int min = (int)vaildRange / 2;
int out = r.nextInt((int)vaildRange)-min;
if(out <= lower){
out = out + lower;
}
double result = out;
return result;
}
}
//double constraint = .5;
//int max = 73728;
//double bufferRange = max * constraint;
//double baseVaildRange = max - bufferRange;
//double curb = Math.round(Math.sqrt(bufferRange));
//double vaildRange = baseVaildRange - curb;
//System.out.println("Constraint = " + constraint);
//System.out.println("Max = " + max);
//System.out.println("Buffer Range = " + bufferRange);
//System.out.println("Base Vaild Range = " + baseVaildRange);
//System.out.println("curb = " + curb);
//System.out.println("Vaild Range = " + vaildRange);
/**
* Time: 3:54:07 PM | Date: 07-09-2021
* @author Galactic
* The method randCoordGen generates acceptable value ranges for Minecraft's coordinate system.
* In order to return proper values for use, axisSum must be the total length of the target axis. (max positive axis length * 2)
* This method returns both positive and negative values.
* If useConstraint is true and
* @see java.util.Random
* @param axisSum
* @param constraintPercentage
* @return result
*/
/**
public static double randCoordGen(int axisSum, double constraintPercentage) {
int max = axisSum;
double constraint = constraintPercentage;
if(constraint != 0.0 && constraint <= 0.15) {
double bufferRange = max * constraint;
double baseVaildRange = max - bufferRange;
double curb = Math.round(Math.sqrt(bufferRange));
double vaildRange = baseVaildRange - curb;
} else {
return 0;
}
double min = vaildRange / 2;
int out = r.nextInt(vaildRange)-min;
double result = (double)out;
return result;
}
**/
//int l = 10000;
//while (l >= 0) {
// l--;
// //System.out.println("xCords: " + randXCordGen(73728) + " zCords: " + randXCordGen(36864));
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment