Skip to content

Commit

Permalink
Add mineshaft feature + check if dimension is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
xpple committed Jun 15, 2021
1 parent 117e6e6 commit d23ba67
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dev.xpple.seedmapper.command;

import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.text.TranslatableText;

public interface SharedExceptions {
DynamicCommandExceptionType NULL_POINTER_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.nullPointerException", arg));
DynamicCommandExceptionType DIMENSION_NOT_SUPPORTED_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.dimensionNotSupported", arg));
DynamicCommandExceptionType VERSION_NOT_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.versionNotFound", arg));
SimpleCommandExceptionType INVALID_DIMENSION_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.exceptions.invalidDimension"));
DynamicCommandExceptionType BIOME_NOT_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.biomeNotFound", arg));
DynamicCommandExceptionType STRUCTURE_NOT_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.structureNotFound", arg));
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import kaptainwutax.biomeutils.source.BiomeSource;
import kaptainwutax.featureutils.Feature;
import kaptainwutax.featureutils.misc.SlimeChunk;
import kaptainwutax.featureutils.structure.Mineshaft;
import kaptainwutax.featureutils.structure.RegionStructure;
import kaptainwutax.featureutils.structure.Stronghold;
import kaptainwutax.featureutils.structure.Structure;
Expand Down Expand Up @@ -130,7 +131,10 @@ private int locateBiome(FabricClientCommandSource source, String biomeName, Stri
return Command.SINGLE_SUCCESS;
}

private static BPos locateBiome(Biome biome, int centerX, int centerZ, int radius, int increment, BiomeSource biomeSource) {
private static BPos locateBiome(Biome biome, int centerX, int centerZ, int radius, int increment, BiomeSource biomeSource) throws CommandSyntaxException {
if (biome.getDimension() != biomeSource.getDimension()) {
throw INVALID_DIMENSION_EXCEPTION.create();
}
if (biome.equals(biomeSource.getBiome(centerX, 0, centerZ))) {
return new BPos(centerX, 0, centerZ);
}
Expand Down Expand Up @@ -217,7 +221,10 @@ private int locateStructure(FabricClientCommandSource source, String structureNa
return Command.SINGLE_SUCCESS;
}

private static BPos locateStructure(Structure<?, ?> structure, BPos currentPos, int radius, ChunkRand chunkRand, BiomeSource source, TerrainGenerator terrainGenerator, int dimCoeff) {
private static BPos locateStructure(Structure<?, ?> structure, BPos currentPos, int radius, ChunkRand chunkRand, BiomeSource source, TerrainGenerator terrainGenerator, int dimCoeff) throws CommandSyntaxException {
if (!structure.isValidDimension(source.getDimension())) {
throw INVALID_DIMENSION_EXCEPTION.create();
}
if (structure instanceof RegionStructure<?, ?> regionStructure) {
int chunkInRegion = regionStructure.getSpacing();
int regionSize = chunkInRegion * 16;
Expand Down Expand Up @@ -262,6 +269,27 @@ private static BPos locateStructure(Structure<?, ?> structure, BPos currentPos,
}
BPos dimPos = closest.toBlockPos().add(9, 0, 9);
return new BPos(dimPos.getX() << dimCoeff, 0, dimPos.getZ() << dimCoeff);
} else if (structure instanceof Mineshaft mineshaft) {
int x = currentPos.getX() >> 4;
int z = currentPos.getZ() >> 4;

float n = 1;
int floorN = 1;
for (int i = 0; floorN / 2 < radius; i++, n += 0.5) {
floorN = (int) Math.floor(n);
for (int j = 0; j < floorN; j++) {
switch (i % 4) {
case 0 -> z++;
case 1 -> x++;
case 2 -> z--;
case 3 -> x--;
}
Feature.Data<Mineshaft> data = mineshaft.at(x, z);
if (data.testStart(source.getWorldSeed(), chunkRand) && data.testBiome(source) && data.testGenerate(terrainGenerator)) {
return new BPos(x << 4, 0, z << 4);
}
}
}
}
}
return null;
Expand Down Expand Up @@ -295,7 +323,7 @@ private static int locateSlimeChunk(FabricClientCommandSource source, String ver

BlockPos center = CLIENT.player.getBlockPos();

CPos slimeChunkPos = locateSlimeChunk(new SlimeChunk(mcVersion), center.getX(), center.getZ(), 6400, seed, new ChunkRand(seed));
CPos slimeChunkPos = locateSlimeChunk(new SlimeChunk(mcVersion), center.getX(), center.getZ(), 6400, seed, new ChunkRand(seed), dimension);
if (slimeChunkPos == null) {
Chat.print("", new TranslatableText("command.locate.feature.slimeChunk.noneFound"));
} else {
Expand Down Expand Up @@ -324,7 +352,10 @@ private static int locateSlimeChunk(FabricClientCommandSource source, String ver
return Command.SINGLE_SUCCESS;
}

private static CPos locateSlimeChunk(SlimeChunk slimeChunk, int centerX, int centerZ, int radius, long seed, ChunkRand rand) {
private static CPos locateSlimeChunk(SlimeChunk slimeChunk, int centerX, int centerZ, int radius, long seed, ChunkRand rand, Dimension dimension) throws CommandSyntaxException {
if (!slimeChunk.isValidDimension(dimension)) {
throw INVALID_DIMENSION_EXCEPTION.create();
}
int x = centerX >> 4;
int z = centerZ >> 4;

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/seedmapper/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"commands.exceptions.versionNotFound": "Version \"%s\" was not found.",
"commands.exceptions.unknownConfig": "Unknown config \"%s\".",
"commands.exceptions.nullPointerException": "\"%s\" is null.",
"commands.exceptions.invalidDimension": "Invalid dimension.",
"commands.exceptions.biomeNotFound": "Biome \"%s\" was not found.",
"commands.exceptions.structureNotFound": "Structure \"%s\" was not found.",

Expand Down

0 comments on commit d23ba67

Please sign in to comment.