Skip to content

Commit

Permalink
fix #31 **seeds saved b4 can have wrong versions**
Browse files Browse the repository at this point in the history
  • Loading branch information
C10udburst committed Aug 14, 2021
1 parent c6d9cc3 commit bfb9b14
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/java/cloudburst/rejects/commands/SeedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
return SINGLE_SUCCESS;
}));

builder.then(argument("seed", LongArgumentType.longArg()).then(argument("version", EnumArgumentType.enumArgument(MCVersion.v1_17_1)).executes(ctx -> {
Seeds.get().setSeed(LongArgumentType.getLong(ctx, "seed"), EnumArgumentType.getEnum(ctx, "version", MCVersion.v1_17_1));
builder.then(argument("seed", LongArgumentType.longArg()).then(argument("version", EnumArgumentType.enumArgument(MCVersion.latest())).executes(ctx -> {
Seeds.get().setSeed(LongArgumentType.getLong(ctx, "seed"), EnumArgumentType.getEnum(ctx, "version", MCVersion.latest()));
return SINGLE_SUCCESS;
})));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ServerCommand extends Command {
private final static SimpleCommandExceptionType ADDRESS_ERROR = new SimpleCommandExceptionType(new LiteralText("Couldn't obtain server address"));
private final static SimpleCommandExceptionType INVALID_RANGE = new SimpleCommandExceptionType(new LiteralText("Invalid range"));

private final static HashMap<Integer, String> ports = new HashMap();
private final static HashMap<Integer, String> ports = new HashMap<Integer, String>();

public ServerCommand() {
super("server", "Prints server information");
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/cloudburst/rejects/utils/WorldGenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
import java.util.*;
import java.util.stream.StreamSupport;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static meteordevelopment.meteorclient.utils.Utils.mc;

public class WorldGenUtils {

private static final Logger LOG = LogManager.getLogger();

private static final HashMap<Feature, List<Block>> FEATURE_BLOCKS = new HashMap<>(){{
put(Feature.nether_fortress, Arrays.asList(
Blocks.NETHER_BRICKS,
Expand Down Expand Up @@ -123,21 +128,37 @@ public static BlockPos locateFeature(Feature feature, BlockPos center) {
Seed seed = Seeds.get().getSeed();
BlockPos pos = null;
if (seed != null) {
pos = locateFeature(seed, feature, center);
try {
pos = locateFeature(seed, feature, center);
} catch (Exception | Error ex) {
LOG.error(ex);
}
if (pos != null) return pos;
}
if (mc.player != null) {
ItemStack stack = mc.player.getStackInHand(Hand.MAIN_HAND);
if (stack.getItem() != Items.FILLED_MAP)
stack = mc.player.getStackInHand(Hand.OFF_HAND);
if (stack.getItem() == Items.FILLED_MAP) {
pos = locateFeatureMap(feature, stack);
try {
pos = locateFeatureMap(feature, stack);
} catch (Exception | Error ex) {
LOG.error(ex);
}
if (pos != null) return pos;
}
}
pos = locateFeatureEntities(feature);
try {
pos = locateFeatureEntities(feature);
} catch (Exception | Error ex) {
LOG.error(ex);
}
if (pos != null) return pos;
pos = locateFeatureBlocks(feature);
try {
pos = locateFeatureBlocks(feature);
} catch (Exception | Error ex) {
LOG.error(ex);
}
return pos;
}

Expand Down Expand Up @@ -183,6 +204,7 @@ private static BlockPos locateFeature(Seed seed, Feature feature, BlockPos cente
return locateStructure(seed, feature, center);
}

// TODO: Fix LinkageError in SpiralIterator
private static BlockPos locateSlimeChunk(Seed seed, BlockPos center) {
Dimension dimension = getDimension(Feature.slime_chunk);
MCVersion mcVersion = seed.version;
Expand Down Expand Up @@ -218,6 +240,7 @@ private static BlockPos locateStructure(Seed seed, Feature feature, BlockPos cen
return toBlockPos(structurePos);
}

// TODO: Fix LinkageError in SpiralIterator
private static BPos locateStructure(Structure<?, ?> structure, BPos center, int radius, ChunkRand chunkRand, BiomeSource source, TerrainGenerator terrainGenerator) {
if (structure instanceof RegionStructure<?, ?> regionStructure) {
int chunkInRegion = regionStructure.getSpacing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RoundedRenderer2D {

public static void quadRoundedOutline(Renderer2D mb, double x, double y, double width, double height, Color color, double r, double s) {
r = getR(r, width, height);
if (r == 0) {
if (r <= 0) {
mb.quad(x, y, width, s, color);
mb.quad(x, y + height - s, width, s, color);
mb.quad(x, y + s, s, height - s * 2, color);
Expand All @@ -35,7 +35,7 @@ public static void quadRoundedOutline(Renderer2D mb, double x, double y, double

public static void quadRounded(Renderer2D mb, double x, double y, double width, double height, Color color, double r, boolean roundTop) {
r = getR(r, width, height);
if (r == 0)
if (r <= 0)
mb.quad(x, y, width, height, color);
else {
if (roundTop) {
Expand All @@ -59,7 +59,7 @@ public static void quadRounded(Renderer2D mb, double x, double y, double width,

public static void quadRoundedSide(Renderer2D mb, double x, double y, double width, double height, Color color, double r, boolean right) {
r = getR(r, width, height);
if (r == 0)
if (r <= 0)
mb.quad(x, y, width, height, color);
else {
if (right) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/cloudburst/rejects/utils/seeds/Seed.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ public class Seed {

public Seed(Long seed, MCVersion version) {
this.seed = seed;
if (version == null)
version = MCVersion.latest();
this.version = version;
}

public NbtCompound toTag() {
NbtCompound tag = new NbtCompound();
tag.put("seed", NbtLong.of(seed));
tag.put("version", NbtString.of(version.name()));
tag.put("version", NbtString.of(version.name));
return tag;
}

public static Seed fromTag(NbtCompound tag) {
return new Seed(
tag.getLong("seed"),
MCVersion.valueOf(tag.getString("version"))
MCVersion.fromString(tag.getString("version"))
);
}

Expand Down
40 changes: 36 additions & 4 deletions src/main/java/cloudburst/rejects/utils/seeds/Seeds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

import net.minecraft.client.network.ServerInfo;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.BaseText;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;

import kaptainwutax.mcutils.version.MCVersion;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.systems.System;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;

import static meteordevelopment.meteorclient.utils.Utils.mc;

Expand All @@ -28,9 +35,13 @@ public static Seeds get() {
}

public Seed getSeed() {
if (mc.isIntegratedServerRunning() && mc.getServer() != null)
return new Seed(mc.getServer().getOverworld().getSeed(), MCVersion.fromString(mc.getServer().getVersion()));

if (mc.isIntegratedServerRunning() && mc.getServer() != null) {
MCVersion version = MCVersion.fromString(mc.getServer().getVersion());
if (version == null)
version = MCVersion.latest();
return new Seed(mc.getServer().getOverworld().getSeed(), version);
}

return seeds.get(Utils.getWorldName());
}

Expand All @@ -45,8 +56,13 @@ public void setSeed(long seed) {
MCVersion ver = null;
if (server != null)
ver = MCVersion.fromString(server.version.asString());
if (ver == null)
if (ver == null) {
String targetVer = "unknown";
if (server != null) targetVer = server.version.asString();
sendInvalidVersionWarning(seed, targetVer);
ver = MCVersion.latest();
}

setSeed(seed, ver);
}

Expand All @@ -67,4 +83,20 @@ public Seeds fromTag(NbtCompound tag) {
});
return this;
}

private static void sendInvalidVersionWarning(long seed, String targetVer) {
BaseText msg = new LiteralText(String.format("Couldn't resolve minecraft version \"%s\". Using %s instead. If you wish to change the version run: ", targetVer, MCVersion.latest().name));
String cmd = String.format("%sseed %d ", Config.get().prefix, seed);
BaseText cmdText = new LiteralText(cmd+"<version>");
cmdText.setStyle(cmdText.getStyle()
.withUnderline(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, cmd))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("run command")))
);
msg.append(cmdText);
msg.setStyle(msg.getStyle()
.withColor(Formatting.YELLOW)
);
ChatUtils.sendMsg("Seed", msg);
}
}

0 comments on commit bfb9b14

Please sign in to comment.