Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
67 changes: 0 additions & 67 deletions src/main/java/redart15/commandly/command/CommandAscend.java

This file was deleted.

67 changes: 0 additions & 67 deletions src/main/java/redart15/commandly/command/CommandDescend.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/redart15/commandly/command/cend/CendUtil.java
Original file line number Diff line number Diff line change
@@ -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<Object> context, BiFunction<CommandSource, Player, Integer> 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);
}
}
40 changes: 40 additions & 0 deletions src/main/java/redart15/commandly/command/cend/CommandAscend.java
Original file line number Diff line number Diff line change
@@ -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<CommandSource> 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);
}
}
41 changes: 41 additions & 0 deletions src/main/java/redart15/commandly/command/cend/CommandDescend.java
Original file line number Diff line number Diff line change
@@ -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<CommandSource> 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);
}

}