diff --git a/src/main/java/cloudburst/rejects/commands/SeedCommand.java b/src/main/java/cloudburst/rejects/commands/SeedCommand.java index 472ef15..11ee7ed 100644 --- a/src/main/java/cloudburst/rejects/commands/SeedCommand.java +++ b/src/main/java/cloudburst/rejects/commands/SeedCommand.java @@ -59,8 +59,8 @@ public class SeedCommand extends Command { 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; }))); } diff --git a/src/main/java/cloudburst/rejects/commands/ServerCommand.java b/src/main/java/cloudburst/rejects/commands/ServerCommand.java index 9b95bb5..1f9312a 100644 --- a/src/main/java/cloudburst/rejects/commands/ServerCommand.java +++ b/src/main/java/cloudburst/rejects/commands/ServerCommand.java @@ -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 ports = new HashMap(); + private final static HashMap ports = new HashMap(); public ServerCommand() { super("server", "Prints server information"); diff --git a/src/main/java/cloudburst/rejects/utils/WorldGenUtils.java b/src/main/java/cloudburst/rejects/utils/WorldGenUtils.java index 8470f4e..96a7e91 100644 --- a/src/main/java/cloudburst/rejects/utils/WorldGenUtils.java +++ b/src/main/java/cloudburst/rejects/utils/WorldGenUtils.java @@ -29,10 +29,15 @@ import net.minecraft.util.math.BlockPos; 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_BLOCKS = new HashMap<>(){{ put(Feature.nether_fortress, Arrays.asList( Blocks.NETHER_BRICKS, @@ -123,7 +128,11 @@ public class WorldGenUtils { 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) { @@ -131,13 +140,25 @@ public class WorldGenUtils { 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; } @@ -183,6 +204,7 @@ public class WorldGenUtils { 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; @@ -218,6 +240,7 @@ public class WorldGenUtils { 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(); diff --git a/src/main/java/cloudburst/rejects/utils/gui/RoundedRenderer2D.java b/src/main/java/cloudburst/rejects/utils/gui/RoundedRenderer2D.java index 8b4ca72..78c0d72 100644 --- a/src/main/java/cloudburst/rejects/utils/gui/RoundedRenderer2D.java +++ b/src/main/java/cloudburst/rejects/utils/gui/RoundedRenderer2D.java @@ -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); @@ -35,7 +35,7 @@ public class RoundedRenderer2D { 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) { @@ -59,7 +59,7 @@ public class RoundedRenderer2D { 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) { diff --git a/src/main/java/cloudburst/rejects/utils/seeds/Seed.java b/src/main/java/cloudburst/rejects/utils/seeds/Seed.java index 6101d3b..ae85d38 100644 --- a/src/main/java/cloudburst/rejects/utils/seeds/Seed.java +++ b/src/main/java/cloudburst/rejects/utils/seeds/Seed.java @@ -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")) ); } diff --git a/src/main/java/cloudburst/rejects/utils/seeds/Seeds.java b/src/main/java/cloudburst/rejects/utils/seeds/Seeds.java index a80aabb..b29cc67 100644 --- a/src/main/java/cloudburst/rejects/utils/seeds/Seeds.java +++ b/src/main/java/cloudburst/rejects/utils/seeds/Seeds.java @@ -4,11 +4,18 @@ import java.util.HashMap; 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; @@ -28,9 +35,13 @@ public class Seeds extends System { } 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()); } @@ -45,8 +56,13 @@ public class Seeds extends System { 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); } @@ -67,4 +83,20 @@ public class Seeds extends System { }); 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+""); + 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); + } }