This commit is contained in:
Vaern 2023-08-16 20:44:32 -07:00
parent b5df3b0979
commit 40af290153
3 changed files with 86 additions and 33 deletions

View File

@ -22,6 +22,8 @@ public class HbmWorld {
initWorldGen(); initWorldGen();
} }
public static NTMWorldGenerator worldGenerator;
public static void initWorldGen() { public static void initWorldGen() {
//MapGenStructureIO.registerStructure(StructureStartTest.class, "HFR_STRUCTURE"); //MapGenStructureIO.registerStructure(StructureStartTest.class, "HFR_STRUCTURE");
@ -33,7 +35,7 @@ public class HbmWorld {
registerWorldGen(new HbmWorldGen(), 1); registerWorldGen(new HbmWorldGen(), 1);
NTMWorldGenerator worldGenerator = new NTMWorldGenerator(); worldGenerator = new NTMWorldGenerator();
registerWorldGen(worldGenerator, 1); //Ideally, move everything over from HbmWorldGen to NTMWorldGenerator registerWorldGen(worldGenerator, 1); //Ideally, move everything over from HbmWorldGen to NTMWorldGenerator
MinecraftForge.EVENT_BUS.register(worldGenerator); MinecraftForge.EVENT_BUS.register(worldGenerator);
//registerWorldGen(new WorldGenTest(), 1); //registerWorldGen(new WorldGenTest(), 1);

View File

@ -1,12 +1,15 @@
package com.hbm.world.gen; package com.hbm.world.gen;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import com.hbm.config.GeneralConfig; import com.hbm.config.GeneralConfig;
import com.hbm.world.gen.component.SpecialFeatures.SpecialContainer; import com.hbm.world.gen.component.SpecialFeatures.SpecialContainer;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.gen.structure.MapGenStructure; import net.minecraft.world.gen.structure.MapGenStructure;
@ -18,7 +21,10 @@ import net.minecraft.world.gen.structure.StructureStart;
//it's 'special' because it's not unique but also limited //it's 'special' because it's not unique but also limited
public class MapGenSpecialFeatures extends MapGenStructure { public class MapGenSpecialFeatures extends MapGenStructure {
//suuuuuper efficient for .contains() //suuuuuper efficient for .contains()
//do i even need chunkcoordintpairs? idk
Set<ChunkCoordIntPair> locs = new HashSet<ChunkCoordIntPair>(); Set<ChunkCoordIntPair> locs = new HashSet<ChunkCoordIntPair>();
//efficient enough for books n shit
List<ChunkCoordIntPair> bookLocs = new ArrayList<ChunkCoordIntPair>();
/** String ID for this MapGen */ /** String ID for this MapGen */
@Override @Override
@ -28,44 +34,89 @@ public class MapGenSpecialFeatures extends MapGenStructure {
@Override @Override
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) { protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) {
if(locs.isEmpty())
if(locs.isEmpty()) { generatePositions();
Random rand = new Random(this.worldObj.getSeed());
double theta = rand.nextDouble() * Math.PI * 2;
int ringMax = 4; //each ring of structures has more (and is farther) than the last
int ringDist = 1;
final int total = 16; //for now
//no biome checks necessary, underground caches can always be a backup
for(int i = 1; i <= total; i++) {
double dist = 312D * (1.25 * ringDist + rand.nextDouble() * 0.5); //5k blocks * random dist in the region of a ring
int cX = (int)Math.round(Math.cos(theta) * dist);
int cZ = (int)Math.round(Math.sin(theta) * dist);
ChunkCoordIntPair pair = new ChunkCoordIntPair(cX, cZ);
locs.add(pair);
if(GeneralConfig.enableDebugMode)
System.out.println("SpecialFeature: " + (pair.chunkXPos * 16 + 8) + ", Y, " + (pair.chunkZPos * 16 + 8));
theta += Math.PI * 2 / ringMax;
if(i == (ringDist - 1) * 4 + ringMax) {
ringDist++;
if(i + ringDist * 4 > total) //last ring may be sparser, but evenly spaced too
ringMax = total - i;
else
ringMax = ringDist * 4;
}
}
}
return locs.contains(new ChunkCoordIntPair(chunkX, chunkZ)); return locs.contains(new ChunkCoordIntPair(chunkX, chunkZ));
} }
//i'll probs make a system to predict which locations are what in advance
//seems like biomes can be cached/gen'd without creating the chunk, thankfully
//vec3 will be the angle + distance from provided coords, given in chunk coords
/*public Vec3 findClosestPosition(int chunkX, int chunkZ) {
createBookList();
long time = System.nanoTime();
ChunkCoordIntPair pair = new ChunkCoordIntPair(0, 0);
long dist = Long.MAX_VALUE;
for(ChunkCoordIntPair loc : bookLocs) {
int x = loc.chunkXPos - chunkX;
int z = loc.chunkZPos - chunkZ;
long cont = x * x + z * z;
if(cont < dist) {
pair = loc;
dist = cont;
}
}
System.out.print(System.nanoTime() - time);
return Vec3.createVectorHelper(pair.chunkXPos - chunkX, 0, pair.chunkZPos - chunkZ);
}
protected void createBookList() {
if(locs.isEmpty())
generatePositions();
if(!bookLocs.isEmpty()) return;
long time = System.nanoTime();
for(ChunkCoordIntPair loc : locs) {
bookLocs.add(loc);
}
System.out.print(System.nanoTime() - time);
}*/
protected void generatePositions() {
//for safety: maybe mandate interactions with these methods to an outside class/wrapper who say "fuck you"
Random rand = new Random(this.worldObj.getSeed()); //TODO: worldObj is null until func_15139_a is called!! very bad!!!
double theta = rand.nextDouble() * Math.PI * 2;
int ringMax = 4; //each ring of structures has more (and is farther) than the last
int ringDist = 1;
final int total = 16; //for now
//no biome checks necessary, underground caches can always be a backup
for(int i = 1; i <= total; i++) {
double dist = 312D * (1.25 * ringDist + rand.nextDouble() * 0.5); //5k blocks * random dist in the region of a ring
int cX = (int)Math.round(Math.cos(theta) * dist);
int cZ = (int)Math.round(Math.sin(theta) * dist);
ChunkCoordIntPair pair = new ChunkCoordIntPair(cX, cZ);
locs.add(pair);
if(GeneralConfig.enableDebugMode)
System.out.println("SpecialFeature: " + (pair.chunkXPos * 16 + 8) + ", Y, " + (pair.chunkZPos * 16 + 8));
theta += Math.PI * 2 / ringMax;
if(i == (ringDist - 1) * 4 + ringMax) {
ringDist++;
//maybe insert random theta each time?
if(i + ringDist * 4 > total) //last ring may be sparser, but evenly spaced too
ringMax = total - i;
else
ringMax = ringDist * 4;
}
}
}
@Override @Override
protected StructureStart getStructureStart(int chunkX, int chunkZ) { protected StructureStart getStructureStart(int chunkX, int chunkZ) {
locs.remove(new ChunkCoordIntPair(chunkX, chunkZ));
return new SpecialStart(this.worldObj, this.rand, chunkX, chunkZ); return new SpecialStart(this.worldObj, this.rand, chunkX, chunkZ);
} }

View File

@ -26,8 +26,8 @@ public class NTMWorldGenerator implements IWorldGenerator {
/** Inits all MapGen upon the loading of a new world. Hopefully clears out structureMaps and structureData when a different world is loaded. */ /** Inits all MapGen upon the loading of a new world. Hopefully clears out structureMaps and structureData when a different world is loaded. */
@SubscribeEvent @SubscribeEvent
public void onLoad(WorldEvent.Load event) { public void onLoad(WorldEvent.Load event) {
scatteredFeatureGen = (MapGenNTMFeatures) getModdedMapGen(new MapGenNTMFeatures(), EventType.CUSTOM); scatteredFeatureGen = (MapGenNTMFeatures) getModdedMapGen(new MapGenNTMFeatures(), EventType.CUSTOM); //TODO: set worlds to a non-null value here.
specialFeatureGen = (MapGenSpecialFeatures) getModdedMapGen(new MapGenSpecialFeatures(), EventType.CUSTOM); specialFeatureGen = (MapGenSpecialFeatures) getModdedMapGen(new MapGenSpecialFeatures(), EventType.CUSTOM); //we've got access to it plain n simple here anyway
hasPopulationEvent = false; hasPopulationEvent = false;
} }