Skip to content

Commit

Permalink
Use old world gen for older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
acheong08 committed Jan 15, 2024
1 parent d5ee5a8 commit 1ffb58d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 40 deletions.
105 changes: 66 additions & 39 deletions src/main/java/anticope/rejects/commands/LocateCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package anticope.rejects.commands;

import anticope.rejects.arguments.EnumArgumentType;
import anticope.rejects.utils.WorldGenUtils;
import anticope.rejects.utils.seeds.Seeds;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.seedfinding.mccore.version.MCVersion;

import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
Expand All @@ -21,45 +24,69 @@

public class LocateCommand extends Command {

private final static DynamicCommandExceptionType NOT_FOUND = new DynamicCommandExceptionType(o -> {
if (o instanceof Cubiomes.StructureType) {
return Text.literal(String.format(
"%s not found.",
Utils.nameToTitle(o.toString().replaceAll("_", "-")))
);
}
return Text.literal("Not found.");
});
private final static DynamicCommandExceptionType NOT_FOUND = new DynamicCommandExceptionType(o -> {
if (o instanceof Cubiomes.StructureType) {
return Text.literal(String.format(
"%s not found.",
Utils.nameToTitle(o.toString().replaceAll("_", "-"))));
}
return Text.literal("Not found.");
});

public LocateCommand() {
super("locate", "Locates structures.", "loc");
}

public LocateCommand() {
super("locate", "Locates structures.", "loc");
}
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("feature")
.then(argument("feature", EnumArgumentType.enumArgument(Cubiomes.StructureType.Village)).executes(ctx -> {
Cubiomes.StructureType feature = EnumArgumentType.getEnum(ctx, "feature", Cubiomes.StructureType.Village);
BlockPos playerPos = mc.player.getBlockPos();
long seed = Seeds.get().getSeed().seed;
MCVersion version = Seeds.get().getSeed().version;
Cubiomes.MCVersion cubiomesVersion = null;
if (version.isNewerOrEqualTo(MCVersion.v1_20)) {
cubiomesVersion = Cubiomes.MCVersion.MC_1_20;
} else if (version.isNewerOrEqualTo(MCVersion.v1_19)) {
switch (version) {
case v1_19:
case v1_19_1:
cubiomesVersion = Cubiomes.MCVersion.MC_1_19;
break;
case v1_19_2:
case v1_19_3:
case v1_19_4:
cubiomesVersion = Cubiomes.MCVersion.MC_1_19_2;
break;
default:
throw new IllegalStateException("Unexpected value: " + version);
}
} else if (version.isNewerOrEqualTo(MCVersion.v1_18)) {
cubiomesVersion = Cubiomes.MCVersion.MC_1_18;
}
Pos pos = null;
if (cubiomesVersion != null) {
pos = Cubiomes.GetNearestStructure(feature, playerPos.getX(), playerPos.getZ(), seed,
Cubiomes.MCVersion.MC_1_20, 8);
} else {
BlockPos bpos = WorldGenUtils.locateFeature(feature, playerPos);
pos = new Pos();
pos.x = bpos.getX();
pos.z = bpos.getZ();

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("feature").then(argument("feature", EnumArgumentType.enumArgument(Cubiomes.StructureType.Village)).executes(ctx -> {
Cubiomes.StructureType feature = EnumArgumentType.getEnum(ctx, "feature", Cubiomes.StructureType.Village);
BlockPos playerPos = mc.player.getBlockPos();
long seed = Seeds.get().getSeed().seed;
Pos pos = Cubiomes.GetNearestStructure(feature, playerPos.getX(), playerPos.getZ(), seed, Cubiomes.MCVersion.MC_1_20, 8);
// BlockPos pos = WorldGenUtils.locateFeature(feature, playerPos);
if (pos != null) {
MutableText text = Text.literal(String.format(
"%s located at ",
Utils.nameToTitle(feature.toString().replaceAll("_", "-"))
));
Vec3d coords = new Vec3d(pos.x, 0, pos.z);
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
// coords = new Vec3d(realPos.x, 0, realPos.z);
// text = Text.literal("Just kidding, it's actually at ");
// text.append(ChatUtils.formatCoords(coords));
// text.append(".");
// info(text);
return SINGLE_SUCCESS;
}
throw NOT_FOUND.create(feature);
})));
}
}
if (pos != null) {
MutableText text = Text.literal(String.format(
"%s located at ",
Utils.nameToTitle(feature.toString().replaceAll("_", "-"))));
Vec3d coords = new Vec3d(pos.x, 0, pos.z);
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
return SINGLE_SUCCESS;
}
throw NOT_FOUND.create(feature);
})));
}
}
17 changes: 16 additions & 1 deletion src/main/java/anticope/rejects/utils/WorldGenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import anticope.rejects.utils.seeds.Seed;
import anticope.rejects.utils.seeds.Seeds;
import baritone.api.BaritoneAPI;
import cubitect.Cubiomes;

import com.seedfinding.mcbiome.source.BiomeSource;
import com.seedfinding.mcfeature.misc.SlimeChunk;
import com.seedfinding.mcfeature.structure.*;
Expand Down Expand Up @@ -126,7 +128,20 @@ public enum Feature {
desert_pyramid
}

public static BlockPos locateFeature(Feature feature, BlockPos center) {
public static BlockPos locateFeature(Cubiomes.StructureType cfeature, BlockPos center) {
Feature feature = switch (cfeature) {
case Treasure -> Feature.buried_treasure;
case Mansion -> Feature.mansion;
case Stronghold -> Feature.stronghold;
case Fortress -> Feature.nether_fortress;
case Monument -> Feature.ocean_monument;
case Bastion -> Feature.bastion_remnant;
case End_City -> Feature.end_city;
case Village -> Feature.village;
case Mineshaft -> Feature.mineshaft;
case Desert_Pyramid -> Feature.desert_pyramid;
default -> null;
};
Seed seed = Seeds.get().getSeed();
BlockPos pos = null;
if (!checkIfInDimension(getDimension(feature))) {
Expand Down

0 comments on commit 1ffb58d

Please sign in to comment.