Compare commits

..

2 commits

Author SHA1 Message Date
4e5ef92a67 username command 2024-06-18 16:36:34 -04:00
e63be0909b lazy bcraw & bcv implementation 2024-06-18 14:45:54 -04:00
31 changed files with 363 additions and 217 deletions

View file

@ -1,15 +1,11 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'maven-publish'
}
version = project.mod_version
group = project.maven_group
base {
archivesName = project.archives_base_name
}
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
@ -26,7 +22,15 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
// modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}
base {
archivesName = project.archives_base_name
}
processResources {
@ -38,7 +42,8 @@ processResources {
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 8
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}
java {
@ -47,21 +52,20 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
rename { "${it}_${base.archivesName.get()}"}
}
}
// configure the maven publication
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
mavenJava(MavenPublication) {
from components.java
}
}

View file

@ -3,12 +3,15 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=20w14infinite
yarn_mappings=20w14infinite+build.4
loader_version=0.15.11
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.17
# Mod Properties
mod_version=rolling
maven_group=land.chipmunk.kaboomfabric
archives_base_name=extras
mod_version = rolling
maven_group = land.chipmunk.kaboomfabric
archives_base_name = extras
# Dependencies
fabric_version=0.75.3+1.19.4

Binary file not shown.

View file

@ -1,7 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

29
gradlew vendored
View file

@ -83,8 +83,10 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@ -131,13 +133,10 @@ location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
@ -145,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -153,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -198,15 +197,11 @@ if "$cygwin" || "$msys" ; then
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \

20
gradlew.bat vendored
View file

@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail

View file

@ -1,10 +1,10 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}

View file

@ -1,13 +1,14 @@
package land.chipmunk.kaboomfabric.extras;
import net.fabricmc.api.ModInitializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.minecraft.util.Formatting;
import com.mojang.brigadier.CommandDispatcher;
import land.chipmunk.kaboomfabric.extras.commands.*;
public class Extras implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger("infinite-fixes");
public static final Logger LOGGER = LoggerFactory.getLogger("extras");
private static final char[] escapeCodes = "0123456789abcdefklmnorx".toCharArray();
@Override
@ -16,7 +17,7 @@ public class Extras implements ModInitializer {
public static void registerCommands (CommandDispatcher dispatcher) {
// CommandBroadcastMM.register(dispatcher);
// CommandBroadcastVanilla.register(dispatcher);
CommandBroadcastVanilla.register(dispatcher);
CommandClearChat.register(dispatcher);
CommandConsole.register(dispatcher);
CommandDestroyEntities.register(dispatcher);
@ -31,8 +32,8 @@ public class Extras implements ModInitializer {
// CommandSkin.register(dispatcher);
CommandSpawn.register(dispatcher);
CommandSpidey.register(dispatcher);
// CommandTellraw.register(dispatcher);
// CommandUsername.register(dispatcher);
CommandTellraw.register(dispatcher);
CommandUsername.register(dispatcher);
}
public static String parseEscapeSequences (String string) {
@ -40,7 +41,7 @@ public class Extras implements ModInitializer {
for (int i = 0; i < string.length(); i++) {
char character = string.charAt(i);
if (character == '&' && string.length() > (i + 1) && validateEscapeCode(string.charAt(i + 1))) sb.append((char) 0xa7);
if (character == '&' && string.length() > (i + 1) && validateEscapeCode(string.charAt(i + 1))) sb.append(Formatting.FORMATTING_CODE_PREFIX);
else sb.append(character);
}

View file

@ -0,0 +1,41 @@
package land.chipmunk.kaboomfabric.extras.commands;
import land.chipmunk.kaboomfabric.extras.Extras;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
public interface CommandBroadcastVanilla {
static void register (CommandDispatcher dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("broadcastvanilla")
.requires(CommandBroadcastVanilla::requirement)
.then(
argument("message", greedyString())
.executes(CommandBroadcastVanilla::tellrawCommand)
)
);
dispatcher.register(literal("bcv").requires(CommandBroadcastVanilla::requirement).executes(CommandTellraw::tellrawCommand).redirect(node));
}
static int tellrawCommand (CommandContext<ServerCommandSource> context) {
String string = getString(context, "message");
Text text = Text.literal(Extras.parseEscapeSequences(string));
context.getSource().sendFeedback(text, true);
return Command.SINGLE_SUCCESS;
}
static boolean requirement (ServerCommandSource source) {
return source.hasPermissionLevel(2);
}
}

View file

@ -7,7 +7,7 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import net.minecraft.server.network.ServerPlayerEntity;
@ -23,11 +23,11 @@ public interface CommandClearChat {
}
static int clearChatCommand (CommandContext<ServerCommandSource> context) {
final Text text = new LiteralText("");
for (int i = 0; i < 100; i++) text.append(new LiteralText("\n"));
text.append(new LiteralText("The chat has been cleared").formatted(Formatting.DARK_GREEN));
final MutableText text = Text.literal("");
for (int i = 0; i < 100; i++) text.append(Text.literal("\n"));
text.append(Text.literal("The chat has been cleared").formatted(Formatting.DARK_GREEN));
for (ServerPlayerEntity player : context.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) {
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
player.sendMessage(text);
}

View file

@ -27,13 +27,13 @@ public interface CommandConsole {
static int consoleCommand (CommandContext<ServerCommandSource> context) {
// ? Should I optimize this to manually create a ParseResults object, or just not wrap the say command in the first place?
final ServerCommandSource source = context.getSource();
final MinecraftServer server = source.getMinecraftServer();
final MinecraftServer server = source.getServer();
final ServerCommandSource console = server.getCommandSource();
final String command = "say " + Extras.parseEscapeSequences(getString(context, "message"));
final CommandManager commandManager = server.getCommandManager();
commandManager.execute(console, command);
commandManager.execute(commandManager.getDispatcher().parse(command, source), command);
return Command.SINGLE_SUCCESS;
}

View file

@ -11,9 +11,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.LiteralText;
import land.chipmunk.kaboomfabric.extras.mixin.ServerWorldAccessor;
import land.chipmunk.kaboomfabric.extras.mixin.EntityAccessor;
import net.minecraft.text.Text;
// Currently broken
public interface CommandDestroyEntities {
@ -29,15 +27,15 @@ public interface CommandDestroyEntities {
static int destroyEntitiesCommand (CommandContext<ServerCommandSource> context) {
final ServerCommandSource source = context.getSource();
final MinecraftServer server = source.getMinecraftServer();
final MinecraftServer server = source.getServer();
int entityCount = 0;
int worldCount = 0;
for (ServerWorld world : server.getWorlds()) {
for (Entity entity : ((ServerWorldAccessor)(Object)world).entitiesById().values()) {
for (Entity entity : world.iterateEntities()) {
if (entity instanceof PlayerEntity) continue;
try {
((EntityAccessor)(Object)entity).destroy();
entity.discard();
entityCount++;
} catch (Exception ignored) {
}
@ -46,11 +44,11 @@ public interface CommandDestroyEntities {
}
source.sendFeedback(
new LiteralText("Successfully destroyed ")
.append(new LiteralText(String.valueOf(entityCount)))
.append(new LiteralText(" entities in "))
.append(new LiteralText(String.valueOf(worldCount)))
.append(new LiteralText(" worlds")),
Text.literal("Successfully destroyed ")
.append(Text.literal(String.valueOf(entityCount)))
.append(Text.literal(" entities in "))
.append(Text.literal(String.valueOf(worldCount)))
.append(Text.literal(" worlds")),
true);
return Command.SINGLE_SUCCESS;

View file

@ -7,19 +7,19 @@ import static net.minecraft.server.command.CommandManager.literal;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.registry.Registries;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
public abstract class CommandEnchantAll {
private static final SimpleCommandExceptionType EMPTY_ITEM_EXCEPTION = new SimpleCommandExceptionType(new LiteralText("Please hold an item in your hand to enchant it"));
private static final SimpleCommandExceptionType EMPTY_ITEM_EXCEPTION = new SimpleCommandExceptionType(Text.literal("Please hold an item in your hand to enchant it"));
public static void register (CommandDispatcher dispatcher) {
dispatcher.register(
@ -31,12 +31,12 @@ public abstract class CommandEnchantAll {
public static int enchantAllCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity player = source.getPlayer();
final PlayerInventory inventory = player.inventory;
final ServerPlayerEntity player = source.getPlayerOrThrow();
final PlayerInventory inventory = player.getInventory();
final ListTag enchantments = new ListTag();
for (Identifier identifier : Registry.ENCHANTMENT.getIds()) {
final CompoundTag enchantment = new CompoundTag();
final NbtList enchantments = new NbtList();
for (Identifier identifier : Registries.ENCHANTMENT.getIds()) {
final NbtCompound enchantment = new NbtCompound();
enchantment.putString("id", identifier.toString());
enchantment.putShort("lvl", (short) 0xFF);
enchantments.add(enchantment);
@ -45,15 +45,15 @@ public abstract class CommandEnchantAll {
final ItemStack stack = inventory.getStack(inventory.selectedSlot).copy();
if (stack.isEmpty()) throw EMPTY_ITEM_EXCEPTION.create();
CompoundTag nbt = stack.getTag();
NbtCompound nbt = stack.getNbt();
if (nbt == null) {
nbt = new CompoundTag();
stack.setTag(nbt);
nbt = new NbtCompound();
stack.setNbt(nbt);
}
stack.getTag().put("Enchantments", enchantments);
stack.getNbt().put("Enchantments", enchantments);
inventory.setStack(inventory.selectedSlot, stack);
source.sendFeedback(new LiteralText("I killed Martin."), false);
source.sendFeedback(Text.literal("I killed Martin."), false);
return Command.SINGLE_SUCCESS;
}

View file

@ -7,18 +7,18 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.command.arguments.EntityArgumentType.players;
import static net.minecraft.command.arguments.EntityArgumentType.getPlayers;
import static net.minecraft.command.argument.EntityArgumentType.players;
import static net.minecraft.command.argument.EntityArgumentType.getPlayers;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.Vec3d;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import java.util.Collection;
public interface CommandJumpscare {
@ -38,11 +38,11 @@ public interface CommandJumpscare {
static int jumpscareCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Collection<ServerPlayerEntity> players = getPlayers(context, "targets");
final ParticleEffect particle = (ParticleEffect) Registry.PARTICLE_TYPE.get(new Identifier("minecraft", "elder_guardian"));
final SoundEvent soundEvent = Registry.SOUND_EVENT.get(new Identifier("minecraft", "entity.enderman.scream"));
final ParticleEffect particle = (ParticleEffect) Registries.PARTICLE_TYPE.get(new Identifier("minecraft", "elder_guardian"));
final SoundEvent soundEvent = Registries.SOUND_EVENT.get(new Identifier("minecraft", "entity.enderman.scream"));
for (ServerPlayerEntity player : players) {
final ServerWorld world = player.getServerWorld();
final ServerWorld world = player.getWorld();
final Vec3d position = player.getPos();
world.<ParticleEffect>spawnParticles(player, particle, false, position.getX(), position.getY(), position.getZ(), 4, 0, 0, 0, 1);
@ -53,15 +53,15 @@ public interface CommandJumpscare {
final ServerPlayerEntity player = (ServerPlayerEntity) players.toArray()[0];
source.sendFeedback(
new LiteralText("Successfully created jumpscare for player \"")
.append(new LiteralText(player.getGameProfile().getName()))
.append(new LiteralText("\""))
Text.literal("Successfully created jumpscare for player \"")
.append(Text.literal(player.getGameProfile().getName()))
.append(Text.literal("\""))
, true);
return Command.SINGLE_SUCCESS;
}
source.sendFeedback(new LiteralText("Successfully created jumpscare for multiple players"), true);
source.sendFeedback(Text.literal("Successfully created jumpscare for multiple players"), true);
return Command.SINGLE_SUCCESS;
}

View file

@ -6,18 +6,17 @@ import com.mojang.brigadier.context.CommandContext;
import static net.minecraft.server.command.CommandManager.literal;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.world.World;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.explosion.Explosion.DestructionType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockPos;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Clearable;
import net.minecraft.text.Text;
import java.util.concurrent.ThreadLocalRandom;
public interface CommandKaboom {
@ -30,40 +29,41 @@ public interface CommandKaboom {
}
static int kaboomCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerPlayerEntity player = context.getSource().getPlayer();
final ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
boolean explode = ThreadLocalRandom.current().nextBoolean();
if (explode) {
final Vec3d position = player.getPos();
final ServerWorld world = player.getServerWorld();
final ServerWorld world = player.getWorld();
final int explosionCount = 20;
final int power = 8;
world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, DestructionType.DESTROY);
world.createExplosion(player, position.getX(), position.getY(), position.getZ(), power, true, World.ExplosionSourceType.MOB);
final int power2 = 4;
final BlockState lava = Registry.BLOCK.get(new Identifier("minecraft", "lava")).getDefaultState();
final BlockState lava = Registries.BLOCK.get(new Identifier("minecraft", "lava")).getDefaultState();
for (int i = 0; i < explosionCount; i++) {
final double posX = position.getX() + ThreadLocalRandom.current().nextInt(-15, 15);
final double posY = position.getY() + ThreadLocalRandom.current().nextInt(-6, 6);
final double posZ = position.getZ() + ThreadLocalRandom.current().nextInt(-15, 15);
world.createExplosion(player, posX, posY, posZ, power2, true, DestructionType.DESTROY);
world.createExplosion(player, posX, posY, posZ, power2, true, World.ExplosionSourceType.MOB);
final BlockPos blockPos = new BlockPos((int) posX, (int) posY, (int) posZ);
if (!world.canSetBlock(blockPos)) continue;
Clearable.clear(world.getBlockEntity(blockPos));
if (world.getBlockState(blockPos).hasBlockEntity()) world.removeBlockEntity(blockPos);
world.setBlockState(blockPos, lava);
}
player.sendMessage(new LiteralText("Forgive me :c"));
player.sendMessage(Text.literal("Forgive me :c"));
return Command.SINGLE_SUCCESS;
}
final PlayerInventory inventory = player.inventory;
inventory.setStack(inventory.selectedSlot, new ItemStack(Registry.ITEM.get(new Identifier("minecraft", "cake"))));
player.sendMessage(new LiteralText("Have a nice day :)"));
final PlayerInventory inventory = player.getInventory();
inventory.setStack(inventory.selectedSlot, new ItemStack(Registries.ITEM.get(new Identifier("minecraft", "cake"))));
player.sendMessage(Text.literal("Have a nice day :)"));
return Command.SINGLE_SUCCESS;
}
}

View file

@ -7,10 +7,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.command.arguments.EntityArgumentType.player;
import static net.minecraft.command.arguments.EntityArgumentType.getPlayer;
import static net.minecraft.command.argument.EntityArgumentType.player;
import static net.minecraft.command.argument.EntityArgumentType.getPlayer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.server.network.ServerPlayerEntity;
@ -32,15 +32,15 @@ public abstract class CommandPing {
public static int pingCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity player = source.getPlayer();
final ServerPlayerEntity player = source.getPlayerOrThrow();
final int ping = player.pingMilliseconds;
final Formatting highlighting = getHighlighting(ping);
source.sendFeedback(
new LiteralText("Your")
.append(new LiteralText(" ping is "))
.append(new LiteralText(String.valueOf(ping)).formatted(highlighting))
.append(new LiteralText("ms.").formatted(highlighting))
Text.literal("Your")
.append(Text.literal(" ping is "))
.append(Text.literal(String.valueOf(ping)).formatted(highlighting))
.append(Text.literal("ms.").formatted(highlighting))
, false);
return Command.SINGLE_SUCCESS;
@ -53,11 +53,11 @@ public abstract class CommandPing {
final Formatting highlighting = getHighlighting(ping);
source.sendFeedback(
new LiteralText(target.getGameProfile().getName())
.append(new LiteralText("'s"))
.append(new LiteralText(" ping is "))
.append(new LiteralText(String.valueOf(ping)).formatted(highlighting))
.append(new LiteralText("ms.").formatted(highlighting))
Text.literal(target.getGameProfile().getName())
.append(Text.literal("'s"))
.append(Text.literal(" ping is "))
.append(Text.literal(String.valueOf(ping)).formatted(highlighting))
.append(Text.literal("ms.").formatted(highlighting))
, false);
return Command.SINGLE_SUCCESS;

View file

@ -6,16 +6,16 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.command.arguments.EntityArgumentType.players;
import static net.minecraft.command.arguments.EntityArgumentType.getPlayers;
import static net.minecraft.command.argument.EntityArgumentType.players;
import static net.minecraft.command.argument.EntityArgumentType.getPlayers;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import java.util.Collection;
public interface CommandPumpkin {
@ -33,10 +33,10 @@ public interface CommandPumpkin {
static int pumpkinCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Collection<ServerPlayerEntity> players = getPlayers(context, "targets");
final Item carvedPumpkin = Registry.ITEM.get(new Identifier("minecraft", "carved_pumpkin"));
final Item carvedPumpkin = Registries.ITEM.get(new Identifier("minecraft", "carved_pumpkin"));
for (ServerPlayerEntity player : players) {
final PlayerInventory inventory = player.inventory;
final PlayerInventory inventory = player.getInventory();
inventory.setStack(39, new ItemStack(carvedPumpkin));
}
@ -44,15 +44,15 @@ public interface CommandPumpkin {
final ServerPlayerEntity player = (ServerPlayerEntity) players.toArray()[0];
source.sendFeedback(
new LiteralText("Player \"")
.append(new LiteralText(player.getGameProfile().getName()))
.append(new LiteralText("\" is now a pumpkin"))
Text.literal("Player \"")
.append(Text.literal(player.getGameProfile().getName()))
.append(Text.literal("\" is now a pumpkin"))
, true);
return Command.SINGLE_SUCCESS;
}
source.sendFeedback(new LiteralText("Multiple players are now pumpkins"), true);
source.sendFeedback(Text.literal("Multiple players are now pumpkins"), true);
return Command.SINGLE_SUCCESS;
}

View file

@ -6,7 +6,8 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@ -26,8 +27,8 @@ public abstract class CommandServerInfo {
private static void sendInfoMessage (ServerCommandSource source, String description, String value) {
source.sendFeedback(
new LiteralText(description).formatted(Formatting.GRAY)
.append(new LiteralText(": " + value).formatted(Formatting.WHITE))
Text.literal(description).formatted(Formatting.GRAY)
.append(Text.literal(": " + value).formatted(Formatting.WHITE))
, false);
}

View file

@ -8,11 +8,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import static net.minecraft.server.command.CommandManager.literal;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.level.LevelProperties;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.text.LiteralText;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.text.Text;
import java.util.Set;
import java.util.HashSet;
@ -28,13 +27,15 @@ public interface CommandSpawn {
static int spawnCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final Entity entity = source.getEntityOrThrow();
final ServerWorld world = source.getMinecraftServer().getWorld(DimensionType.OVERWORLD);
final LevelProperties properties = world.getLevelProperties();
final ServerWorld world = source.getServer().getOverworld();
entity.setWorld(world);
entity.teleport(properties.getSpawnX() + 0.5, properties.getSpawnY(), properties.getSpawnZ() + 0.5);
final Vec3d spawn = Vec3d.ofCenter(world.getSpawnPos());
final float spawnAngle = world.getSpawnAngle();
source.sendFeedback(new LiteralText("Successfully moved to spawn"), false);
final Set<PositionFlag> positionFlags = new HashSet<>();
entity.teleport(world, spawn.getX(), spawn.getY(), spawn.getZ(), positionFlags, spawnAngle, 0);
source.sendFeedback(Text.literal("Successfully moved to spawn"), false);
return Command.SINGLE_SUCCESS;
}

View file

@ -9,12 +9,11 @@ import static net.minecraft.server.command.CommandManager.argument;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Clearable;
import land.chipmunk.kaboomfabric.extras.modules.block.BlockIterator;
public abstract class CommandSpidey {
@ -30,7 +29,7 @@ public abstract class CommandSpidey {
final ServerCommandSource source = context.getSource();
final Entity entity = source.getEntityOrThrow();
final ServerWorld world = source.getWorld();
/*
final Vec3d start = entity.getEyePos();
final Vec3d direction = Vec3d.fromPolar(entity.getYaw(), entity.getPitch());
final int yOffset = 0;
@ -38,16 +37,15 @@ public abstract class CommandSpidey {
final BlockIterator iterator = new BlockIterator(start, direction, yOffset, distance);
final BlockState cobweb = Registry.BLOCK.get(new Identifier("minecraft", "cobweb")).getDefaultState();
final BlockState cobweb = Registries.BLOCK.get(new Identifier("minecraft", "cobweb")).getDefaultState();
while (iterator.hasNext()) {
BlockPos pos = iterator.next();
if ((pos.getY() >= 0 && pos.getY() <= 255) || !world.getBlockState(pos).isAir()) break;
if (!world.isInBuildLimit(pos) || !world.getBlockState(pos).isAir()) break;
Clearable.clear(world.getBlockEntity(pos));
if (world.getBlockState(pos).hasBlockEntity()) world.removeBlockEntity(pos);
world.setBlockState(pos, cobweb);
}
*/
return Command.SINGLE_SUCCESS;
}

View file

@ -0,0 +1,45 @@
package land.chipmunk.kaboomfabric.extras.commands;
import land.chipmunk.kaboomfabric.extras.Extras;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.server.network.ServerPlayerEntity;
import com.mojang.brigadier.tree.LiteralCommandNode;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
public interface CommandTellraw {
static void register (CommandDispatcher dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("broadcastraw")
.requires(CommandTellraw::requirement)
.then(
argument("message", greedyString())
.executes(CommandTellraw::tellrawCommand)
)
);
dispatcher.register(literal("bcraw").requires(CommandTellraw::requirement).executes(CommandTellraw::tellrawCommand).redirect(node));
// No tellraw alias
}
static int tellrawCommand (CommandContext<ServerCommandSource> context) {
String string = getString(context, "message");
Text text = Text.literal(Extras.parseEscapeSequences(string));
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
player.sendMessage(text);
}
return Command.SINGLE_SUCCESS;
}
static boolean requirement (ServerCommandSource source) {
return source.hasPermissionLevel(2);
}
}

View file

@ -0,0 +1,93 @@
package land.chipmunk.kaboomfabric.extras.commands;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.authlib.properties.Property;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.PlayerManager;
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import land.chipmunk.kaboomfabric.extras.Extras;
import land.chipmunk.kaboomfabric.extras.mixin.PlayerEntityAccessor;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
public abstract class CommandUsername {
private static final DynamicCommandExceptionType ALREADY_HAVE_USERNAME_EXCEPTION = new DynamicCommandExceptionType(name -> Text.literal("You already have the username \"").append(Text.literal((String)name)).append(Text.literal("\"")));
private static final SimpleCommandExceptionType RATELIMIT_EXCEPTION = new SimpleCommandExceptionType(Text.literal("Please wait a few seconds before changing your username."));
private static final SimpleCommandExceptionType ALREADY_LOGGED_IN_EXCEPTION = new SimpleCommandExceptionType(Text.literal("A player with that username is already logged in."));
public static final Map<ServerPlayerEntity, Long> lastUsedMillis = new HashMap<>();
public static void register (CommandDispatcher dispatcher) {
dispatcher.register(
literal("username")
.requires(source -> source.hasPermissionLevel(2))
.then(
argument("username", greedyString())
.executes(CommandUsername::usernameCommand)
)
);
}
public static int usernameCommand (CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
final ServerCommandSource source = context.getSource();
final ServerPlayerEntity player = source.getPlayerOrThrow();
final PlayerManager playerManager = source.getServer().getPlayerManager();
final GameProfile oldProfile = player.getGameProfile();
final PropertyMap oldProperties = oldProfile.getProperties();
final String nameColor = Extras.parseEscapeSequences(getString(context, "username"));
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
final long millis = lastUsedMillis.getOrDefault(player, 0L);
final long millisDifference = System.currentTimeMillis() - millis;
if (name.equals(oldProfile.getName())) {
throw ALREADY_HAVE_USERNAME_EXCEPTION.create(name);
}
if (millisDifference <= 2000) {
throw RATELIMIT_EXCEPTION.create();
}
for (ServerPlayerEntity other : source.getServer().getPlayerManager().getPlayerList()) {
if (!other.getGameProfile().getName().equalsIgnoreCase(name)) continue;
throw ALREADY_LOGGED_IN_EXCEPTION.create();
}
final GameProfile newProfile = new GameProfile(oldProfile.getId(), name);
final PropertyMap newProperties = newProfile.getProperties();
for (final Property property : oldProperties.values()) newProperties.put(property.getName(), property);
((PlayerEntityAccessor)(Object)player).gameProfile(newProfile);
lastUsedMillis.put(player, System.currentTimeMillis());
// Update the player's player list entry
playerManager.sendToAll(new PlayerRemoveS2CPacket(Collections.singletonList(oldProfile.getId())));
playerManager.sendToAll(PlayerListS2CPacket.entryFromPlayer(Collections.singleton(player)));
source.sendFeedback(
Text.literal("Successfully set your username to \"")
.append(Text.literal(name))
.append(Text.literal("\""))
, false);
return Command.SINGLE_SUCCESS;
}
}

View file

@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.CommandRegistryAccess;
import com.mojang.brigadier.CommandDispatcher;
@Mixin(CommandManager.class)
@ -16,7 +17,7 @@ public abstract class CommandManagerMixin {
private CommandDispatcher<ServerCommandSource> dispatcher;
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;setConsumer(Lcom/mojang/brigadier/ResultConsumer;)V", remap = false), method = "<init>")
private void init (boolean isDedicatedServer, CallbackInfo info) {
private void init (CommandManager.RegistrationEnvironment environment, CommandRegistryAccess commandRegistryAccess, CallbackInfo info) {
Extras.registerCommands(dispatcher);
}
}

View file

@ -1,16 +0,0 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
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.brigadier.CommandDispatcher;
import net.minecraft.server.command.ServerCommandSource;
@Mixin(net.minecraft.server.command.DebugDimCommand.class)
public abstract class DebugDimCommandMixin {
@Inject(at = @At("HEAD"), method = "register", cancellable = true)
private static void register (CommandDispatcher<ServerCommandSource> dispatcher, CallbackInfo info) {
info.cancel();
}
}

View file

@ -1,9 +0,0 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(net.minecraft.entity.Entity.class)
public interface EntityAccessor {
@Invoker("destroy") void destroy ();
}

View file

@ -0,0 +1,11 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import com.mojang.authlib.GameProfile;
@Mixin(net.minecraft.entity.player.PlayerEntity.class)
public interface PlayerEntityAccessor {
@Accessor("gameProfile") @Mutable void gameProfile (GameProfile profile);
}

View file

@ -3,15 +3,14 @@ package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.mojang.brigadier.context.CommandContext;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.server.command.ServerCommandSource;
import java.util.Collection;
@Mixin(net.minecraft.server.command.ReloadCommand.class)
public abstract class ReloadCommandMixin {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;reload()V"), method = "method_13530", cancellable = true)
private static void reload (CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> info) {
@Inject(at = @At("HEAD"), method = "tryReloadDataPacks", cancellable = true)
private static void tryReloadDataPacks (Collection<?> datapacks, ServerCommandSource source, CallbackInfo info) {
info.cancel();
}
}

View file

@ -1,11 +0,0 @@
package land.chipmunk.kaboomfabric.extras.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.entity.Entity;
@Mixin(net.minecraft.server.world.ServerWorld.class)
public interface ServerWorldAccessor {
@Accessor("entitiesById") Int2ObjectMap<Entity> entitiesById ();
}

View file

@ -219,12 +219,9 @@ public class BlockIterator implements Iterator<BlockPos> {
return getPosition(direction.getZ(), position.getZ(), block.getZ());
}
// TODO: Backport
/*
public BlockIterator(Entity entity, int maxDistance) {
this(entity.getPos(), Vec3d.fromPolar(entity.getYaw(), entity.getPitch()), entity.getEyeHeight(entity.getPose()), maxDistance);
}
*/
/**
* Constructs the BlockIterator.
@ -234,11 +231,9 @@ public class BlockIterator implements Iterator<BlockPos> {
* @param entity Information from the entity is used to set up the trace
*/
/*
public BlockIterator(Entity entity) {
this(entity, 0);
}
*/
/**
* Returns true if the iteration has more elements

View file

@ -11,9 +11,7 @@
"ReloadCommandMixin",
"OpCommandMixin",
"EntitySelectorMixin",
"ServerWorldAccessor",
"EntityAccessor",
"DebugDimCommandMixin"
"PlayerEntityAccessor"
],
"injectors": {
"defaultRequire": 1

View file

@ -33,11 +33,10 @@
],
"depends": {
"fabricloader": ">=0.15.11",
"minecraft": "1.16-alpha.20.13.inf",
"java": ">=8"
"fabricloader": ">=0.14.17",
"minecraft": "~1.19.4",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
}