Last active
August 29, 2021 13:15
-
-
Save hube12/1ade36199940f20e66da87f97325e890 to your computer and use it in GitHub Desktop.
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 neil; | |
import kaptainwutax.featureutils.structure.*; | |
import kaptainwutax.mcutils.rand.ChunkRand; | |
import kaptainwutax.mcutils.util.pos.CPos; | |
import kaptainwutax.mcutils.util.pos.RPos; | |
import kaptainwutax.mcutils.version.MCVersion; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
import java.util.stream.Collectors; | |
import java.util.stream.LongStream; | |
import java.util.stream.Stream; | |
public class LiftingExample { | |
public static final MCVersion VERSION = MCVersion.v1_16_5; | |
public static final DesertPyramid DESERT_PYRAMID = new DesertPyramid(VERSION); | |
public static final SwampHut SWAMP_HUT = new SwampHut(VERSION); | |
public static final Igloo IGLOO = new Igloo(VERSION); | |
public static final JunglePyramid JUNGLE_TEMPLE = new JunglePyramid(VERSION); | |
public static void main(String[] args) { | |
test(); | |
} | |
public static List<Long> crack(List<OldStructure.Data<?>> dataList) { | |
Stream<Long> lowerBitsStream = LongStream.range(0, 1L << 19).boxed().filter(lowerBits -> { | |
ChunkRand rand= new ChunkRand(); | |
for (OldStructure.Data<?> data : dataList) { | |
rand.setRegionSeed(lowerBits, data.regionX, data.regionZ, data.feature.getSalt(), VERSION); | |
if (rand.nextInt(24) % 4 != data.offsetX % 4 || rand.nextInt(24) % 4 != data.offsetZ % 4) { | |
return false; | |
} | |
} | |
return true; | |
}); | |
Stream<Long> seedStream = lowerBitsStream | |
.flatMap(lowerBits -> | |
LongStream.range(0, 1L << (48 - 19)) | |
.boxed() | |
.map(upperBits -> (upperBits << 19) | lowerBits) | |
); | |
Stream<Long> strutureSeedStream = seedStream.filter(seed -> { | |
ChunkRand rand= new ChunkRand(); | |
for (RegionStructure.Data<?> data : dataList) { | |
rand.setRegionSeed(seed, data.regionX, data.regionZ, data.feature.getSalt(), VERSION); | |
if (rand.nextInt(24) != data.offsetX || rand.nextInt(24) != data.offsetZ) { | |
return false; | |
} | |
} | |
return true; | |
}); | |
return strutureSeedStream.parallel().collect(Collectors.toList()); | |
} | |
public static void test() { | |
long structureSeed = 90212; | |
List<OldStructure.Data<?>> dataList = new ArrayList<>(); | |
dataList.addAll(generateData(structureSeed, SWAMP_HUT, 3)); | |
dataList.addAll(generateData(structureSeed, IGLOO, 3)); | |
dataList.addAll(generateData(structureSeed, DESERT_PYRAMID, 3)); | |
dataList.addAll(generateData(structureSeed, JUNGLE_TEMPLE, 3)); | |
List<Long> seeds = crack(dataList); | |
for (Long seed : seeds) { | |
System.out.println(seed); | |
} | |
} | |
public static List<OldStructure.Data<?>> generateData(long structureSeed, RegionStructure<?, ?> regionStructure, int count) { | |
List<OldStructure.Data<?>> res = new ArrayList<>(count); | |
ChunkRand rand = new ChunkRand(); | |
for (int i = 0; i < count; i++) { | |
RPos rpos = getRandomRPos(); | |
CPos cPos = regionStructure.getInRegion(structureSeed, rpos.getX(), rpos.getZ(), rand); | |
res.add(regionStructure.at(cPos.getX(), cPos.getZ())); | |
} | |
return res; | |
} | |
public static RPos getRandomRPos() { | |
Random random = new Random(); | |
return new RPos(random.nextInt(10000) - 5000, random.nextInt(10000) - 5000, DESERT_PYRAMID.getSpacing()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment