Skip to content

Commit

Permalink
Port seed selector to fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Jan 22, 2020
1 parent fe34aaf commit aa77a66
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ org.gradle.jvmargs=-Xmx1G
# Mod Properties
mod_version = 1.0.0
maven_group = net.earthcomputer
archives_base_name = world-gen-tests
archives_base_name = seed-selector

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.earthcomputer.seedselector.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.src.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import javax.swing.*;
import java.io.File;

@Mixin(Minecraft.class)
public abstract class MixinMinecraft {

@Shadow public static File func_6240_b() {
return null;
}

@Shadow public abstract void func_6261_a(World var1);

@Shadow public abstract void func_6263_a(World var1, String var2);

@Inject(method = "func_6247_b", at = @At("HEAD"), cancellable = true)
private void onRun(String worldName, CallbackInfo ci) {
File levelDat = new File(func_6240_b(), "saves/" + worldName + "/level.dat");
if (!levelDat.exists()) {
String answer = JOptionPane.showInputDialog(null, "Ender seed (leave blank for no seed)");
if (answer != null && !answer.isEmpty()) {
long seed;
try {
seed = Long.parseLong(answer);
} catch (NumberFormatException e) {
seed = answer.hashCode();
}
if (!validSeed(seed))
JOptionPane.showMessageDialog(null, "Note: this seed could not have been generated normally", "Warning", JOptionPane.WARNING_MESSAGE);

func_6261_a(null);
System.gc();
World world = new World(new File(func_6240_b(), "saves"), worldName, seed);
if (world.field_1033_r) {
func_6263_a(world, "Generating level");
} else {
func_6263_a(world, "Loading level");
}

ci.cancel();
}
}
}

// https://twitter.com/Geosquare_/status/1169623192153010176
boolean validSeed(long a){long b=18218081,c=1L<<48,d=7847617,e=((((d*((24667315*(a>>>32)+b*(int)a+67552711)>>32)-b*((-4824621*(a>>>32)+d*(int)a+d)>>32))-11)*0xdfe05bcb1365L)%c);return((((0x5deece66dl*e+11)%c)>>16)<<32)+(int)(((0xbb20b4600a69L*e+0x40942de6baL)%c)>>16)==a;}

}

This file was deleted.

12 changes: 6 additions & 6 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"schemaVersion": 1,
"id": "worldgentests",
"id": "seedselector",
"version": "${version}",

"name": "World Gen Tests",
"description": "World Generation Testing to help us find the pack.png seed",
"name": "Seed Selector",
"description": "Allows you to choose the world seed when generating a world",
"authors": [
"Earthcomputer"
],
"contact": {
"homepage": "https://earthcomputer.net/",
"sources": "https://github.com/Earthcomputer/pack-png-mods/world-gen-tests"
"sources": "https://github.com/pack-png-mods/seed-selector"
},

"license": "CC0-1.0",
"icon": "assets/worldgentests/icon.png",
"icon": "assets/seedselector/icon.png",

"environment": "*",
"mixins": [
"worldgentests.mixins.json"
"seedselector.mixins.json"
],

"depends": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"required": true,
"package": "net.earthcomputer.worldgentests.mixin",
"package": "net.earthcomputer.seedselector.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
Expand Down

0 comments on commit aa77a66

Please sign in to comment.