Set spawn point option

This commit is contained in:
paulevsGitch 2021-03-18 15:05:37 +03:00
parent 47ddc3a07c
commit 2f2b6dc654
2 changed files with 31 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.metadata.ModMetadata; import net.fabricmc.loader.api.metadata.ModMetadata;
@ -17,6 +18,7 @@ import net.minecraft.nbt.NbtIo;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener; import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
@ -26,6 +28,7 @@ import net.minecraft.world.level.ServerWorldProperties;
import net.minecraft.world.level.storage.LevelStorage; import net.minecraft.world.level.storage.LevelStorage;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.util.DataFixerUtil; import ru.betterend.util.DataFixerUtil;
import ru.betterend.world.generator.GeneratorOptions;
@Mixin(ServerWorld.class) @Mixin(ServerWorld.class)
public class ServerWorldMixin { public class ServerWorldMixin {
@ -57,6 +60,16 @@ public class ServerWorldMixin {
} }
} }
@Inject(method = "getSpawnPos", at = @At("HEAD"), cancellable = true)
private void be_getSpawnPos(CallbackInfoReturnable<BlockPos> info) {
if (GeneratorOptions.changeSpawn()) {
if (((ServerWorld) (Object) this).getRegistryKey() == World.END) {
info.setReturnValue(GeneratorOptions.getSpawn());
info.cancel();
}
}
}
private void be_writeDataFile(File file, String version) { private void be_writeDataFile(File file, String version) {
CompoundTag root = new CompoundTag(); CompoundTag root = new CompoundTag();
root.putString("version", version); root.putString("version", version);

View file

@ -1,5 +1,6 @@
package ru.betterend.world.generator; package ru.betterend.world.generator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import ru.betterend.config.Configs; import ru.betterend.config.Configs;
@ -20,6 +21,8 @@ public class GeneratorOptions {
public static LayerOptions bigOptions; public static LayerOptions bigOptions;
public static LayerOptions mediumOptions; public static LayerOptions mediumOptions;
public static LayerOptions smallOptions; public static LayerOptions smallOptions;
private static boolean changeSpawn;
private static BlockPos spawn;
public static void init() { public static void init() {
biomeSizeLand = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeLand", 256); biomeSizeLand = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeLand", 256);
@ -38,6 +41,12 @@ public class GeneratorOptions {
bigOptions = new LayerOptions("customGenerator.layers.bigIslands", Configs.GENERATOR_CONFIG, 300, 200, 70, 10, false); bigOptions = new LayerOptions("customGenerator.layers.bigIslands", Configs.GENERATOR_CONFIG, 300, 200, 70, 10, false);
mediumOptions = new LayerOptions("customGenerator.layers.mediumIslands", Configs.GENERATOR_CONFIG, 150, 100, 70, 20, true); mediumOptions = new LayerOptions("customGenerator.layers.mediumIslands", Configs.GENERATOR_CONFIG, 150, 100, 70, 20, true);
smallOptions = new LayerOptions("customGenerator.layers.smallIslands", Configs.GENERATOR_CONFIG, 60, 50, 70, 30, false); smallOptions = new LayerOptions("customGenerator.layers.smallIslands", Configs.GENERATOR_CONFIG, 60, 50, 70, 30, false);
changeSpawn = Configs.GENERATOR_CONFIG.getBoolean("spawn", "changeSpawn", false);
spawn = new BlockPos(
Configs.GENERATOR_CONFIG.getInt("spawn.point", "x", 20),
Configs.GENERATOR_CONFIG.getInt("spawn.point", "y", 65),
Configs.GENERATOR_CONFIG.getInt("spawn.point", "z", 0)
);
} }
public static int getBiomeSizeLand() { public static int getBiomeSizeLand() {
@ -91,4 +100,12 @@ public class GeneratorOptions {
public static int getEndCityFailChance() { public static int getEndCityFailChance() {
return endCityFailChance; return endCityFailChance;
} }
public static boolean changeSpawn() {
return changeSpawn;
}
public static BlockPos getSpawn() {
return spawn;
}
} }