Skip to content

Commit

Permalink
update to mc17
Browse files Browse the repository at this point in the history
  • Loading branch information
WearBlackAllDay committed Jun 8, 2021
1 parent 0c15215 commit cd59b49
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
implementation "com.github.KaptainWutax:SEED:b1b7c79e9b"
implementation "com.github.KaptainWutax:SEED:b090a45dd5"
implementation "com.github.wearblackallday:JavaUtils:1b369d41cd"
implementation "com.formdev:flatlaf:0.38"
implementation "com.formdev:flatlaf-intellij-themes:1.1.2"
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/wearblackallday/SeedCandy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wearblackallday;

import com.formdev.flatlaf.intellijthemes.FlatOneDarkIJTheme;
import kaptainwutax.mcutils.version.MCVersion;
import wearblackallday.components.dungeontab.DungeonTab;
import wearblackallday.components.structuretab.StructureTab;
import wearblackallday.components.worldtab.WorldTab;
Expand All @@ -11,6 +12,14 @@
import javax.swing.*;

public class SeedCandy {
public static final MCVersion[] SUPPORTED_VERSIONS = {
MCVersion.v1_17,
MCVersion.v1_16,
MCVersion.v1_15,
MCVersion.v1_14,
MCVersion.v1_13,
};

public static void main(String[] args) {
FlatOneDarkIJTheme.install();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/wearblackallday/components/SeedTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class SeedTab extends Box {
private final Box mainPanel = new Box(BoxLayout.Y_AXIS);
public static final ThreadPool POOL = new ThreadPool();

public SeedTab(String title) {
protected SeedTab(String title) {
super(BoxLayout.X_AXIS);
this.setName(title);
this.add(this.input);
Expand All @@ -21,8 +21,8 @@ public SeedTab(String title) {
}

protected void addComponents(JComponent... components) {
for(JComponent c : components) {
this.mainPanel.add(c);
for(var component : components) {
this.mainPanel.add(component);
}
}

Expand Down
31 changes: 19 additions & 12 deletions src/main/java/wearblackallday/components/dungeontab/DungeonTab.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package wearblackallday.components.dungeontab;

import kaptainwutax.biomeutils.Biome;
import kaptainwutax.seedutils.mc.MCVersion;
import kaptainwutax.biomeutils.biome.Biome;
import kaptainwutax.mcutils.version.MCVersion;
import wearblackallday.SeedCandy;
import wearblackallday.components.TextBlock;
import wearblackallday.data.Strings;
import wearblackallday.swing.SwingUtils;
Expand All @@ -11,6 +12,9 @@

import javax.swing.*;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class DungeonTab extends JComponent {
private final FloorPanel floorPanel = new FloorPanel();
Expand All @@ -29,13 +33,11 @@ public DungeonTab() {
this.updateInfo();
});

SelectionBox<Biome> biomeSelector =
new SelectionBox<>(DungeonTab::getBiomeName, Biome.THE_VOID, Biome.DESERT, Biome.SWAMP, Biome.SWAMP_HILLS);
SelectionBox<MCVersion> versionSelector =
new SelectionBox<>(MCVersion.v1_16, MCVersion.v1_15, MCVersion.v1_14, MCVersion.v1_13);
SelectionBox<Biome> biomeSelector = new SelectionBox<>(Biome::getName, getFossilBiomeSelection());
SelectionBox<MCVersion> versionSelector = new SelectionBox<>(SeedCandy.SUPPORTED_VERSIONS);

versionSelector.addActionListener(e ->
biomeSelector.setEnabled(versionSelector.getSelected() == MCVersion.v1_16));
biomeSelector.setEnabled(versionSelector.getSelected().isNewerOrEqualTo(MCVersion.v1_16)));

JComponent userEntry = new LPanel()
.addComponent(this.sizeSelector)
Expand All @@ -55,10 +57,11 @@ public DungeonTab() {
}
dungeonOutput.setText("");
Dungeon.crack(this.dungeonString.getText(), posX, posY, posZ,
versionSelector.getSelected(), biomeSelector.getSelected()).forEach(dungeonOutput::addEntry);
versionSelector.getSelected(), biomeSelector.getSelected())
.forEach(dungeonOutput::addEntry);
if(dungeonOutput.getText().isEmpty()) dungeonOutput.setText("no results");
})
.addButton("copy", (panel, button, event) ->
Strings.clipboard(dungeonOutput.getText()))
.addButton("copy", () -> Strings.clipboard(dungeonOutput.getText()))
.addComponent(this.bitLabel);

this.setLayout(new BorderLayout());
Expand All @@ -73,7 +76,11 @@ protected void updateInfo() {
this.dungeonString.setText(this.floorPanel.getString());
}

private static String getBiomeName(Biome biome) {
return biome == Biome.THE_VOID ? "other Biome" : biome.getName();
private static List<Biome> getFossilBiomeSelection() {
List<Biome> biomes = new ArrayList<>(Dungeon.FOSSIL_BIOMES);
biomes.add(new Biome(MCVersion.v1_0, null, -1, "other Biome", null,
null, Float.NaN, Float.NaN, Float.NaN, null));
biomes.sort(Comparator.comparingInt(Biome::getId));
return biomes;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package wearblackallday.components.structuretab;

import kaptainwutax.biomeutils.Biome;
import kaptainwutax.biomeutils.biome.Biome;
import kaptainwutax.biomeutils.biome.Biomes;
import kaptainwutax.biomeutils.source.OverworldBiomeSource;
import kaptainwutax.seedutils.mc.Dimension;
import kaptainwutax.mcutils.state.Dimension;
import wearblackallday.swing.SwingUtils;
import wearblackallday.swing.components.SelectionBox;
import wearblackallday.util.Filters;
Expand All @@ -11,7 +12,7 @@
import java.util.Comparator;

public class BiomeUnit extends JPanel {
private static final Biome[] BIOMES = Biome.REGISTRY.values().stream()
private static final Biome[] BIOMES = Biomes.REGISTRY.values().stream()
.filter(Filters.byKeyID(Biome::getDimension, Dimension.OVERWORLD))
.sorted(Comparator.comparing(Biome::getName))
.toArray(Biome[]::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package wearblackallday.components.structuretab;

import kaptainwutax.biomeutils.source.OverworldBiomeSource;
import kaptainwutax.seedutils.mc.MCVersion;
import kaptainwutax.seedutils.mc.seed.StructureSeed;
import kaptainwutax.mcutils.rand.seed.StructureSeed;
import kaptainwutax.mcutils.version.MCVersion;
import wearblackallday.components.SeedTab;
import wearblackallday.data.Strings;
import wearblackallday.swing.components.GridPanel;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/wearblackallday/components/worldtab/WorldTab.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package wearblackallday.components.worldtab;

import kaptainwutax.biomeutils.source.OverworldBiomeSource;
import kaptainwutax.seedutils.mc.MCVersion;
import kaptainwutax.seedutils.mc.pos.BPos;
import kaptainwutax.seedutils.mc.seed.ChunkSeeds;
import kaptainwutax.seedutils.mc.seed.WorldSeed;
import kaptainwutax.mcutils.rand.seed.ChunkSeeds;
import kaptainwutax.mcutils.rand.seed.WorldSeed;
import kaptainwutax.mcutils.util.pos.BPos;
import kaptainwutax.mcutils.version.MCVersion;
import wearblackallday.SeedCandy;
import wearblackallday.components.SeedTab;
import wearblackallday.data.Strings;
import wearblackallday.swing.components.LPanel;
Expand All @@ -17,8 +18,7 @@
public class WorldTab extends SeedTab {
public WorldTab() {
super("WorldSeed");
SelectionBox<MCVersion> versionSelector =
new SelectionBox<>(MCVersion.v1_16, MCVersion.v1_15, MCVersion.v1_14, MCVersion.v1_13);
SelectionBox<MCVersion> versionSelector = new SelectionBox<>(SeedCandy.SUPPORTED_VERSIONS);
JProgressBar progressBar = new JProgressBar(0, 1);

LPanel selectionPanel = new LPanel()
Expand All @@ -44,13 +44,13 @@ public WorldTab() {
selectionPanel.getInt("z"));

POOL.execute(this.input.getLongs(), worldSeed -> {
OverworldBiomeSource biomeSource = new OverworldBiomeSource(version, worldSeed);
var biomeSource = new OverworldBiomeSource(version, worldSeed);
if(biomeSource.getSpawnPoint().equals(target))
this.output.addEntry(worldSeed);
});
} catch(NumberFormatException exception) {
POOL.execute(this.input.getLongs(), worldSeed -> {
OverworldBiomeSource biomeSource = new OverworldBiomeSource(version, worldSeed);
var biomeSource = new OverworldBiomeSource(version, worldSeed);
this.output.addEntry(String.format("%d (%d, %d)", worldSeed,
biomeSource.getSpawnPoint().getX(), biomeSource.getSpawnPoint().getZ()));
});
Expand Down
53 changes: 28 additions & 25 deletions src/main/java/wearblackallday/util/Dungeon.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package wearblackallday.util;

import kaptainwutax.biomeutils.Biome;
import kaptainwutax.biomeutils.biome.Biome;
import kaptainwutax.biomeutils.biome.Biomes;
import kaptainwutax.mcutils.version.MCVersion;
import kaptainwutax.seedutils.lcg.LCG;
import kaptainwutax.seedutils.mc.MCVersion;
import mjtb49.hashreversals.ChunkRandomReverser;
import randomreverser.call.java.FilteredSkip;
import randomreverser.call.java.NextInt;
Expand All @@ -11,25 +12,17 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Dungeon {
public static final Set<Biome> FOSSIL_BIOMES = Set.of(Biomes.DESERT, Biomes.SWAMP, Biomes.SWAMP_HILLS);

public static List<Long> crack(String dungeonString, int posX, int posY, int posZ, MCVersion version, Biome biome) {
List<Long> structureSeeds = new ArrayList<>();
if(!dungeonString.matches("[0-2]+")) return structureSeeds;
int offsetX = posX & 15;
int offsetZ = posZ & 15;
LCG failedDungeon = LCG.JAVA.combine(-5);

JavaRandomDevice device = new JavaRandomDevice();
device.addCall(NextInt.withValue(16, offsetX));
if(version.isNewerThan(MCVersion.v1_14_4)) {
device.addCall(NextInt.withValue(16, offsetZ));
device.addCall(NextInt.withValue(256, posY));
} else {
device.addCall(NextInt.withValue(256, posY));
device.addCall(NextInt.withValue(16, offsetZ));
}
device.addCall(NextInt.consume(2, 2));
LCG failedDungeon = LCG.JAVA.combine(-5);
JavaRandomDevice device = getDungeonRand(posX, posY, posZ, version);

for(char c : dungeonString.toCharArray()) {
switch(c) {
Expand All @@ -48,23 +41,33 @@ public static List<Long> crack(String dungeonString, int posX, int posY, int pos
for(int i = 0; i < 8; i++) {
structureSeeds.addAll(ChunkRandomReverser.reversePopulationSeed(
(decoratorSeed ^ LCG.JAVA.multiplier) - getDungeonSalt(version, biome),
posX & -16,
posZ & -16,
version));
posX & -16, posZ & -16, version));
decoratorSeed = failedDungeon.nextSeed(decoratorSeed);
}
});
return structureSeeds;
}

private static long getDungeonSalt(MCVersion version, Biome biome) {
if(version != MCVersion.v1_16) return 20003L;
if(biome == Biome.DESERT ||
biome == Biome.SWAMP ||
biome == Biome.SWAMP_HILLS) {
return 30003L;
private static JavaRandomDevice getDungeonRand(int posX, int posY, int posZ, MCVersion version) {
JavaRandomDevice device = new JavaRandomDevice();
device.addCall(NextInt.withValue(16, posX & 15));
if(version.isNewerOrEqualTo(MCVersion.v1_15)) {
device.addCall(NextInt.withValue(16, posZ & 15));
device.addCall(NextInt.withValue(256, posY));
} else {
device.addCall(NextInt.withValue(256, posY));
device.addCall(NextInt.withValue(16, posZ & 15));
}
return 30002L;
device.addCall(NextInt.consume(2, 2));
return device;
}

private static long getDungeonSalt(MCVersion version, Biome biome) {
return switch(version) {
case v1_17, v1_16 -> FOSSIL_BIOMES.contains(biome) ? 30003L : 30002L;
case v1_15, v1_14, v1_13 -> 20003L;
default -> throw new IllegalArgumentException();
};
}

public enum Size {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/wearblackallday/util/QuadHuts.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package wearblackallday.util;

import kaptainwutax.biomeutils.source.OverworldBiomeSource;
import kaptainwutax.featureutils.structure.OldStructure;
import kaptainwutax.featureutils.structure.SwampHut;
import kaptainwutax.mathutils.arithmetic.Rational;
import kaptainwutax.mathutils.component.vector.QVector;
import kaptainwutax.seedutils.mc.ChunkRand;
import kaptainwutax.seedutils.mc.MCVersion;
import kaptainwutax.seedutils.mc.pos.BPos;
import kaptainwutax.seedutils.mc.pos.CPos;
import kaptainwutax.seedutils.mc.seed.RegionSeed;
import kaptainwutax.mcutils.rand.ChunkRand;
import kaptainwutax.mcutils.rand.seed.RegionSeed;
import kaptainwutax.mcutils.util.pos.BPos;
import kaptainwutax.mcutils.util.pos.CPos;
import kaptainwutax.mcutils.version.MCVersion;
import mjtb49.hashreversals.Lattice2D;

import java.io.BufferedReader;
Expand All @@ -23,8 +22,8 @@ public class QuadHuts {

public static List<BPos> find(long worldSeed, MCVersion version) {
List<BPos> quadHuts = new ArrayList<>(2);
SwampHut swampHut = new SwampHut(version);
var biomeSource = new OverworldBiomeSource(version, worldSeed);
var swampHut = new SwampHut(version);

for(long regionSeed : REGION_SEEDS) {
for(QVector solution : REGION_LATTICE.findSolutionsInBox(regionSeed - worldSeed - swampHut.getSalt(),
Expand All @@ -38,15 +37,15 @@ public static List<BPos> find(long worldSeed, MCVersion version) {
}


private static boolean checkBiomes(OverworldBiomeSource source, QVector solution, OldStructure<?> structure) {
private static boolean checkBiomes(OverworldBiomeSource source, QVector solution, SwampHut structure) {
if(checkStructure(source, solution.get(0), solution.get(1), structure)) return false;
if(checkStructure(source, solution.get(0).subtract(1), solution.get(1), structure)) return false;
if(checkStructure(source, solution.get(0), solution.get(1).subtract(1), structure)) return false;
if(checkStructure(source, solution.get(0).subtract(1), solution.get(1).subtract(1), structure)) return false;
return true;
}

private static boolean checkStructure(OverworldBiomeSource source, Rational x, Rational z, OldStructure<?> structure) {
private static boolean checkStructure(OverworldBiomeSource source, Rational x, Rational z, SwampHut structure) {
CPos chunk = structure.getInRegion(source.getWorldSeed(), x.intValue(), z.intValue(), new ChunkRand());
return !structure.canSpawn(chunk.getX(), chunk.getZ(), source);
}
Expand Down

0 comments on commit cd59b49

Please sign in to comment.