diff --git a/gradle.properties b/gradle.properties index 9b1882e..903b46e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,9 +19,9 @@ loom_version = 1.13.0-bta java_version = 8 ########################################################################## # Mod Properties -mod_version = 1.1.4+7.3_04 +mod_version = 1.1.5+7.3_04 mod_group = redart15 -mod_name = Commandly +mod_name = commandly ########################################################################## # Mod Dependencies # Check this on https://github.com/Turnip-Labs/ModMenu/releases/latest/ diff --git a/src/main/java/redart15/commandly/command/CommandAscend.java b/src/main/java/redart15/commandly/command/CommandAscend.java deleted file mode 100644 index d213c5b..0000000 --- a/src/main/java/redart15/commandly/command/CommandAscend.java +++ /dev/null @@ -1,67 +0,0 @@ -package redart15.commandly.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.ArgumentBuilderLiteral; -import com.mojang.brigadier.builder.ArgumentBuilderRequired; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.tree.CommandNode; -import net.minecraft.core.entity.player.Player; -import net.minecraft.core.net.command.CommandManager; -import net.minecraft.core.net.command.CommandSource; -import net.minecraft.core.net.command.arguments.ArgumentTypeEntity; -import net.minecraft.core.world.World; - -import static redart15.commandly.command.CommandlyCommands.ReturnValues.*; - -@SuppressWarnings("ALL") //cause this drives me nuts -public class CommandAscend implements CommandManager.CommandRegistry { - - @Override - public void register(CommandDispatcher dispatcher) { - ArgumentBuilderLiteral command = - (ArgumentBuilderLiteral) ((ArgumentBuilderLiteral) ArgumentBuilderLiteral.literal("ascend") - .requires((t) -> ((CommandSource) t).hasAdmin()) - .executes(CommandAscend::ascend) - .then(ArgumentBuilderRequired.argument("player", ArgumentTypeEntity.username()) - .executes(CommandAscend::ascend))); - CommandNode registeredCommand = dispatcher.register(command); - dispatcher.register((ArgumentBuilderLiteral)((ArgumentBuilderLiteral)ArgumentBuilderLiteral.literal("up") - .requires((t) -> ((CommandSource) t).hasAdmin()) - .redirect((CommandNode)(CommandNode) registeredCommand))); - } - - private static int ascend(CommandContext context) { - CommandSource source = (CommandSource) context.getSource(); - Player player; - try { - player = context.getArgument("player", Player.class); - } catch (IllegalArgumentException e) { - player = source.getSender(); - } - return ascend(source, player); - } - - - private static int ascend(CommandSource source, Player player) { - World world = player.world; - for (double y = player.y; y <= world.getHeightBlocks(); y++) { - if (canPlacePlayer(world, player.x, y, player.z)) { - source.teleportPlayerToPos(player, player.x, (int) Math.ceil(y) + 1, player.z); - source.sendTranslatableMessage("commandly.ascend.up"); - return code(OK); - } - } - source.sendTranslatableMessage("commandly.ascend.fail"); - return code(FAIL); - } - - private static boolean canPlacePlayer(World world, double dx, double dy, double dz) { - int x = (int) Math.floor(dx); - int z = (int) Math.floor(dz); - int y = (int) Math.ceil(dy); - - return world.isAirBlock(x, y, z) - && world.isAirBlock(x, y - 1, z) - && world.isBlockNormalCube(x, y - 2, z); - } -} diff --git a/src/main/java/redart15/commandly/command/CommandDescend.java b/src/main/java/redart15/commandly/command/CommandDescend.java deleted file mode 100644 index 39140a7..0000000 --- a/src/main/java/redart15/commandly/command/CommandDescend.java +++ /dev/null @@ -1,67 +0,0 @@ -package redart15.commandly.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.ArgumentBuilderLiteral; -import com.mojang.brigadier.builder.ArgumentBuilderRequired; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.tree.CommandNode; -import net.minecraft.core.block.material.Material; -import net.minecraft.core.entity.player.Player; -import net.minecraft.core.net.command.CommandManager; -import net.minecraft.core.net.command.CommandSource; -import net.minecraft.core.net.command.arguments.ArgumentTypeEntity; -import net.minecraft.core.world.World; - -import static redart15.commandly.command.CommandlyCommands.ReturnValues.*; - -@SuppressWarnings("ALL") //cause this drives me nuts -public class CommandDescend implements CommandManager.CommandRegistry { - - @Override - public void register(CommandDispatcher dispatcher) { - ArgumentBuilderLiteral command = - (ArgumentBuilderLiteral) ((ArgumentBuilderLiteral) ArgumentBuilderLiteral.literal("descend") - .requires((t) -> ((CommandSource) t).hasAdmin()) - .executes(CommandDescend::descend) - .then(ArgumentBuilderRequired.argument("player", ArgumentTypeEntity.username()) - .executes(CommandDescend::descend))); - CommandNode registeredCommand = dispatcher.register(command); - dispatcher.register((ArgumentBuilderLiteral)((ArgumentBuilderLiteral)ArgumentBuilderLiteral.literal("down") - .requires((t) -> ((CommandSource) t).hasAdmin()) - .redirect((CommandNode)(CommandNode) registeredCommand))); - } - - private static int descend(CommandContext context) { - CommandSource source = (CommandSource) context.getSource(); - Player player; - try { - player = context.getArgument("player", Player.class); - } catch (IllegalArgumentException e) { - player = source.getSender(); - } - return descend(source, player); - } - - private static int descend(CommandSource source, Player player) { - World world = player.world; - for (double y = player.y - player.bbHeight; y > 0; y--) { - if (canPlacePlayer(world, player.x, y, player.z)) { - source.teleportPlayerToPos(player, player.x, (int)Math.ceil(y) + 1, player.z); - source.sendTranslatableMessage("commandly.descend.down"); - return code(OK); - } - } - source.sendTranslatableMessage("commandly.descend.fail"); - return code(FAIL); - } - - private static boolean canPlacePlayer(World world, double dx, double dy, double dz) { - int x = (int) Math.floor(dx); - int z = (int) Math.floor(dz); - int y = (int)Math.ceil(dy); - - return world.isAirBlock(x, y, z) - && world.isAirBlock(x, y - 1, z) - && world.isBlockNormalCube(x, y - 2, z); - } -} diff --git a/src/main/java/redart15/commandly/command/CommandlyCommands.java b/src/main/java/redart15/commandly/command/CommandlyCommands.java index 5bf4186..14ee0dd 100644 --- a/src/main/java/redart15/commandly/command/CommandlyCommands.java +++ b/src/main/java/redart15/commandly/command/CommandlyCommands.java @@ -3,6 +3,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.core.net.command.CommandManager; +import redart15.commandly.command.cend.CommandAscend; +import redart15.commandly.command.cend.CommandDescend; public class CommandlyCommands { diff --git a/src/main/java/redart15/commandly/command/cend/CendUtil.java b/src/main/java/redart15/commandly/command/cend/CendUtil.java new file mode 100644 index 0000000..f259052 --- /dev/null +++ b/src/main/java/redart15/commandly/command/cend/CendUtil.java @@ -0,0 +1,49 @@ +package redart15.commandly.command.cend; + +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.core.block.material.MaterialDecoration; +import net.minecraft.core.entity.player.Player; +import net.minecraft.core.net.command.CommandSource; +import net.minecraft.core.world.World; +import net.minecraft.core.world.chunk.ChunkCoordinates; + +import java.util.function.BiFunction; + +public class CendUtil { + private CendUtil() {} + + public static ChunkCoordinates canPlacePlayer(World world, double dx, double dy, double dz) { + int y = (int) Math.ceil(dy); + int minX = (int) Math.floor(dx); + int maxX = (int) Math.ceil(dx); + int minZ = (int) Math.floor(dz); + int maxZ = (int) Math.ceil(dz); + + for (; minX < maxX; minX++) { + for (; minZ < maxZ; minZ++) { + if (world.isAirBlock(minX, y, minZ) && world.isAirBlock(minX, y - 1, minZ) && canTeleportTo(world, minX, y, minZ)) { + return new ChunkCoordinates(minX, y, minZ); + } + } + } + return null; + } + + private static boolean canTeleportTo(World world, int x, int y, int z) { + if (world.getBlockMaterial(x, y - 2, z).isSolid()) { + return true; + } + return world.getBlockMaterial(x, y - 2, z) instanceof MaterialDecoration && world.getBlockMaterial(x, y - 3, z).isSolid(); + } + + protected static int cend(CommandContext context, BiFunction cend) { + CommandSource source = (CommandSource) context.getSource(); + Player player; + try { + player = context.getArgument("player", Player.class); + } catch (IllegalArgumentException e) { + player = source.getSender(); + } + return cend.apply(source, player); + } +} diff --git a/src/main/java/redart15/commandly/command/cend/CommandAscend.java b/src/main/java/redart15/commandly/command/cend/CommandAscend.java new file mode 100644 index 0000000..0f8a166 --- /dev/null +++ b/src/main/java/redart15/commandly/command/cend/CommandAscend.java @@ -0,0 +1,40 @@ +package redart15.commandly.command.cend; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.ArgumentBuilderLiteral; +import com.mojang.brigadier.builder.ArgumentBuilderRequired; +import net.minecraft.core.entity.player.Player; +import net.minecraft.core.net.command.CommandManager; +import net.minecraft.core.net.command.CommandSource; +import net.minecraft.core.net.command.arguments.ArgumentTypeEntity; +import net.minecraft.core.world.World; +import net.minecraft.core.world.chunk.ChunkCoordinates; + +import static redart15.commandly.command.CommandlyCommands.ReturnValues.*; + +@SuppressWarnings("ALL") //cause this drives me nuts +public class CommandAscend implements CommandManager.CommandRegistry { + + @Override + public void register(CommandDispatcher dispatcher) { + dispatcher.register((ArgumentBuilderLiteral) ((ArgumentBuilderLiteral) ArgumentBuilderLiteral.literal("ascend") + .requires((t) -> ((CommandSource) t).hasAdmin()) + .executes(ctx -> CendUtil.cend(ctx, CommandAscend::ascend)) + .then(ArgumentBuilderRequired.argument("player", ArgumentTypeEntity.username()) + .executes(ctx -> CendUtil.cend(ctx, CommandAscend::ascend))))); + } + + private static int ascend(CommandSource source, Player player) { + World world = player.world; + for (double y = player.y; y <= world.getHeightBlocks(); y++) { + ChunkCoordinates telePos = CendUtil.canPlacePlayer(world, player.x, y, player.z); + if (telePos != null) { + source.teleportPlayerToPos(player, telePos.x, telePos.y + 1.0f, telePos.z); + source.sendTranslatableMessage("commandly.ascend.up"); + return code(OK); + } + } + source.sendTranslatableMessage("commandly.ascend.fail"); + return code(FAIL); + } +} diff --git a/src/main/java/redart15/commandly/command/cend/CommandDescend.java b/src/main/java/redart15/commandly/command/cend/CommandDescend.java new file mode 100644 index 0000000..9ce29d7 --- /dev/null +++ b/src/main/java/redart15/commandly/command/cend/CommandDescend.java @@ -0,0 +1,41 @@ +package redart15.commandly.command.cend; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.ArgumentBuilderLiteral; +import com.mojang.brigadier.builder.ArgumentBuilderRequired; +import net.minecraft.core.entity.player.Player; +import net.minecraft.core.net.command.CommandManager; +import net.minecraft.core.net.command.CommandSource; +import net.minecraft.core.net.command.arguments.ArgumentTypeEntity; +import net.minecraft.core.world.World; +import net.minecraft.core.world.chunk.ChunkCoordinates; + +import static redart15.commandly.command.CommandlyCommands.ReturnValues.*; + +@SuppressWarnings("ALL") //cause this drives me nuts +public class CommandDescend implements CommandManager.CommandRegistry { + + @Override + public void register(CommandDispatcher dispatcher) { + dispatcher.register((ArgumentBuilderLiteral) ((ArgumentBuilderLiteral) ArgumentBuilderLiteral.literal("descend") + .requires((t) -> ((CommandSource) t).hasAdmin()) + .executes(ctx -> CendUtil.cend(ctx, CommandDescend::descend)) + .then(ArgumentBuilderRequired.argument("player", ArgumentTypeEntity.username()) + .executes(ctx -> CendUtil.cend(ctx, CommandDescend::descend))))); + } + + private static int descend(CommandSource source, Player player) { + World world = player.world; + for (double y = player.y - player.bbHeight; y > 0; y--) { + ChunkCoordinates telePos = CendUtil.canPlacePlayer(world, player.x, y, player.z); + if (telePos != null) { + source.teleportPlayerToPos(player, telePos.x, telePos.y + 1.0f, telePos.z); + source.sendTranslatableMessage("commandly.descend.down"); + return code(OK); + } + } + source.sendTranslatableMessage("commandly.descend.fail"); + return code(FAIL); + } + +}