From 56591633ecfac62c76b455afd3b0ef95e1a000f4 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 13 Jan 2021 13:34:43 +0300 Subject: [PATCH] Player spawn in Overworld fix --- src/main/java/ru/betterend/BetterEnd.java | 2 - .../ru/betterend/blocks/EndPortalBlock.java | 2 - .../mixin/common/MinecraftServerMixin.java | 38 +++ .../common/NoiseChunkGeneratorMixin.java | 3 +- .../mixin/common/PlayerManagerMixin.java | 260 ++++++++++++++++++ .../mixin/common/ServerPlayerEntityMixin.java | 33 ++- .../java/ru/betterend/registry/EndBiomes.java | 2 +- .../world/generator/BetterEndBiomeSource.java | 4 +- .../world/generator/GeneratorOptions.java | 18 ++ .../world/generator/IslandLayer.java | 14 +- .../world/generator/TerrainGenerator.java | 28 +- .../resources/betterend.mixins.common.json | 7 +- 12 files changed, 370 insertions(+), 41 deletions(-) create mode 100644 src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java diff --git a/src/main/java/ru/betterend/BetterEnd.java b/src/main/java/ru/betterend/BetterEnd.java index f58d6399..9169d613 100644 --- a/src/main/java/ru/betterend/BetterEnd.java +++ b/src/main/java/ru/betterend/BetterEnd.java @@ -31,7 +31,6 @@ import ru.betterend.util.BonemealUtil; import ru.betterend.util.Logger; import ru.betterend.world.generator.BetterEndBiomeSource; import ru.betterend.world.generator.GeneratorOptions; -import ru.betterend.world.generator.TerrainGenerator; import ru.betterend.world.surface.SurfaceBuilders; public class BetterEnd implements ModInitializer { @@ -60,7 +59,6 @@ public class BetterEnd implements ModInitializer { EndStructures.register(); Integrations.register(); BonemealUtil.init(); - TerrainGenerator.init(); GeneratorOptions.init(); if (hasGuideBook()) { diff --git a/src/main/java/ru/betterend/blocks/EndPortalBlock.java b/src/main/java/ru/betterend/blocks/EndPortalBlock.java index 63b1e8a1..8e882f56 100644 --- a/src/main/java/ru/betterend/blocks/EndPortalBlock.java +++ b/src/main/java/ru/betterend/blocks/EndPortalBlock.java @@ -111,8 +111,6 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable while (checkPos.getY() > 5) { BlockState state = world.getBlockState(checkPos); if (state.isOf(this)) { - System.out.println("Out: " + checkPos); - Axis axis = state.get(AXIS); checkPos = this.findCenter(world, checkPos, axis); diff --git a/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java index 960f7ee4..f739527e 100644 --- a/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java @@ -15,9 +15,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resource.ServerResourceManager; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.WorldGenerationProgressListener; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.SaveProperties; import net.minecraft.world.World; +import net.minecraft.world.level.ServerWorldProperties; import ru.betterend.recipe.EndRecipeManager; import ru.betterend.registry.EndBiomes; import ru.betterend.world.generator.GeneratorOptions; @@ -30,6 +34,10 @@ public class MinecraftServerMixin { @Final @Shadow private Map, ServerWorld> worlds; + + @Final + @Shadow + protected SaveProperties saveProperties; @Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true) private void beOnReload(Collection collection, CallbackInfoReturnable> info) { @@ -53,6 +61,36 @@ public class MinecraftServerMixin { info.cancel(); } } + + @Inject(method = "createWorlds", at = @At(value = "TAIL")) + private final void be_CreateWorlds(WorldGenerationProgressListener worldGenerationProgressListener, CallbackInfo info) { + if (GeneratorOptions.swapOverworldToEnd()) { + ServerWorld world = worlds.get(World.END); + if (world == null) { + world = worlds.get(World.OVERWORLD); + } + this.getPlayerManager().setMainWorld(world); + ServerWorldProperties serverWorldProperties = saveProperties.getMainWorldProperties(); + net.minecraft.world.gen.GeneratorOptions generatorOptions = saveProperties.getGeneratorOptions(); + boolean bl = generatorOptions.isDebugWorld(); + setupSpawn(world, serverWorldProperties, generatorOptions.hasBonusChest(), bl, true); + } + } + + @Inject(method = "setupSpawn", at = @At(value = "HEAD"), cancellable = true) + private static void be_SetupSpawn(ServerWorld world, ServerWorldProperties serverWorldProperties, boolean bonusChest, boolean debugWorld, boolean bl, CallbackInfo info) { + if (GeneratorOptions.swapOverworldToEnd() && world.getRegistryKey() == World.OVERWORLD) { + info.cancel(); + } + } + + @Shadow + private static void setupSpawn(ServerWorld world, ServerWorldProperties serverWorldProperties, boolean bonusChest, boolean debugWorld, boolean bl) {} + + @Shadow + public PlayerManager getPlayerManager() { + return null; + } private void beInjectRecipes() { if (FabricLoader.getInstance().isModLoaded("kubejs")) { diff --git a/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java b/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java index 695603f5..a41e262b 100644 --- a/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java +++ b/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java @@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; import net.minecraft.world.gen.chunk.NoiseChunkGenerator; +import ru.betterend.world.generator.GeneratorOptions; import ru.betterend.world.generator.TerrainGenerator; @Mixin(NoiseChunkGenerator.class) @@ -27,7 +28,7 @@ public abstract class NoiseChunkGeneratorMixin { @Inject(method = "sampleNoiseColumn([DII)V", at = @At("HEAD"), cancellable = true, allow = 2) private void beSampleNoiseColumn(double[] buffer, int x, int z, CallbackInfo info) { - if (TerrainGenerator.useNewGenerator() && settings.get().equals(ChunkGeneratorSettings.END)) { + if (GeneratorOptions.useNewGenerator() && settings.get().equals(ChunkGeneratorSettings.END)) { if (TerrainGenerator.canGenerate(x, z)) { TerrainGenerator.fillTerrainDensity(buffer, x, z); info.cancel(); diff --git a/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java b/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java new file mode 100644 index 00000000..7bcb80e6 --- /dev/null +++ b/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java @@ -0,0 +1,260 @@ +package ru.betterend.mixin.common; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.mojang.authlib.GameProfile; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.Dynamic; + +import io.netty.buffer.Unpooled; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.MessageType; +import net.minecraft.network.Packet; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.play.DifficultyS2CPacket; +import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket; +import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import net.minecraft.network.packet.s2c.play.HeldItemChangeS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; +import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket; +import net.minecraft.network.packet.s2c.play.SynchronizeTagsS2CPacket; +import net.minecraft.scoreboard.ServerScoreboard; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; +import net.minecraft.util.UserCache; +import net.minecraft.util.Util; +import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.GameRules; +import net.minecraft.world.World; +import net.minecraft.world.WorldProperties; +import net.minecraft.world.biome.source.BiomeAccess; +import net.minecraft.world.dimension.DimensionType; +import ru.betterend.world.generator.GeneratorOptions; + +@Mixin(PlayerManager.class) +public class PlayerManagerMixin { + @Final + @Shadow + private static Logger LOGGER; + + @Final + @Shadow + private MinecraftServer server; + + @Final + @Shadow + private DynamicRegistryManager.Impl registryManager; + + @Shadow + private int viewDistance; + + @Final + @Shadow + private List players; + + @Final + @Shadow + private Map playerMap; + + @Inject(method = "onPlayerConnect", at = @At(value = "HEAD"), cancellable = true) + public void be_onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) { + if (GeneratorOptions.swapOverworldToEnd()) { + GameProfile gameProfile = player.getGameProfile(); + UserCache userCache = this.server.getUserCache(); + GameProfile gameProfile2 = userCache.getByUuid(gameProfile.getId()); + String string = gameProfile2 == null ? gameProfile.getName() : gameProfile2.getName(); + userCache.add(gameProfile); + CompoundTag compoundTag = this.loadPlayerData(player); + RegistryKey var23; + if (compoundTag != null) { + DataResult> var10000 = DimensionType.method_28521(new Dynamic(NbtOps.INSTANCE, compoundTag.get("Dimension"))); + Logger var10001 = LOGGER; + var10001.getClass(); + var23 = (RegistryKey) var10000.resultOrPartial(var10001::error).orElse(World.END); + } + else { + var23 = World.END; + } + + System.out.println("World " + this.server.getWorld(World.END)); + + RegistryKey registryKey = var23; + ServerWorld serverWorld = this.server.getWorld(registryKey); + ServerWorld serverWorld3; + if (serverWorld == null) { + LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", registryKey); + serverWorld3 = this.server.getOverworld(); + } + else { + serverWorld3 = serverWorld; + } + + player.setWorld(serverWorld3); + player.interactionManager.setWorld((ServerWorld) player.world); + String string2 = "local"; + if (connection.getAddress() != null) { + string2 = connection.getAddress().toString(); + } + + LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", player.getName().getString(), string2, player.getEntityId(), player.getX(), player.getY(), player.getZ()); + WorldProperties worldProperties = serverWorld3.getLevelProperties(); + this.setGameMode(player, (ServerPlayerEntity) null, serverWorld3); + ServerPlayNetworkHandler serverPlayNetworkHandler = new ServerPlayNetworkHandler(this.server, connection, player); + GameRules gameRules = serverWorld3.getGameRules(); + boolean bl = gameRules.getBoolean(GameRules.DO_IMMEDIATE_RESPAWN); + boolean bl2 = gameRules.getBoolean(GameRules.REDUCED_DEBUG_INFO); + serverPlayNetworkHandler.sendPacket(new GameJoinS2CPacket(player.getEntityId(), player.interactionManager.getGameMode(), player.interactionManager.getPreviousGameMode(), BiomeAccess.hashSeed(serverWorld3.getSeed()), + worldProperties.isHardcore(), this.server.getWorldRegistryKeys(), this.registryManager, serverWorld3.getDimension(), serverWorld3.getRegistryKey(), this.getMaxPlayerCount(), this.viewDistance, bl2, !bl, + serverWorld3.isDebugWorld(), serverWorld3.isFlat())); + serverPlayNetworkHandler.sendPacket(new CustomPayloadS2CPacket(CustomPayloadS2CPacket.BRAND, (new PacketByteBuf(Unpooled.buffer())).writeString(this.getServer().getServerModName()))); + serverPlayNetworkHandler.sendPacket(new DifficultyS2CPacket(worldProperties.getDifficulty(), worldProperties.isDifficultyLocked())); + serverPlayNetworkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities)); + serverPlayNetworkHandler.sendPacket(new HeldItemChangeS2CPacket(player.inventory.selectedSlot)); + serverPlayNetworkHandler.sendPacket(new SynchronizeRecipesS2CPacket(this.server.getRecipeManager().values())); + serverPlayNetworkHandler.sendPacket(new SynchronizeTagsS2CPacket(this.server.getTagManager())); + this.sendCommandTree(player); + player.getStatHandler().updateStatSet(); + player.getRecipeBook().sendInitRecipesPacket(player); + this.sendScoreboard(serverWorld3.getScoreboard(), player); + this.server.forcePlayerSampleUpdate(); + TranslatableText mutableText2; + if (player.getGameProfile().getName().equalsIgnoreCase(string)) { + mutableText2 = new TranslatableText("multiplayer.player.joined", new Object[] { player.getDisplayName() }); + } + else { + mutableText2 = new TranslatableText("multiplayer.player.joined.renamed", new Object[] { player.getDisplayName(), string }); + } + + this.broadcastChatMessage(mutableText2.formatted(Formatting.YELLOW), MessageType.SYSTEM, Util.NIL_UUID); + serverPlayNetworkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch); + this.players.add(player); + this.playerMap.put(player.getUuid(), player); + this.sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, new ServerPlayerEntity[] { player })); + + for (int i = 0; i < this.players.size(); ++i) { + player.networkHandler.sendPacket(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, new ServerPlayerEntity[] { (ServerPlayerEntity) this.players.get(i) })); + } + + serverWorld3.onPlayerConnected(player); + this.server.getBossBarManager().onPlayerConnect(player); + this.sendWorldInfo(player, serverWorld3); + if (!this.server.getResourcePackUrl().isEmpty()) { + player.sendResourcePackUrl(this.server.getResourcePackUrl(), this.server.getResourcePackHash()); + } + + Iterator var24 = player.getStatusEffects().iterator(); + + while (var24.hasNext()) { + StatusEffectInstance statusEffectInstance = (StatusEffectInstance) var24.next(); + serverPlayNetworkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getEntityId(), statusEffectInstance)); + } + + if (compoundTag != null && compoundTag.contains("RootVehicle", 10)) { + CompoundTag compoundTag2 = compoundTag.getCompound("RootVehicle"); + Entity entity = EntityType.loadEntityWithPassengers(compoundTag2.getCompound("Entity"), serverWorld3, (vehicle) -> { + return !serverWorld3.tryLoadEntity(vehicle) ? null : vehicle; + }); + if (entity != null) { + UUID uUID2; + if (compoundTag2.containsUuid("Attach")) { + uUID2 = compoundTag2.getUuid("Attach"); + } + else { + uUID2 = null; + } + + Iterator var21; + Entity entity3; + if (entity.getUuid().equals(uUID2)) { + player.startRiding(entity, true); + } + else { + var21 = entity.getPassengersDeep().iterator(); + + while (var21.hasNext()) { + entity3 = (Entity) var21.next(); + if (entity3.getUuid().equals(uUID2)) { + player.startRiding(entity3, true); + break; + } + } + } + + if (!player.hasVehicle()) { + LOGGER.warn("Couldn't reattach entity to player"); + serverWorld3.removeEntity(entity); + var21 = entity.getPassengersDeep().iterator(); + + while (var21.hasNext()) { + entity3 = (Entity) var21.next(); + serverWorld3.removeEntity(entity3); + } + } + } + } + + player.onSpawn(); + info.cancel(); + } + } + + @Shadow + public CompoundTag loadPlayerData(ServerPlayerEntity player) { + return null; + } + + @Shadow + private void setGameMode(ServerPlayerEntity player, @Nullable ServerPlayerEntity oldPlayer, ServerWorld world) {} + + @Shadow + public void sendCommandTree(ServerPlayerEntity player) {} + + @Shadow + public int getMaxPlayerCount() { + return 0; + } + + @Shadow + public MinecraftServer getServer() { + return null; + } + + @Shadow + protected void sendScoreboard(ServerScoreboard scoreboard, ServerPlayerEntity player) {} + + @Shadow + public void broadcastChatMessage(Text message, MessageType type, UUID senderUuid) {} + + @Shadow + public void sendToAll(Packet packet) {} + + @Shadow + public void sendWorldInfo(ServerPlayerEntity player, ServerWorld world) {} +} diff --git a/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java b/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java index 8199b00e..97255cd7 100644 --- a/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java @@ -1,34 +1,57 @@ package ru.betterend.mixin.common; +import java.util.Map; + import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.google.common.collect.Maps; +import com.mojang.authlib.GameProfile; + +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; import ru.betterend.interfaces.TeleportingEntity; @Mixin(ServerPlayerEntity.class) -public abstract class ServerPlayerEntityMixin implements TeleportingEntity { +public abstract class ServerPlayerEntityMixin extends PlayerEntity implements TeleportingEntity { + private static final Map COOLDOWN = Maps.newHashMap(); - private long beCooldown; + public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile profile) { + super(world, pos, yaw, profile); + } + + @Shadow + private RegistryKey spawnPointDimension; @Inject(method = "tick", at = @At("TAIL")) public void be_baseTick(CallbackInfo info) { if (hasCooldown()) { - this.beCooldown--; + ServerPlayerEntity key = (ServerPlayerEntity) (Object) this; + long value = COOLDOWN.getOrDefault(key, 0L) - 1; + COOLDOWN.put(key, value); } } + @Shadow + private void moveToSpawn(ServerWorld world) {} + @Override public long beGetCooldown() { - return this.beCooldown; + ServerPlayerEntity key = (ServerPlayerEntity) (Object) this; + return COOLDOWN.getOrDefault(key, 0L); } @Override public void beSetCooldown(long time) { - this.beCooldown = time; + ServerPlayerEntity key = (ServerPlayerEntity) (Object) this; + COOLDOWN.put(key, time); } @Override diff --git a/src/main/java/ru/betterend/registry/EndBiomes.java b/src/main/java/ru/betterend/registry/EndBiomes.java index 2ec5e5e7..90fe5c39 100644 --- a/src/main/java/ru/betterend/registry/EndBiomes.java +++ b/src/main/java/ru/betterend/registry/EndBiomes.java @@ -176,6 +176,7 @@ public class EndBiomes { } } if (BetterEnd.isDevEnvironment()) { + System.out.println("=================================="); System.out.println("Added void biomes from Fabric API:"); FABRIC_VOID.forEach((id) -> { System.out.println(id); @@ -324,7 +325,6 @@ public class EndBiomes { public static void addSubBiomeIntegration(EndBiome biome, Identifier parent) { if (Configs.BIOME_CONFIG.getBoolean(biome.getID(), "enabled", true)) { EndBiome parentBiome = ID_MAP.get(parent); - System.out.println(parentBiome); if (parentBiome != null && !parentBiome.containsSubBiome(biome)) { parentBiome.addSubBiome(biome); } diff --git a/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java b/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java index 441d8ce2..96e98a76 100644 --- a/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java +++ b/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java @@ -70,7 +70,7 @@ public class BetterEndBiomeSource extends BiomeSource { @Override public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { - boolean hasVoid = !TerrainGenerator.useNewGenerator() || !TerrainGenerator.noRingVoid(); + boolean hasVoid = !GeneratorOptions.useNewGenerator() || !GeneratorOptions.noRingVoid(); long i = (long) biomeX * (long) biomeX; long j = (long) biomeZ * (long) biomeZ; if (hasVoid && i + j <= 65536L) return this.centerBiome; @@ -80,7 +80,7 @@ public class BetterEndBiomeSource extends BiomeSource { mapVoid.clearCache(); } - if (TerrainGenerator.useNewGenerator()) { + if (GeneratorOptions.useNewGenerator()) { if (TerrainGenerator.isLand(biomeX, biomeZ)) { return mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); } diff --git a/src/main/java/ru/betterend/world/generator/GeneratorOptions.java b/src/main/java/ru/betterend/world/generator/GeneratorOptions.java index fa07784e..8e9d4ca2 100644 --- a/src/main/java/ru/betterend/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/betterend/world/generator/GeneratorOptions.java @@ -11,6 +11,9 @@ public class GeneratorOptions { private static boolean swapOverworldToEnd; private static boolean changeChorusPlant; private static boolean removeChorusFromVanillaBiomes; + private static boolean newGenerator; + private static boolean noRingVoid; + private static boolean generateCentralIsland; public static void init() { biomeSizeLand = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeLand", 256); @@ -21,6 +24,9 @@ public class GeneratorOptions { swapOverworldToEnd = Configs.GENERATOR_CONFIG.getBooleanRoot("swapOverworldToEnd", false); changeChorusPlant = Configs.GENERATOR_CONFIG.getBoolean("chorusPlant", "changeChorusPlant", true); removeChorusFromVanillaBiomes = Configs.GENERATOR_CONFIG.getBoolean("chorusPlant", "removeChorusFromVanillaBiomes", true); + newGenerator = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "useNewGenerator", false); + noRingVoid = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "noRingVoid", false); + generateCentralIsland = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "generateCentralIsland", false); } public static int getBiomeSizeLand() { @@ -54,4 +60,16 @@ public class GeneratorOptions { public static boolean removeChorusFromVanillaBiomes() { return removeChorusFromVanillaBiomes; } + + public static boolean noRingVoid() { + return noRingVoid; + } + + public static boolean useNewGenerator() { + return newGenerator; + } + + public static boolean hasCentralIsland() { + return generateCentralIsland; + } } diff --git a/src/main/java/ru/betterend/world/generator/IslandLayer.java b/src/main/java/ru/betterend/world/generator/IslandLayer.java index 533e2d66..5dc633e2 100644 --- a/src/main/java/ru/betterend/world/generator/IslandLayer.java +++ b/src/main/java/ru/betterend/world/generator/IslandLayer.java @@ -29,10 +29,11 @@ public class IslandLayer { private final int minY; private final int maxY; private final long center; + private final boolean hasCentralIsland; private int lastX = Integer.MIN_VALUE; private int lastZ = Integer.MIN_VALUE; - public IslandLayer(int seed, double distance, float scale, int center, int heightVariation) { + public IslandLayer(int seed, double distance, float scale, int center, int heightVariation, boolean hasCentralIsland) { this.distance = distance; this.density = new OpenSimplexNoise(seed); this.scale = scale; @@ -40,6 +41,7 @@ public class IslandLayer { this.minY = center - heightVariation; this.maxY = center + heightVariation; this.center = MHelper.floor(1000 / distance); + this.hasCentralIsland = hasCentralIsland; } private int getSeed(int x, int z) { @@ -59,7 +61,7 @@ public class IslandLayer { int px = pox + ix; for (int poz = -1; poz < 2; poz++) { int pz = poz + iz; - if (TerrainGenerator.noRingVoid() || (long) px + (long) pz > center) { + if (GeneratorOptions.noRingVoid() || (long) px + (long) pz > center) { RANDOM.setSeed(getSeed(px, pz)); double posX = (px + RANDOM.nextFloat()) * distance; double posY = MHelper.randRange(minY, maxY, RANDOM); @@ -70,6 +72,14 @@ public class IslandLayer { } } } + if (hasCentralIsland && GeneratorOptions.hasCentralIsland() && ix == 0 && iz == 0) { + if (positions.size() > 4) { + positions.set(4, new BlockPos(0, 64, 0)); + } + else { + positions.add(new BlockPos(0, 64, 0)); + } + } } } diff --git a/src/main/java/ru/betterend/world/generator/TerrainGenerator.java b/src/main/java/ru/betterend/world/generator/TerrainGenerator.java index 506fa2d9..fca78431 100644 --- a/src/main/java/ru/betterend/world/generator/TerrainGenerator.java +++ b/src/main/java/ru/betterend/world/generator/TerrainGenerator.java @@ -4,7 +4,6 @@ import java.util.Random; import java.util.concurrent.locks.ReentrantLock; import net.minecraft.util.math.MathHelper; -import ru.betterend.config.Configs; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.MHelper; @@ -19,35 +18,20 @@ public class TerrainGenerator { private static IslandLayer smallIslands; private static OpenSimplexNoise noise1; private static OpenSimplexNoise noise2; - private static boolean newGenerator; - private static boolean noRingVoid; - public static void init() { - newGenerator = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "useNewGenerator", false); - noRingVoid = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "noRingVoid", false); + public static boolean canGenerate(int x, int z) { + return GeneratorOptions.noRingVoid() || (long) x + (long) z > CENTER; } public static void initNoise(long seed) { Random random = new Random(seed); - largeIslands = new IslandLayer(random.nextInt(), 300, 200, 70, 10); - mediumIslands = new IslandLayer(random.nextInt(), 150, 100, 70, 20); - smallIslands = new IslandLayer(random.nextInt(), 60, 50, 70, 30); + largeIslands = new IslandLayer(random.nextInt(), 300, 200, 70, 10, false); + mediumIslands = new IslandLayer(random.nextInt(), 150, 100, 70, 20, true); + smallIslands = new IslandLayer(random.nextInt(), 60, 50, 70, 30, false); noise1 = new OpenSimplexNoise(random.nextInt()); noise2 = new OpenSimplexNoise(random.nextInt()); } - public static boolean canGenerate(int x, int z) { - return noRingVoid || (long) x + (long) z > CENTER; - } - - public static boolean noRingVoid() { - return noRingVoid; - } - - public static boolean useNewGenerator() { - return newGenerator; - } - public static void fillTerrainDensity(double[] buffer, int x, int z) { LOCKER.lock(); @@ -128,8 +112,6 @@ public class TerrainGenerator { public static int getHeight(int x, int z) { LOCKER.lock(); - //x >>= 3; - //z >>= 3; double px = (double) x / 8.0; double pz = (double) z / 8.0; diff --git a/src/main/resources/betterend.mixins.common.json b/src/main/resources/betterend.mixins.common.json index 835574ad..2bd6770a 100644 --- a/src/main/resources/betterend.mixins.common.json +++ b/src/main/resources/betterend.mixins.common.json @@ -23,16 +23,17 @@ "MinecraftServerMixin", "TagGroupLoaderMixin", "EndermanEntityMixin", - "DimensionTypeMixin", - "RecipeManagerMixin", "AbstractBlockMixin", + "DimensionTypeMixin", + "PlayerManagerMixin", + "RecipeManagerMixin", "HostileEntityMixin", "LivingEntityMixin", "BoneMealItemMixin", "PlayerEntityMixin", "SlimeEntityMixin", "BrewingAccessor", - "EntityMixin" + "EntityMixin", ], "injectors": { "defaultRequire": 1