diff --git a/build.gradle b/build.gradle index 68a3e3b..a727a72 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/src/main/java/wearblackallday/SeedCandy.java b/src/main/java/wearblackallday/SeedCandy.java index fadb78d..e28433c 100644 --- a/src/main/java/wearblackallday/SeedCandy.java +++ b/src/main/java/wearblackallday/SeedCandy.java @@ -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; @@ -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(); diff --git a/src/main/java/wearblackallday/components/SeedTab.java b/src/main/java/wearblackallday/components/SeedTab.java index 8003007..0edf826 100644 --- a/src/main/java/wearblackallday/components/SeedTab.java +++ b/src/main/java/wearblackallday/components/SeedTab.java @@ -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); @@ -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); } } diff --git a/src/main/java/wearblackallday/components/dungeontab/DungeonTab.java b/src/main/java/wearblackallday/components/dungeontab/DungeonTab.java index a4187cb..b66c33b 100644 --- a/src/main/java/wearblackallday/components/dungeontab/DungeonTab.java +++ b/src/main/java/wearblackallday/components/dungeontab/DungeonTab.java @@ -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; @@ -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(); @@ -29,13 +33,11 @@ public DungeonTab() { this.updateInfo(); }); - SelectionBox biomeSelector = - new SelectionBox<>(DungeonTab::getBiomeName, Biome.THE_VOID, Biome.DESERT, Biome.SWAMP, Biome.SWAMP_HILLS); - SelectionBox versionSelector = - new SelectionBox<>(MCVersion.v1_16, MCVersion.v1_15, MCVersion.v1_14, MCVersion.v1_13); + SelectionBox biomeSelector = new SelectionBox<>(Biome::getName, getFossilBiomeSelection()); + SelectionBox 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) @@ -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()); @@ -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 getFossilBiomeSelection() { + List 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; } } diff --git a/src/main/java/wearblackallday/components/structuretab/BiomeUnit.java b/src/main/java/wearblackallday/components/structuretab/BiomeUnit.java index c11bbe6..061b337 100644 --- a/src/main/java/wearblackallday/components/structuretab/BiomeUnit.java +++ b/src/main/java/wearblackallday/components/structuretab/BiomeUnit.java @@ -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; @@ -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); diff --git a/src/main/java/wearblackallday/components/structuretab/StructureTab.java b/src/main/java/wearblackallday/components/structuretab/StructureTab.java index 914b404..b81acd0 100644 --- a/src/main/java/wearblackallday/components/structuretab/StructureTab.java +++ b/src/main/java/wearblackallday/components/structuretab/StructureTab.java @@ -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; diff --git a/src/main/java/wearblackallday/components/worldtab/WorldTab.java b/src/main/java/wearblackallday/components/worldtab/WorldTab.java index 1bbbd72..ff1a602 100644 --- a/src/main/java/wearblackallday/components/worldtab/WorldTab.java +++ b/src/main/java/wearblackallday/components/worldtab/WorldTab.java @@ -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; @@ -17,8 +18,7 @@ public class WorldTab extends SeedTab { public WorldTab() { super("WorldSeed"); - SelectionBox versionSelector = - new SelectionBox<>(MCVersion.v1_16, MCVersion.v1_15, MCVersion.v1_14, MCVersion.v1_13); + SelectionBox versionSelector = new SelectionBox<>(SeedCandy.SUPPORTED_VERSIONS); JProgressBar progressBar = new JProgressBar(0, 1); LPanel selectionPanel = new LPanel() @@ -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())); }); diff --git a/src/main/java/wearblackallday/util/Dungeon.java b/src/main/java/wearblackallday/util/Dungeon.java index 959449d..0e08eaa 100644 --- a/src/main/java/wearblackallday/util/Dungeon.java +++ b/src/main/java/wearblackallday/util/Dungeon.java @@ -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; @@ -11,25 +12,17 @@ import java.util.ArrayList; import java.util.List; +import java.util.Set; public class Dungeon { + public static final Set FOSSIL_BIOMES = Set.of(Biomes.DESERT, Biomes.SWAMP, Biomes.SWAMP_HILLS); + public static List crack(String dungeonString, int posX, int posY, int posZ, MCVersion version, Biome biome) { List 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) { @@ -48,23 +41,33 @@ public static List 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 { diff --git a/src/main/java/wearblackallday/util/QuadHuts.java b/src/main/java/wearblackallday/util/QuadHuts.java index 4dfa266..19e0893 100755 --- a/src/main/java/wearblackallday/util/QuadHuts.java +++ b/src/main/java/wearblackallday/util/QuadHuts.java @@ -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; @@ -23,8 +22,8 @@ public class QuadHuts { public static List find(long worldSeed, MCVersion version) { List 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(), @@ -38,7 +37,7 @@ public static List 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; @@ -46,7 +45,7 @@ private static boolean checkBiomes(OverworldBiomeSource source, QVector solution 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); }