Last active
July 26, 2021 07:53
-
-
Save hube12/b880d2a7d24a31ae5067bd27f5d8829b to your computer and use it in GitHub Desktop.
FastRuinedPortal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.seedfinding.neil; | |
import kaptainwutax.biomeutils.source.OverworldBiomeSource; | |
import kaptainwutax.featureutils.loot.ChestContent; | |
import kaptainwutax.featureutils.loot.item.Items; | |
import kaptainwutax.featureutils.structure.RuinedPortal; | |
import kaptainwutax.featureutils.structure.generator.structure.RuinedPortalGenerator; | |
import kaptainwutax.mcutils.rand.ChunkRand; | |
import kaptainwutax.mcutils.rand.seed.StructureSeed; | |
import kaptainwutax.mcutils.state.Dimension; | |
import kaptainwutax.mcutils.util.data.Pair; | |
import kaptainwutax.mcutils.util.pos.BPos; | |
import kaptainwutax.mcutils.util.pos.CPos; | |
import kaptainwutax.mcutils.version.MCVersion; | |
import kaptainwutax.terrainutils.TerrainGenerator; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
public class Dean { | |
public static void main(String[] args) { | |
// optimization | |
ChunkRand chunkRand = new ChunkRand(); | |
System.out.println("The program has started!"); | |
MCVersion version = MCVersion.v1_16_5; | |
int validSeedCount = 0; | |
int testedWorldSeedCount = 0; | |
int testedStructureSeedCount = 0; | |
for (long structureSeed = 0L; structureSeed < 1L << 48; structureSeed++) { | |
if (++testedStructureSeedCount % 10000 == 0) { | |
System.out.printf("The program has checked %s structure seeds.\n", testedStructureSeedCount); | |
} | |
RuinedPortal ruinedPortal = new RuinedPortal(Dimension.OVERWORLD, version); | |
CPos ruinedPortalChunkPos = ruinedPortal.getInRegion(structureSeed, 0, 0, chunkRand); | |
RuinedPortalGenerator fastPortalGenerator = new RuinedPortalGenerator(version) { | |
private CPos cPos; | |
@Override | |
public boolean generateStructure(TerrainGenerator generator, int chunkX, int chunkZ, ChunkRand rand) { | |
this.cPos = new CPos(chunkX, chunkZ); | |
return true; | |
} | |
@Override | |
public List<Pair<ILootType, BPos>> getLootPos() { | |
if (cPos == null) { | |
return Collections.emptyList(); | |
} | |
return Collections.singletonList(new Pair<>(LootType.RUINED_PORTAL, cPos.toBlockPos())); | |
} | |
}; | |
if (!fastPortalGenerator.getPossibleLootItems().containsAll(Arrays.asList(Items.GOLD_BLOCK))) { | |
throw new UnsupportedOperationException("Items are missing"); | |
} | |
// fast check loot | |
boolean ignored = fastPortalGenerator.generate(null, ruinedPortalChunkPos, chunkRand); | |
if (ruinedPortal.getLoot(structureSeed, fastPortalGenerator, chunkRand, false).stream() | |
.noneMatch(chestContent -> chestContent.contains(Items.GOLD_BLOCK))) { | |
continue; | |
} | |
for (long biomeSeed = 0L; biomeSeed < 1L << 16; biomeSeed++) { | |
long worldSeed = StructureSeed.toWorldSeed(structureSeed, biomeSeed); | |
if (++testedWorldSeedCount % 10000 == 0) { | |
System.out.printf("The program has checked %s world seeds.\n", testedWorldSeedCount); | |
} | |
// check spawn | |
OverworldBiomeSource overworld = new OverworldBiomeSource(version, worldSeed); | |
if (!ruinedPortal.canSpawn(ruinedPortalChunkPos, overworld)) continue; | |
// check generate | |
RuinedPortalGenerator ruinedPortalGenerator = new RuinedPortalGenerator(version); | |
if (!ruinedPortalGenerator.generate(TerrainGenerator.of(Dimension.OVERWORLD, overworld), ruinedPortalChunkPos, chunkRand)) continue; | |
// check loot | |
List<ChestContent> chests = ruinedPortal.getLoot(structureSeed, ruinedPortalGenerator, chunkRand, false); | |
boolean isValid = false; | |
for (ChestContent chestContent : chests) { | |
if (chestContent.contains(Items.GOLD_BLOCK)) { | |
isValid = true; | |
} | |
} | |
if (!isValid) { | |
continue; | |
} | |
BPos bPos = ruinedPortalChunkPos.toBlockPos(); | |
System.out.printf("Found : %d with ruined portal : /tp @p %d ~ %d\n", worldSeed, bPos.getX(), bPos.getZ()); | |
++validSeedCount; | |
break; | |
} | |
if (validSeedCount >= 2) break; | |
} | |
System.out.println("The program has finished!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment