Merge remote-tracking branch 'origin/worktree-agent-a2bb16cfb9ff4be19' into t3code/rewrite-minecraft-rust

# Conflicts:
#	tools/prepare_native_client.py
This commit is contained in:
Ludovic Marie
2026-10-08 11:18:39 +02:00
23 changed files with 5942 additions and 6 deletions
@@ -0,0 +1,40 @@
package dev.horizonlab.parity;
import com.google.gson.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import net.minecraft.SharedConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.server.Bootstrap;
import net.minecraft.world.RandomizableContainer;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
/**
* Original exporter of per-state structure-template behavior: BlockState.rotate
* and BlockState.mirror results, StructureTemplate's full-block ordering class
* and whether the state's block entity is a RandomizableContainer.
*/
public final class VanillaStructureBlockExporter {
public static void main(String[] args) throws Exception {
SharedConstants.tryDetectVersion();Bootstrap.bootStrap();
var rotate=new JsonArray();var mirror=new JsonArray();var full=new JsonArray();var loot=new JsonArray();
Rotation[] rotations={Rotation.CLOCKWISE_90,Rotation.CLOCKWISE_180,Rotation.COUNTERCLOCKWISE_90};
Mirror[] mirrors={Mirror.LEFT_RIGHT,Mirror.FRONT_BACK};
for(BlockState state:Block.BLOCK_STATE_REGISTRY) {
var r=new JsonArray();for(var rotation:rotations)r.add(Block.getId(state.rotate(rotation)));rotate.add(r);
var m=new JsonArray();for(var value:mirrors)m.add(Block.getId(state.mirror(value)));mirror.add(m);
full.add(!state.getBlock().hasDynamicShape()&&state.isCollisionShapeFullBlock(EmptyBlockGetter.INSTANCE,BlockPos.ZERO));
boolean container=false;
if(state.getBlock() instanceof EntityBlock entityBlock) {
try{container=entityBlock.newBlockEntity(BlockPos.ZERO,state) instanceof RandomizableContainer;}catch(Throwable ignored){}
}
if(container)loot.add(Block.getId(state));
}
var result=new JsonObject();
result.addProperty("states",Block.BLOCK_STATE_REGISTRY.size());
result.add("rotate",rotate);result.add("mirror",mirror);result.add("full_block",full);result.add("loot_containers",loot);
Files.writeString(Path.of(args[0]),new Gson().toJson(result),StandardCharsets.UTF_8);
}
}
@@ -0,0 +1,111 @@
package dev.horizonlab.parity;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
import net.minecraft.SharedConstants;
import net.minecraft.core.*;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.ServerPacksSource;
import net.minecraft.server.packs.resources.MultiPackResourceManager;
import net.minecraft.tags.TagLoader;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.biome.MultiNoiseBiomeSource;
import net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterLists;
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
import net.minecraft.world.level.levelgen.*;
import net.minecraft.world.level.levelgen.structure.*;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
import net.minecraft.world.level.storage.LevelStorageSource;
/**
* Original oracle: runs vanilla structure placement checks, start selection
* and Structure.generate (as ChunkGenerator.createStructures does for a fresh
* chunk) for a rectangle of overworld chunks and prints every valid start.
*/
public final class VanillaStructureStartOracle {
public static void main(String[] args) throws Exception {
SharedConstants.tryDetectVersion();Bootstrap.bootStrap();
Path out=Path.of(args[0]);long seed=Long.parseLong(args[1]);
int x0=Integer.parseInt(args[2]),z0=Integer.parseInt(args[3]),x1=Integer.parseInt(args[4]),z1=Integer.parseInt(args[5]);
var repo=ServerPacksSource.createVanillaTrustedRepository();repo.reload();repo.setSelected(List.of("vanilla"));
var resources=new MultiPackResourceManager(PackType.SERVER_DATA,repo.openAllSelected());
var layers=RegistryLayer.createRegistryAccess();
var staticTags=TagLoader.loadTagsForExistingRegistries(resources,layers.getLayer(RegistryLayer.STATIC));
var context=TagLoader.buildUpdatedLookups(layers.getAccessForLoading(RegistryLayer.WORLD),staticTags);
RegistryAccess.Frozen world=RegistryDataLoader.load(resources,context,RegistryDataLoader.WORLD_REGISTRIES,Runnable::run).join();
staticTags.forEach(Registry.PendingTags::apply);
RegistryAccess access=layers.replaceFrom(RegistryLayer.WORLD,world).compositeAccess();
var settings=world.lookupOrThrow(Registries.NOISE_SETTINGS).getOrThrow(NoiseGeneratorSettings.OVERWORLD);
var randomState=RandomState.create(world.lookupOrThrow(Registries.NOISE),seed,settings.value());
var biomeSource=MultiNoiseBiomeSource.createFromPreset(world.lookupOrThrow(Registries.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST).getOrThrow(MultiNoiseBiomeSourceParameterLists.OVERWORLD));
var generator=new NoiseBasedChunkGenerator(biomeSource,settings);
var state=ChunkGeneratorStructureState.createForNormal(randomState,seed,new ChunkPos(0,0),biomeSource,world.lookupOrThrow(Registries.STRUCTURE_SET));
Path tmp=Files.createTempDirectory("horizon-structures");
var storage=LevelStorageSource.createDefault(tmp).createAccess("oracle");
var templates=new StructureTemplateManager(resources,storage,DataFixers.getDataFixer(),BuiltInRegistries.BLOCK);
LevelHeightAccessor height=LevelHeightAccessor.create(-64,384);
var climate=randomState.createClimateSampler(net.minecraft.world.level.levelgen.densityfunction.SamplerContext.builder().enableCaches().build());
var structures=world.lookupOrThrow(Registries.STRUCTURE);
try(var w=new PrintWriter(Files.newBufferedWriter(out,StandardCharsets.UTF_8))) {
structures.listElements().forEach(h->w.println("registry "+h.key().identifier()+" "+h.value().step().ordinal()));
if(System.getenv("HORIZON_HEIGHTS")!=null)for(String p:System.getenv("HORIZON_HEIGHTS").split(";")){
String[] xz=p.split(",");int x=Integer.parseInt(xz[0]),z=Integer.parseInt(xz[1]);
int floor=generator.getBaseHeight(x,z,Heightmap.Types.OCEAN_FLOOR_WG,height,randomState),surface=generator.getBaseHeight(x,z,Heightmap.Types.WORLD_SURFACE_WG,height,randomState);
var resolver=biomeSource.createResolver(climate);
StringBuilder biomes=new StringBuilder();
for(int qy=(floor-12)>>2;qy<=(floor+8)>>2;qy++)biomes.append(" "+qy+":"+resolver.getNoiseBiome(x>>2,qy,z>>2).unwrapKey().get().identifier().getPath());
w.println("height "+x+" "+z+" "+floor+" "+surface+biomes);
}
for(int cx=x0;cx<=x1;cx++)for(int cz=z0;cz<=z1;cz++) {
ChunkPos pos=new ChunkPos(cx,cz);
for(var set:state.possibleStructureSets()) {
var placement=set.value().placement();var entries=set.value().structures();
if(!placement.isStructureChunk(state,cx,cz))continue;
if(System.getenv("HORIZON_PLACED")!=null)w.println("placed "+cx+" "+cz+" "+set.unwrapKey().get().identifier());
var options=new ArrayList<>(entries);
WorldgenRandom random=new WorldgenRandom(new LegacyRandomSource(0L));random.setLargeFeatureSeed(seed,cx,cz);
int total=0;for(var o:options)total+=o.weight();
while(!options.isEmpty()) {
StructureSet.StructureSelectionEntry selected;int index=0;
if(entries.size()==1){selected=options.get(0);}
else{int choice=random.nextInt(total);for(var o:options){choice-=o.weight();if(choice<0)break;index++;}selected=options.get(index);}
var structure=selected.structure();
StructureStart start=structure.value().generate(structure,Level.OVERWORLD,access,generator,biomeSource,climate,randomState,templates,seed,pos,0,height,structure.value().biomes()::contains);
if(System.getenv("HORIZON_PLACED")!=null){
w.println("generate "+structure.unwrapKey().get().identifier()+" "+start.isValid());
var ctx=new Structure.GenerationContext(access,generator,biomeSource,climate,randomState,templates,seed,pos,height,structure.value().biomes()::contains);
try{var m=Structure.class.getDeclaredMethod("findGenerationPoint",Structure.GenerationContext.class);m.setAccessible(true);
var stub=(java.util.Optional<?>)m.invoke(structure.value(),ctx);
stub.ifPresent(st->{var sp=((Structure.GenerationStub)st).position();w.println("stub "+sp+" "+ctx.biomeResolver().getNoiseBiome(sp.getX()>>2,sp.getY()>>2,sp.getZ()>>2).unwrapKey().get().identifier());});}catch(Exception e){w.println("err "+e);}
}
if(start.isValid()) {
var b=start.getBoundingBox();
w.println("start "+cx+" "+cz+" "+structure.unwrapKey().get().identifier()+" "+b.minX()+" "+b.minY()+" "+b.minZ()+" "+b.maxX()+" "+b.maxY()+" "+b.maxZ()+" "+start.getPieces().size());
for(var piece:start.getPieces()) {
var pb=piece.getBoundingBox();
String extra="";
if(piece instanceof PoolElementStructurePiece pool)extra=" "+pool.getPosition().getX()+" "+pool.getPosition().getY()+" "+pool.getPosition().getZ()+" "+pool.getRotation()+" "+pool.getGroundLevelDelta()+" "+pool.getJunctions().size()+" "+pool.getElement();
w.println("piece "+BuiltInRegistries.STRUCTURE_PIECE.getKey(piece.getType())+" "+pb.minX()+" "+pb.minY()+" "+pb.minZ()+" "+pb.maxX()+" "+pb.maxY()+" "+pb.maxZ()+extra);
}
break;
}
if(entries.size()==1)break;
options.remove(index);total-=selected.weight();
}
}
}
}
storage.close();
System.exit(0);
}
}