use of com.seedfinding.mccore.rand.ChunkRand in project SeedcrackerX by 19MisterX98.
the class TimeMachine method pokeLifting.
protected boolean pokeLifting() {
if (!this.structureSeeds.isEmpty() || this.dataStorage.getLiftingBits() < 40F)
return false;
List<UniformStructure.Data<?>> dataList = new ArrayList<>();
for (DataStorage.Entry<Feature.Data<?>> e : this.dataStorage.baseSeedData) {
if (e.data.feature instanceof OldStructure || e.data.feature instanceof Shipwreck) {
dataList.add((UniformStructure.Data<?>) e.data);
}
}
List<Feature.Data<?>> cache = new ArrayList<>();
for (DataStorage.Entry<Feature.Data<?>> entry : this.dataStorage.baseSeedData) {
if (!(entry.data.feature instanceof Decorator) || entry.data.feature.getVersion().isOlderThan(MCVersion.v1_18)) {
if (!(entry.data.feature instanceof PillagerOutpost)) {
cache.add(entry.data);
}
}
}
Log.warn("tmachine.startLifting", dataList.size());
// You could first lift on 1L<<18 with %2 since that would be a smaller range
// Then lift on 1<<19 with those 1<<18 fixed with % 4 and for nextInt(24)
// You can even do %8 on 1<<20 (however we included shipwreck so only nextInt(20) so 1<<19 is the max here
Stream<Long> lowerBitsStream = LongStream.range(0, 1L << 19).boxed().filter(lowerBits -> {
ChunkRand rand = new ChunkRand();
for (UniformStructure.Data<?> data : dataList) {
rand.setRegionSeed(lowerBits, data.regionX, data.regionZ, data.feature.getSalt(), Config.get().getVersion());
if (rand.nextInt(((UniformStructure<?>) data.feature).getOffset()) % 4 != data.offsetX % 4 || rand.nextInt(((UniformStructure<?>) data.feature).getOffset()) % 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 (Feature.Data<?> data : cache) {
if (!data.testStart(seed, rand)) {
return false;
}
}
return true;
});
this.structureSeeds = strutureSeedStream.parallel().collect(Collectors.toSet());
if (!this.structureSeeds.isEmpty()) {
Log.warn("tmachine.structureSeedSearchFinished");
} else {
Log.error("finishedSearchNoResult");
}
return !this.structureSeeds.isEmpty();
}
use of com.seedfinding.mccore.rand.ChunkRand in project SeedcrackerX by 19MisterX98.
the class TimeMachine method pokeStructures.
protected boolean pokeStructures() {
if (this.pillarSeeds == null || !this.structureSeeds.isEmpty() || this.dataStorage.getBaseBits() < this.dataStorage.getWantedBits())
return false;
List<Feature.Data<?>> cache = new ArrayList<>();
for (DataStorage.Entry<Feature.Data<?>> entry : this.dataStorage.baseSeedData) {
if (!(entry.data.feature instanceof Decorator) || entry.data.feature.getVersion().isOlderThan(MCVersion.v1_18)) {
if (!(entry.data.feature instanceof PillagerOutpost)) {
cache.add(entry.data);
}
}
}
for (int pillarSeed : this.pillarSeeds) {
Log.debug("====================================");
Log.warn("tmachine.lookingForStructureSeeds", pillarSeed);
AtomicInteger completion = new AtomicInteger();
ProgressListener progressListener = new ProgressListener();
for (int threadId = 0; threadId < 4; threadId++) {
int fThreadId = threadId;
SERVICE.submit(() -> {
ChunkRand rand = new ChunkRand();
long lower = (long) fThreadId * (1L << 30);
long upper = (long) (fThreadId + 1) * (1L << 30);
for (long partialWorldSeed = lower; partialWorldSeed < upper && !this.shouldTerminate; partialWorldSeed++) {
if ((partialWorldSeed & ((1 << 27) - 1)) == 0) {
progressListener.addPercent(3.125F, true);
}
long seed = this.timeMachine(partialWorldSeed, pillarSeed);
boolean matches = true;
for (Feature.Data<?> baseSeedDatum : cache) {
if (!baseSeedDatum.testStart(seed, rand)) {
matches = false;
break;
}
}
if (matches) {
this.structureSeeds.add(seed);
Log.printSeed("foundStructureSeed", seed);
}
}
completion.getAndIncrement();
});
}
while (completion.get() != 4) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (this.shouldTerminate) {
return false;
}
}
progressListener.addPercent(0.0F, true);
}
if (!this.structureSeeds.isEmpty()) {
Log.warn("tmachine.structureSeedSearchFinished");
} else {
Log.error("finishedSearchNoResult");
}
return true;
}
use of com.seedfinding.mccore.rand.ChunkRand in project SeedcrackerX by 19MisterX98.
the class TimeMachine method pokeStructureReduce.
protected boolean pokeStructureReduce() {
if (shouldTerminate)
return false;
if (!this.worldSeeds.isEmpty() || this.structureSeeds.size() < 2)
return false;
if (Config.get().getVersion().isOlderThan(MCVersion.v1_13))
return false;
Set<Long> result = new HashSet<>();
Log.debug("====================================");
Log.warn("tmachine.reduceSeeds", this.structureSeeds.size());
if (this.pillarSeeds != null) {
structureSeeds.forEach(seed -> {
if (this.pillarSeeds.contains((int) PillarSeed.fromStructureSeed(seed))) {
result.add(seed);
}
});
}
if (result.size() != 1) {
this.dataStorage.baseSeedData.dump();
this.dataStorage.baseSeedData.getBaseSet().removeIf(dataEntry -> !dataEntry.data.feature.getVersion().equals(Config.get().getVersion()));
List<Feature.Data<?>> cache = new ArrayList<>();
for (DataStorage.Entry<Feature.Data<?>> entry : this.dataStorage.baseSeedData) {
if (!(entry.data.feature instanceof Decorator) || entry.data.feature.getVersion().isOlderThan(MCVersion.v1_18)) {
// todo remove this when libs are updated
if (!(entry.data.feature instanceof PillagerOutpost)) {
cache.add(entry.data);
}
}
}
ChunkRand rand = new ChunkRand();
for (Long seed : this.structureSeeds) {
boolean matches = true;
for (Feature.Data<?> baseSeedDatum : cache) {
if (!baseSeedDatum.testStart(seed, rand)) {
matches = false;
break;
}
}
if (matches) {
result.add(seed);
}
}
}
if (!result.isEmpty() && this.structureSeeds.size() > result.size()) {
if (result.size() < 10) {
result.forEach(seed -> Log.printSeed("foundStructureSeed", seed));
} else {
Log.warn("tmachine.succeedReducing", result.size());
}
this.structureSeeds = result;
return true;
} else {
Log.warn("tmachine.failedReducing");
}
return false;
}
Aggregations