diff --git a/src/main/java/vazkii/botania/common/Botania.java b/src/main/java/vazkii/botania/common/Botania.java index 68fafa975..8b1cceb17 100644 --- a/src/main/java/vazkii/botania/common/Botania.java +++ b/src/main/java/vazkii/botania/common/Botania.java @@ -8,10 +8,8 @@ */ package vazkii.botania.common; -import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.Block; import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.attributes.Attribute; @@ -81,7 +79,7 @@ import vazkii.botania.common.brew.potion.PotionEmptiness; import vazkii.botania.common.brew.potion.PotionSoulCross; import vazkii.botania.common.capability.NoopCapStorage; import vazkii.botania.common.capability.NoopExoflameHeatable; -import vazkii.botania.common.core.command.CommandSkyblockSpread; +import vazkii.botania.common.core.command.SkyblockCommand; import vazkii.botania.common.core.handler.*; import vazkii.botania.common.core.helper.ColorHelper; import vazkii.botania.common.core.loot.DisposeModifier; @@ -206,7 +204,7 @@ public class Botania { CorporeaHelper.instance().registerRequestMatcher(prefix("item_stack"), CorporeaItemStackMatcher.class, CorporeaItemStackMatcher::createFromNBT); if (Botania.gardenOfGlassLoaded) { - MinecraftForge.EVENT_BUS.addListener(SkyblockWorldEvents::onPlayerUpdate); + MinecraftForge.EVENT_BUS.addListener(SkyblockWorldEvents::onPlayerJoin); MinecraftForge.EVENT_BUS.addListener(SkyblockWorldEvents::onPlayerInteract); } @@ -297,7 +295,7 @@ public class Botania { private void serverStarting(FMLServerStartingEvent event) { if (Botania.gardenOfGlassLoaded) { - CommandSkyblockSpread.register(event.getCommandDispatcher()); + SkyblockCommand.register(event.getCommandDispatcher()); } } diff --git a/src/main/java/vazkii/botania/common/core/command/CommandSkyblockSpread.java b/src/main/java/vazkii/botania/common/core/command/CommandSkyblockSpread.java deleted file mode 100644 index 2da4b27bd..000000000 --- a/src/main/java/vazkii/botania/common/core/command/CommandSkyblockSpread.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This class is distributed as part of the Botania Mod. - * Get the Source Code in github: - * https://github.com/Vazkii/Botania - * - * Botania is Open Source and distributed under the - * Botania License: http://botaniamod.net/license.php - */ -package vazkii.botania.common.core.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraft.command.arguments.EntityArgument; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; - -import vazkii.botania.common.core.helper.MathHelper; -import vazkii.botania.common.world.SkyblockWorldEvents; - -public class CommandSkyblockSpread { - private static final int DEFAULT_RANGE = 200000; - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register( - Commands.literal("botania-skyblock-spread") - .requires(s -> s.hasPermissionLevel(2)) - .then(Commands.argument("player", EntityArgument.player()) - .then(Commands.argument("range", IntegerArgumentType.integer(250, 1000000)) - .executes(ctx -> run(ctx, IntegerArgumentType.getInteger(ctx, "range")))) - .executes(ctx -> run(ctx, DEFAULT_RANGE))) - ); - } - - private static int run(CommandContext ctx, int range) throws CommandSyntaxException { - PlayerEntity player = EntityArgument.getPlayer(ctx, "player"); - int minDist = 100; - BlockPos spawn = ((ServerWorld) player.world).func_241135_u_(); - int x, z; - - do { - x = player.world.rand.nextInt(range) - range / 2 + spawn.getX(); - z = player.world.rand.nextInt(range) - range / 2 + spawn.getZ(); - } while (MathHelper.pointDistancePlane(x, z, spawn.getX(), spawn.getZ()) < minDist); - - SkyblockWorldEvents.spawnPlayer(player, new BlockPos(x, spawn.getY(), z), true); - return 1; - } -} diff --git a/src/main/java/vazkii/botania/common/core/command/SkyblockCommand.java b/src/main/java/vazkii/botania/common/core/command/SkyblockCommand.java new file mode 100644 index 000000000..dad36d216 --- /dev/null +++ b/src/main/java/vazkii/botania/common/core/command/SkyblockCommand.java @@ -0,0 +1,173 @@ +/* + * This class is distributed as part of the Botania Mod. + * Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + */ +package vazkii.botania.common.core.command; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import com.mojang.brigadier.tree.LiteralCommandNode; + +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.command.ISuggestionProvider; +import net.minecraft.command.arguments.EntityArgument; +import net.minecraft.command.arguments.UUIDArgument; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.Util; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.server.ServerWorld; + +import vazkii.botania.common.world.IslandPos; +import vazkii.botania.common.world.SkyblockChunkGenerator; +import vazkii.botania.common.world.SkyblockSavedData; +import vazkii.botania.common.world.SkyblockWorldEvents; + +import java.util.UUID; + +public class SkyblockCommand { + private static final SimpleCommandExceptionType NOT_SKYBLOCK_WORLD = new SimpleCommandExceptionType( + new TranslationTextComponent("botaniamisc.command.skyblock.world")); + private static final SimpleCommandExceptionType NO_ISLAND = new SimpleCommandExceptionType( + new TranslationTextComponent("botaniamisc.command.skyblock.noisland")); + + public static void register(CommandDispatcher dispatcher) { + // This isn't what we consider the "primary" name. It's just here to be a reminder for old /botania-skyblock-spread users. + // However some Mojang code seems to assume that aliases are made alphabetically... + LiteralArgumentBuilder commandBuilder = Commands.literal("botania-skyblock") + .requires(s -> s.hasPermissionLevel(2)) + .then(Commands.literal("help") + .executes(SkyblockCommand::printHelp)) + .then(Commands.literal("island") + .then(Commands.argument("player", EntityArgument.player()) + .executes(SkyblockCommand::createIsland))) + .then(Commands.literal("spawn") + .executes(SkyblockCommand::teleportToSpawn)) + + .then(Commands.literal("visit") + .then(Commands.argument("player", EntityArgument.player()) + .executes(ctx -> teleportToIsland(ctx, EntityArgument.getPlayer(ctx, "player"))) + ) + .then(Commands.argument("playerUuid", UUIDArgument.func_239194_a_()) + .suggests((ctx, builder) -> ISuggestionProvider.suggest( + SkyblockSavedData.get(ctx.getSource().getWorld()).skyblocks + .values().stream().map(UUID::toString), + builder)) + .executes(ctx -> teleportToIsland(ctx, UUIDArgument.func_239195_a_(ctx, "playerUuid"))) + ) + ) + + .then(Commands.literal("regen-island") + .then(Commands.argument("player", EntityArgument.player()) + .executes(ctx -> rebuildIsland(ctx, EntityArgument.getPlayer(ctx, "player"))) + ) + .then(Commands.argument("playerUuid", UUIDArgument.func_239194_a_()) + .suggests((ctx, builder) -> ISuggestionProvider.suggest( + SkyblockSavedData.get(ctx.getSource().getWorld()).skyblocks + .values().stream().map(UUID::toString), + builder)) + .executes(ctx -> rebuildIsland(ctx, UUIDArgument.func_239195_a_(ctx, "playerUuid"))) + ) + ); + LiteralCommandNode command = dispatcher.register(commandBuilder); + dispatcher.register(Commands.literal("gardenofglass").redirect(command)); + dispatcher.register(Commands.literal("gog").redirect(command)); + } + + private static int printHelp(CommandContext ctx) { + for (int i = 0; i < 5; i++) { + ctx.getSource().sendFeedback(new TranslationTextComponent("botaniamisc.command.skyblock.help." + i), false); + } + return Command.SINGLE_SUCCESS; + } + + private static int doTeleportToIsland(CommandContext ctx, UUID owner, ITextComponent feedback) throws CommandSyntaxException { + ServerWorld world = getSkyblockWorld(ctx); + IslandPos pos = getIslandForUUID(owner, SkyblockSavedData.get(world)); + + ServerPlayerEntity player = ctx.getSource().asPlayer(); + BlockPos blockPos = pos.getCenter(); + + player.teleport(world, blockPos.getX() + 0.5, blockPos.getY(), + blockPos.getZ() + 0.5, player.rotationYaw, player.rotationPitch); + ctx.getSource().sendFeedback(feedback, true); + return Command.SINGLE_SUCCESS; + } + + private static int createIsland(CommandContext ctx) throws CommandSyntaxException { + PlayerEntity player = EntityArgument.getPlayer(ctx, "player"); + SkyblockSavedData data = SkyblockSavedData.get(getSkyblockWorld(ctx)); + UUID uuid = player.getUniqueID(); + + if (data.skyblocks.containsValue(uuid)) { + doTeleportToIsland(ctx, uuid, new TranslationTextComponent("botaniamisc.command.skyblock.island.teleported", + ctx.getSource().getDisplayName())); + return Command.SINGLE_SUCCESS; + } + + SkyblockWorldEvents.spawnPlayer(player, data.create(uuid)); + ctx.getSource().sendFeedback(new TranslationTextComponent("botaniamisc.command.skyblock.island.success", player.getDisplayName()), true); + return Command.SINGLE_SUCCESS; + } + + private static int doRebuildIsland(CommandContext ctx, UUID player, ITextComponent feedback) throws CommandSyntaxException { + ServerWorld world = getSkyblockWorld(ctx); + IslandPos pos = getIslandForUUID(player, SkyblockSavedData.get(world)); + + SkyblockWorldEvents.createSkyblock(world, pos.getCenter()); + ctx.getSource().sendFeedback(feedback, true); + return Command.SINGLE_SUCCESS; + } + + // Helper methods + private static IslandPos getIslandForUUID(UUID player, SkyblockSavedData data) throws CommandSyntaxException { + IslandPos pos = data.skyblocks.inverse().get(player); + if (pos == null) { + throw NO_ISLAND.create(); + } + return pos; + } + + private static ServerWorld getSkyblockWorld(CommandContext ctx) throws CommandSyntaxException { + ServerWorld world = ctx.getSource().getWorld(); + if (!SkyblockChunkGenerator.isWorldSkyblock(world)) { + throw NOT_SKYBLOCK_WORLD.create(); + } + return world; + } + + // Translation feedback helpers + private static int teleportToIsland(CommandContext ctx, PlayerEntity owner) throws CommandSyntaxException { + return doTeleportToIsland(ctx, owner.getUniqueID(), new TranslationTextComponent("botaniamisc.command.skyblock.teleport.success", + ctx.getSource().getDisplayName(), owner.getName())); + } + + private static int teleportToIsland(CommandContext ctx, UUID owner) throws CommandSyntaxException { + return doTeleportToIsland(ctx, owner, new TranslationTextComponent("botaniamisc.command.skyblock.teleport.success", + ctx.getSource().getDisplayName(), owner)); + } + + private static int teleportToSpawn(CommandContext ctx) throws CommandSyntaxException { + return doTeleportToIsland(ctx, Util.DUMMY_UUID, new TranslationTextComponent("botaniamisc.command.skyblock.spawn.success", + ctx.getSource().getDisplayName())); + } + + private static int rebuildIsland(CommandContext ctx, ServerPlayerEntity owner) throws CommandSyntaxException { + return doRebuildIsland(ctx, owner.getUniqueID(), new TranslationTextComponent("botaniamisc.command.skyblock.regenisland.success", owner.getDisplayName())); + } + + private static int rebuildIsland(CommandContext ctx, UUID owner) throws CommandSyntaxException { + return doRebuildIsland(ctx, owner, new TranslationTextComponent("botaniamisc.command.skyblock.regenisland.success", owner)); + } +} diff --git a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java index 8b9e12089..0add4a628 100644 --- a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java @@ -138,6 +138,7 @@ public final class ConfigHandler { public final ForgeConfigSpec.IntValue mushroomQuantity; public final ForgeConfigSpec.BooleanValue gogSpawnWithLexicon; + public final ForgeConfigSpec.IntValue gogIslandScaleMultiplier; public Common(ForgeConfigSpec.Builder builder) { builder.push("blockBreakingParticles"); @@ -212,6 +213,12 @@ public final class ConfigHandler { gogSpawnWithLexicon = builder .comment("Set this to false to disable spawning with a Lexica Botania in Garden of Glass worlds, if you are modifying the modpack's progression to not start with Botania.") .define("gardenOfGlass.spawnWithLexicon", true); + gogIslandScaleMultiplier = builder + .comment("The multiplier for island distances for multiplayer Garden of Glass worlds.\n" + + "Islands are placed on a grid with 256 blocks between points, with the spawn island always being placed on 256, 256.\n" + + "By default, the scale is 8, putting each island on points separated by 2048 blocks.\n" + + "Values below 4 (1024 block spacing) are not recommended due to Nether portal collisions.") + .defineInRange("gardenOfGlass.islandScaleMultiplier", 8, 1, 512); } } diff --git a/src/main/java/vazkii/botania/common/world/IslandPos.java b/src/main/java/vazkii/botania/common/world/IslandPos.java new file mode 100644 index 000000000..5a8d42b3c --- /dev/null +++ b/src/main/java/vazkii/botania/common/world/IslandPos.java @@ -0,0 +1,55 @@ +/* + * This class is distributed as part of the Botania Mod. + * Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + */ +package vazkii.botania.common.world; + +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.math.BlockPos; + +public final class IslandPos { + private final int x; + private final int z; + + public IslandPos(int x, int z) { + this.x = x; + this.z = z; + } + + public BlockPos getCenter() { + return new BlockPos(x << 8, 64, z << 8); + } + + public static IslandPos fromTag(CompoundNBT tag) { + return new IslandPos(tag.getInt("IslandX"), tag.getInt("IslandZ")); + } + + public CompoundNBT toTag() { + CompoundNBT tag = new CompoundNBT(); + tag.putInt("IslandX", x); + tag.putInt("IslandZ", z); + return tag; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof IslandPos)) { + return false; + } + IslandPos islandPos = (IslandPos) o; + return this.x == islandPos.x && this.z == islandPos.z; + } + + @Override + public int hashCode() { + int result = x; + result = 31 * result + z; + return result; + } +} diff --git a/src/main/java/vazkii/botania/common/world/SkyblockSavedData.java b/src/main/java/vazkii/botania/common/world/SkyblockSavedData.java new file mode 100644 index 000000000..d790d4be9 --- /dev/null +++ b/src/main/java/vazkii/botania/common/world/SkyblockSavedData.java @@ -0,0 +1,129 @@ +/* + * This class is distributed as part of the Botania Mod. + * Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + */ +package vazkii.botania.common.world; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.Util; +import net.minecraft.world.server.ServerWorld; +import net.minecraft.world.storage.WorldSavedData; +import net.minecraftforge.common.util.Constants; + +import vazkii.botania.common.core.handler.ConfigHandler; + +import javax.annotation.Nonnull; + +import java.util.Map; +import java.util.UUID; + +public class SkyblockSavedData extends WorldSavedData { + private static final String NAME = "gog_skyblock_islands"; + + /** The offset is chosen to put islands under default settings in the center of a chunk region. */ + private static final int OFFSET = 1; + + public BiMap skyblocks = HashBiMap.create(); + private Spiral spiral = new Spiral(); + + public SkyblockSavedData() { + super(NAME); + } + + public static SkyblockSavedData get(ServerWorld world) { + return world.getSavedData().getOrCreate(SkyblockSavedData::new, NAME); + } + + public IslandPos getSpawn() { + if (skyblocks.containsValue(Util.DUMMY_UUID)) { + return skyblocks.inverse().get(Util.DUMMY_UUID); + } + IslandPos pos = new IslandPos(OFFSET, OFFSET); + skyblocks.put(pos, Util.DUMMY_UUID); + markDirty(); + return pos; + } + + public IslandPos create(UUID playerId) { + int scale = ConfigHandler.COMMON.gogIslandScaleMultiplier.get(); + IslandPos islandPos; + do { + int[] pos = spiral.next(); + islandPos = new IslandPos(pos[0] * scale + OFFSET, pos[1] * scale + OFFSET); + } while (skyblocks.containsKey(islandPos)); + + skyblocks.put(islandPos, playerId); + markDirty(); + return islandPos; + } + + @Override + public void read(CompoundNBT nbt) { + HashBiMap map = HashBiMap.create(); + for (INBT inbt : nbt.getList("Islands", Constants.NBT.TAG_COMPOUND)) { + CompoundNBT tag = (CompoundNBT) inbt; + map.put(IslandPos.fromTag(tag), tag.getUniqueId("Player")); + } + this.skyblocks = map; + this.spiral = Spiral.fromArray(nbt.getIntArray("SpiralState")); + } + + @Nonnull + @Override + public CompoundNBT write(@Nonnull CompoundNBT nbt) { + ListNBT list = new ListNBT(); + for (Map.Entry entry : skyblocks.entrySet()) { + CompoundNBT entryTag = entry.getKey().toTag(); + entryTag.putUniqueId("Player", entry.getValue()); + list.add(entryTag); + } + nbt.putIntArray("SpiralState", spiral.toIntArray()); + nbt.put("Islands", list); + return nbt; + } + + // Adapted from https://stackoverflow.com/questions/398299/looping-in-a-spiral + private static class Spiral { + private int x = 0; + private int y = 0; + private int dx = 0; + private int dy = -1; + + Spiral() {} + + Spiral(int x, int y, int dx, int dy) { + this.x = x; + this.y = y; + this.dx = dx; + this.dy = dy; + } + + int[] next() { + if (x == y || x < 0 && x == -y || x > 0 && x == 1 - y) { + int t = dx; + dx = -dy; + dy = t; + } + x += dx; + y += dy; + return new int[] { x, y }; + } + + int[] toIntArray() { + return new int[] { x, y, dx, dy }; + } + + static Spiral fromArray(int[] ints) { + return new Spiral(ints[0], ints[1], ints[2], ints[3]); + } + } +} diff --git a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java index 2eb609623..ee6f5cfc5 100644 --- a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java +++ b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java @@ -17,18 +17,18 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.CompoundNBT; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ITag; import net.minecraft.util.ActionResultType; +import net.minecraft.util.Util; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.fml.server.ServerLifecycleHooks; import vazkii.botania.common.Botania; import vazkii.botania.common.block.ModBlocks; @@ -36,43 +36,22 @@ import vazkii.botania.common.block.tile.TileManaFlame; import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.tool.ToolCommons; -import vazkii.botania.common.lib.ModTags; public final class SkyblockWorldEvents { private SkyblockWorldEvents() {} private static final ITag.INamedTag PEBBLE_SOURCES = BlockTags.makeWrapperTag("gardenofglass:pebble_sources"); - private static final String TAG_MADE_ISLAND = "Botania-MadeIsland"; - private static final String TAG_HAS_OWN_ISLAND = "Botania-HasOwnIsland"; - private static final String TAG_ISLAND_X = "Botania-IslandX"; - private static final String TAG_ISLAND_Y = "Botania-IslandY"; - private static final String TAG_ISLAND_Z = "Botania-IslandZ"; - public static void onPlayerUpdate(LivingUpdateEvent event) { - if (event.getEntityLiving() instanceof PlayerEntity && !event.getEntityLiving().world.isRemote) { - PlayerEntity player = (PlayerEntity) event.getEntityLiving(); - CompoundNBT data = player.getPersistentData(); - if (!data.contains(PlayerEntity.PERSISTED_NBT_TAG)) { - data.put(PlayerEntity.PERSISTED_NBT_TAG, new CompoundNBT()); - } - - CompoundNBT persist = data.getCompound(PlayerEntity.PERSISTED_NBT_TAG); - if (player.ticksExisted > 3 && !persist.getBoolean(TAG_MADE_ISLAND)) { - World overworld = ServerLifecycleHooks.getCurrentServer().getWorld(World.field_234918_g_); - ServerWorld world = (ServerWorld) player.world; - if (SkyblockChunkGenerator.isWorldSkyblock(world)) { - BlockPos coords = world.func_241135_u_(); - if (coords.getY() <= 0) { - coords = new BlockPos(coords.getX(), 64, coords.getZ()); - world.func_241124_a__(coords); - } - if (world.getBlockState(coords.down(4)).getBlock() != Blocks.BEDROCK && world == overworld) { - spawnPlayer(player, coords, false); - } - } - - persist.putBoolean(TAG_MADE_ISLAND, true); + public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) { + World world = event.getPlayer().world; + if (SkyblockChunkGenerator.isWorldSkyblock(world)) { + SkyblockSavedData data = SkyblockSavedData.get((ServerWorld) world); + if (!data.skyblocks.containsValue(Util.DUMMY_UUID)) { + IslandPos islandPos = data.getSpawn(); + ((ServerWorld) world).func_241124_a__(islandPos.getCenter()); + spawnPlayer(event.getPlayer(), islandPos); + Botania.LOGGER.info("Created the spawn GoG island"); } } } @@ -122,41 +101,16 @@ public final class SkyblockWorldEvents { } } - public static void spawnPlayer(PlayerEntity player, BlockPos pos, boolean fabricated) { - CompoundNBT data = player.getPersistentData(); - if (!data.contains(PlayerEntity.PERSISTED_NBT_TAG)) { - data.put(PlayerEntity.PERSISTED_NBT_TAG, new CompoundNBT()); - } - CompoundNBT persist = data.getCompound(PlayerEntity.PERSISTED_NBT_TAG); + public static void spawnPlayer(PlayerEntity player, IslandPos islandPos) { + BlockPos pos = islandPos.getCenter(); + createSkyblock(player.world, pos); - final boolean test = false; - - if (test || !persist.getBoolean(TAG_HAS_OWN_ISLAND)) { - createSkyblock(player.world, pos); - - if (player instanceof ServerPlayerEntity) { - ServerPlayerEntity pmp = (ServerPlayerEntity) player; - pmp.setPositionAndUpdate(pos.getX() + 0.5, pos.getY() + 1.6, pos.getZ() + 0.5); - pmp.func_241153_a_(pmp.world.func_234923_W_(), pos, true, false); - if (ConfigHandler.COMMON.gogSpawnWithLexicon.get()) { - player.inventory.addItemStackToInventory(new ItemStack(ModItems.lexicon)); - } - } - - if (fabricated) { - persist.putBoolean(TAG_HAS_OWN_ISLAND, true); - persist.putDouble(TAG_ISLAND_X, player.getPosX()); - persist.putDouble(TAG_ISLAND_Y, player.getPosY()); - persist.putDouble(TAG_ISLAND_Z, player.getPosZ()); - } - } else { - double posX = persist.getDouble(TAG_ISLAND_X); - double posY = persist.getDouble(TAG_ISLAND_Y); - double posZ = persist.getDouble(TAG_ISLAND_Z); - - if (player instanceof ServerPlayerEntity) { - ServerPlayerEntity pmp = (ServerPlayerEntity) player; - pmp.setPositionAndUpdate(posX, posY, posZ); + if (player instanceof ServerPlayerEntity) { + ServerPlayerEntity pmp = (ServerPlayerEntity) player; + pmp.setPositionAndUpdate(pos.getX() + 0.5, pos.getY() + 1.6, pos.getZ() + 0.5); + pmp.func_241153_a_(pmp.world.func_234923_W_(), pos, true, false); + if (ConfigHandler.COMMON.gogSpawnWithLexicon.get()) { + player.inventory.addItemStackToInventory(new ItemStack(ModItems.lexicon)); } } } diff --git a/src/main/resources/assets/botania/lang/en_us.json b/src/main/resources/assets/botania/lang/en_us.json index 9ff6ebbd8..7e78c56b1 100644 --- a/src/main/resources/assets/botania/lang/en_us.json +++ b/src/main/resources/assets/botania/lang/en_us.json @@ -87,8 +87,18 @@ "botaniamisc.lockedStopped": "Locked, Stopped", "botaniamisc.challenges": "Challenges", "botaniamisc.challengeInfo": "Learn about the challenges", - "botaniamisc.skyblockRangeTooLow": "Invalid range, must be at least 250.", - "botaniamisc.skyblockRangeTooHigh": "Invalid range, can't be higher than 1000000 (1 million).", + "botaniamisc.command.skyblock.island.success": "Successfully created the island for player %s", + "botaniamisc.command.skyblock.island.teleported": "Teleported player %s as an island already exists", + "botaniamisc.command.skyblock.regenisland.success": "Successfully regenerated the island for player %s", + "botaniamisc.command.skyblock.teleport.success": "Teleported player %s to the island %s", + "botaniamisc.command.skyblock.spawn.success": "Teleported player %s to the spawn island", + "botaniamisc.command.skyblock.world": "The command cannot be used in a non-skyblock dimension", + "botaniamisc.command.skyblock.noisland": "An island for this player does not exist", + "botaniamisc.command.skyblock.help.0": "/gardenofglass help - prints this message", + "botaniamisc.command.skyblock.help.1": "/gardenofglass island - creates a new island or teleports the player to their existing one if one exists", + "botaniamisc.command.skyblock.help.2": "/gardenofglass spawn - teleports the user to the spawn island", + "botaniamisc.command.skyblock.help.3": "/gardenofglass visit - teleports the user to the specified player's island", + "botaniamisc.command.skyblock.help.4": "/gardenofglass regen-island - rebuilds the specified player's island", "botaniamisc.pay2win": "Upgrade your Mana Pool to infuse this item", "botaniamisc.justDoIt": "DO IT", "botaniamisc.changes0": "\u00a7aBotania\u00a77 has changed since you last used it in this instance!",