Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
d15b8a8786 Finalize the 1.16.5 backport
Please note that tab completions do not fully work as intended yet
2023-06-03 22:01:35 -04:00
dfc8cf6cf9 more backporting 2023-06-03 18:12:39 -04:00
916a8df766 Merge branch '1.19' of code.chipmunk.land:ChipmunkMC/chipmunkmod into HEAD 2023-06-03 17:43:09 -04:00
7d0ceeef9b partially backport it 2023-06-03 17:33:38 -04:00
20 changed files with 90 additions and 146 deletions

View file

@ -4,9 +4,9 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.19
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.10
loader_version=0.14.21
# Mod Properties
mod_version = 1.0.0
@ -14,4 +14,4 @@ org.gradle.parallel=true
archives_base_name = chipmunkmod
# Dependencies
fabric_version=0.80.0+1.19.4
fabric_version=0.42.0+1.16

View file

@ -1,12 +1,13 @@
package land.chipmunk.chipmunkmod;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.util.math.BlockPos;
import land.chipmunk.chipmunkmod.util.gson.*;
import land.chipmunk.chipmunkmod.command.CommandManager;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
@ -20,7 +21,7 @@ public class ChipmunkMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("chipmunkmod");
public static final Logger LOGGER = LogManager.getLogger("chipmunkmod");
public static Configuration CONFIG;
private static File CONFIG_DIR = new File("config");
private static File CONFIG_FILE = new File(CONFIG_DIR, "chipmunkmod.json");
@ -37,6 +38,8 @@ public class ChipmunkMod implements ModInitializer {
throw new RuntimeException("Could not load the config", exception);
}
CommandManager.INSTANCE = new CommandManager(CONFIG.commands.prefix); // ? Should this be done here?
LOGGER.info("Hello Fabric world!");
}

View file

@ -8,12 +8,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.CommandException;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Texts;
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.client.MinecraftClient;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import land.chipmunk.chipmunkmod.commands.*;
public class CommandManager {
@ -22,7 +23,7 @@ public class CommandManager {
public static CommandManager INSTANCE;
public CommandManager (String prefix, CommandRegistryAccess commandRegistryAccess) {
public CommandManager (String prefix) {
this.prefix = prefix;
TestCommand.register(this.dispatcher);
@ -30,7 +31,7 @@ public class CommandManager {
UsernameCommand.register(this.dispatcher);
CloopCommand.register(this.dispatcher);
ValidateCommand.register(this.dispatcher);
ItemCommand.register(this.dispatcher, commandRegistryAccess);
ItemCommand.register(this.dispatcher);
SayCommand.register(this.dispatcher);
}
@ -59,24 +60,24 @@ public class CommandManager {
if (input == null || _cursor < 0) {
return null;
}
final MutableText text = Text.literal("")
final MutableText text = new LiteralText("")
.formatted(Formatting.GRAY);
text.setStyle(text.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, prefix + input)));
final int cursor = Math.min(input.length(), _cursor);
if (cursor > CommandSyntaxException.CONTEXT_AMOUNT) {
text.append(Text.literal("..."));
text.append(new LiteralText("..."));
}
text
.append(Text.literal(input.substring(Math.max(0, cursor - CommandSyntaxException.CONTEXT_AMOUNT), cursor)))
.append(Text.literal(input.substring(cursor)).formatted(Formatting.RED, Formatting.UNDERLINE))
.append(Text.translatable("command.context.here").formatted(Formatting.RED, Formatting.ITALIC));
.append(new LiteralText(input.substring(Math.max(0, cursor - CommandSyntaxException.CONTEXT_AMOUNT), cursor)))
.append(new LiteralText(input.substring(cursor)).formatted(Formatting.RED, Formatting.UNDERLINE))
.append(new TranslatableText("command.context.here").formatted(Formatting.RED, Formatting.ITALIC));
return text;
}
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (String name) { return LiteralArgumentBuilder.literal(name); }
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument (String name, ArgumentType<T> type) { return RequiredArgumentBuilder.argument(name, type); }
}
}

View file

@ -13,13 +13,14 @@ import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import land.chipmunk.chipmunkmod.modules.CommandLoopManager;
import java.util.List;
public class CloopCommand {
private static final DynamicCommandExceptionType INVALID_CLOOP_ID_EXCEPTION = new DynamicCommandExceptionType(id -> Text.translatable("Invalid cloop id: %s", Text.literal(String.valueOf(id))));
private static final DynamicCommandExceptionType INVALID_CLOOP_ID_EXCEPTION = new DynamicCommandExceptionType(id -> new TranslatableText("Invalid cloop id: %s", new LiteralText(String.valueOf(id))));
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
@ -59,7 +60,7 @@ public class CloopCommand {
int id = CommandLoopManager.INSTANCE.loopCommand(command, interval);
source.sendFeedback(Text.translatable("Successfully created a loop for command '%s' with id %s", Text.literal(command), Text.literal(String.valueOf(id))));
source.sendFeedback(new TranslatableText("Successfully created a loop for command '%s' with id %s", new LiteralText(command), new LiteralText(String.valueOf(id))));
return Command.SINGLE_SUCCESS;
}
@ -72,7 +73,7 @@ public class CloopCommand {
manager.removeAndStop(id);
source.sendFeedback(Text.translatable("Successfully removed loop with id %s", Text.literal(String.valueOf(id))));
source.sendFeedback(new TranslatableText("Successfully removed loop with id %s", new LiteralText(String.valueOf(id))));
return Command.SINGLE_SUCCESS;
}
@ -82,7 +83,7 @@ public class CloopCommand {
manager.clearLoops();
source.sendFeedback(Text.translatable("Successfully cleared all command loops"));
source.sendFeedback(new TranslatableText("Successfully cleared all command loops"));
return Command.SINGLE_SUCCESS;
}
@ -92,12 +93,12 @@ public class CloopCommand {
int id = 0;
for (CommandLoopManager.CommandLoop loop : loops) {
source.sendFeedback(Text.translatable("%s: %s (%s)", Text.literal(String.valueOf(id)), Text.literal(loop.command()), Text.literal(String.valueOf(loop.interval()))));
source.sendFeedback(new TranslatableText("%s: %s (%s)", new LiteralText(String.valueOf(id)), new LiteralText(loop.command()), new LiteralText(String.valueOf(loop.interval()))));
id++;
}
if (id == 0) {
source.sendFeedback(Text.translatable("No command loops are currently running"));
source.sendFeedback(new TranslatableText("No command loops are currently running"));
}
return Command.SINGLE_SUCCESS;

View file

@ -7,7 +7,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.minecraft.nbt.NbtCompound;
import java.util.concurrent.CompletableFuture;

View file

@ -10,19 +10,19 @@ import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static net.minecraft.command.argument.ItemStackArgumentType.itemStack;
import static net.minecraft.command.argument.ItemStackArgumentType.getItemStackArgument;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandRegistryAccess;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
public class ItemCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
literal("item")
.then(
argument("item", itemStack(commandRegistryAccess))
argument("item", itemStack())
.executes(c -> setItem(c, 1))
.then(
argument("count", integer(1, 64))
@ -42,14 +42,14 @@ public class ItemCommand {
final ItemStack stack = getItemStackArgument(context, "item").createStack(count, false);
int slot = 36 + client.player.getInventory().selectedSlot;
int slot = 36 + client.player.inventory.selectedSlot;
client.getNetworkHandler().getConnection().send(new CreativeInventoryActionC2SPacket(slot, stack));
source.sendFeedback(
Text.translatable(
new TranslatableText(
"Replaced your held item with %s %s",
Text.literal(String.valueOf(count)),
new LiteralText(String.valueOf(count)),
stack.toHoverableText()
)
);

View file

@ -7,8 +7,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
public class SayCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
@ -23,7 +22,7 @@ public class SayCommand {
public static int say (CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
source.getClient().getNetworkHandler().sendChatMessage(getString(context, "message"));
source.getPlayer().sendChatMessage(getString(context, "message"));
return Command.SINGLE_SUCCESS;
}

View file

@ -4,8 +4,8 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.text.LiteralText;
public class TestCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
@ -17,7 +17,7 @@ public class TestCommand {
public static int helloWorld (CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
source.sendFeedback(Text.literal("Hello, world!"));
source.sendFeedback(new LiteralText("Hello, world!"));
return Command.SINGLE_SUCCESS;
}

View file

@ -7,7 +7,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConnectScreen;
import net.minecraft.client.gui.screen.TitleScreen;
@ -15,7 +15,7 @@ import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.util.Session;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import java.util.Optional;
@ -23,7 +23,7 @@ import land.chipmunk.chipmunkmod.mixin.MinecraftClientAccessor;
public class UsernameCommand {
private static final Session ORIGINAL_SESSION = ((MinecraftClientAccessor) MinecraftClient.getInstance()).session();
private static final SimpleCommandExceptionType USERNAME_TOO_LONG = new SimpleCommandExceptionType(Text.translatable("The specified username is longer than 16 characters"));
private static final SimpleCommandExceptionType USERNAME_TOO_LONG = new SimpleCommandExceptionType(new TranslatableText("The specified username is longer than 16 characters"));
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
@ -45,7 +45,7 @@ public class UsernameCommand {
public static int updateUsername (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
final String username = getString(context, "username");
if (username.length() > 16) throw USERNAME_TOO_LONG.create();
final Session session = new Session(username, "", "", Optional.empty(), Optional.empty(), Session.AccountType.MOJANG);
final Session session = new Session(username, "", "", "");
return updateSession(context, session);
}
@ -60,7 +60,8 @@ public class UsernameCommand {
final ServerInfo info = client.getCurrentServerEntry();
client.world.disconnect();
client.disconnect();
ConnectScreen.connect(new MultiplayerScreen(new TitleScreen()), client, ServerAddress.parse(info.address), info);
final ServerAddress address = ServerAddress.parse(info.address);
new ConnectScreen(new MultiplayerScreen(new TitleScreen()), client, info);
return Command.SINGLE_SUCCESS;
}

View file

@ -7,10 +7,10 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import java.util.Arrays;
@ -23,7 +23,7 @@ import land.chipmunk.chipmunkmod.Configuration;
import land.chipmunk.chipmunkmod.util.Hexadecimal;
public class ValidateCommand {
private static final SimpleCommandExceptionType UNSPECIFIED_KEY = new SimpleCommandExceptionType(Text.literal("The key of the bot is unspecified (null), did you incorrectly add it to your config?"));
private static final SimpleCommandExceptionType UNSPECIFIED_KEY = new SimpleCommandExceptionType(new LiteralText("The key of the bot is unspecified (null), did you incorrectly add it to your config?"));
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(
@ -41,7 +41,6 @@ public class ValidateCommand {
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.hbot;
final String command = getString(context, "command");
final MinecraftClient client = context.getSource().getClient();
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
final String prefix = info.prefix;
final String key = info.key;
@ -55,9 +54,9 @@ public class ValidateCommand {
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
String stringHash = bigInt.toString(Character.MAX_RADIX);
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
client.player.sendChatMessage(prefix + command + " " + stringHash);
} catch (NoSuchAlgorithmException e) {
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
throw new SimpleCommandExceptionType(new LiteralText(e.getMessage())).create();
}
return Command.SINGLE_SUCCESS;
@ -67,7 +66,6 @@ public class ValidateCommand {
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot;
final String command = getString(context, "command");
final MinecraftClient client = context.getSource().getClient();
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
final String prefix = info.prefix;
final String key = info.key;
@ -81,9 +79,9 @@ public class ValidateCommand {
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
String stringHash = bigInt.toString(Character.MAX_RADIX);
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
client.player.sendChatMessage(prefix + command + " " + stringHash);
} catch (NoSuchAlgorithmException e) {
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
throw new SimpleCommandExceptionType(new LiteralText(e.getMessage())).create();
}
return Command.SINGLE_SUCCESS;
@ -92,7 +90,7 @@ public class ValidateCommand {
public static int chomens (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.chomens;
final String command = getString(context, "command");
final ClientPlayNetworkHandler networkHandler = context.getSource().getClient().getNetworkHandler();
final MinecraftClient client = context.getSource().getClient();
final String prefix = info.prefix;
final String key = info.key;
@ -106,9 +104,9 @@ public class ValidateCommand {
String stringHash = Hexadecimal.encode(hash).substring(0, 16);
String[] arguments = command.split(" ");
networkHandler.sendChatMessage(prefix + arguments[0] + " " + stringHash + " " + String.join(" ", Arrays.copyOfRange(arguments, 1, arguments.length)));
client.player.sendChatMessage(prefix + arguments[0] + " " + stringHash + " " + String.join(" ", Arrays.copyOfRange(arguments, 1, arguments.length)));
} catch (NoSuchAlgorithmException e) {
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
throw new SimpleCommandExceptionType(new LiteralText(e.getMessage())).create();
}
return Command.SINGLE_SUCCESS;
@ -117,7 +115,7 @@ public class ValidateCommand {
public static int kittycorp (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.kittycorp;
final String command = getString(context, "command");
final ClientPlayNetworkHandler networkHandler = context.getSource().getClient().getNetworkHandler();
final MinecraftClient client = context.getSource().getClient();
final String prefix = info.prefix;
final String key = info.key;
@ -131,9 +129,9 @@ public class ValidateCommand {
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
String stringHash = bigInt.toString(Character.MAX_RADIX);
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
client.player.sendChatMessage(prefix + command + " " + stringHash);
} catch (NoSuchAlgorithmException e) {
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
throw new SimpleCommandExceptionType(new LiteralText(e.getMessage())).create();
}
return Command.SINGLE_SUCCESS;

View file

@ -1,24 +0,0 @@
package land.chipmunk.chipmunkmod.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 net.minecraft.client.MinecraftClient;
import land.chipmunk.chipmunkmod.command.CommandManager;
@Mixin(net.minecraft.client.gui.screen.ChatScreen.class)
public class ChatScreenMixin {
@Inject(at = @At("HEAD"), method = "sendMessage", cancellable = true)
public void sendMessage(String chatText, boolean addToHistory, CallbackInfoReturnable<Boolean> cir) {
final CommandManager commandManager = CommandManager.INSTANCE;
if (chatText.startsWith(commandManager.prefix)) {
commandManager.executeCommand(chatText.substring(commandManager.prefix.length()));
if (addToHistory) MinecraftClient.getInstance().inGameHud.getChatHud().addToMessageHistory(chatText);
cir.setReturnValue(true);
}
}
}

View file

@ -1,20 +0,0 @@
package land.chipmunk.chipmunkmod.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 net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.text.Text;
import land.chipmunk.chipmunkmod.modules.CommandCore;
import land.chipmunk.chipmunkmod.modules.SelfCare;
@Mixin(net.minecraft.network.ClientConnection.class)
public class ClientConnectionMixin {
@Inject(at = @At("HEAD"), method = "disconnect", cancellable = true)
public void disconnect (Text disconnectReason, CallbackInfo ci) {
if (disconnectReason == ClientPlayNetworkHandlerAccessor.chatValidationFailedText()) {
ci.cancel();
}
}
}

View file

@ -1,11 +0,0 @@
package land.chipmunk.chipmunkmod.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.text.Text;
@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class)
public interface ClientPlayNetworkHandlerAccessor {
@Accessor("CHAT_VALIDATION_FAILED_TEXT")
public static Text chatValidationFailedText () { throw new AssertionError(); }
}

View file

@ -6,24 +6,12 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.registry.CombinedDynamicRegistries;
import net.minecraft.client.network.ClientDynamicRegistryType;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.command.CommandManager;
import land.chipmunk.chipmunkmod.modules.SelfCare;
@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
@Shadow private FeatureSet enabledFeatures;
@Shadow private CombinedDynamicRegistries<ClientDynamicRegistryType> combinedDynamicRegistries;
@Inject(method = "onGameJoin", at = @At("TAIL"))
private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) {
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures);
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
SelfCare.INSTANCE.init();
}
}

View file

@ -11,8 +11,8 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec2f;
import land.chipmunk.chipmunkmod.modules.CommandCore;
import land.chipmunk.chipmunkmod.command.CommandManager;
@Mixin(ClientPlayerEntity.class)
public class ClientPlayerEntityMixin {
@ -28,7 +28,18 @@ public class ClientPlayerEntityMixin {
final BlockPos origin = CommandCore.INSTANCE.origin();
if (origin == null) { CommandCore.INSTANCE.move(position); return; }
final int distance = (int) Math.sqrt(new Vec2f(origin.getX() / 16, origin.getZ() / 16).distanceSquared(new Vec2f((int) position.getX() / 16, (int) position.getZ() / 16)));
if (distance > world.getSimulationDistance()) CommandCore.INSTANCE.move(position);
final int distance = (int) Math.hypot(origin.getX() / 16 - (int) position.getX() / 16, origin.getZ() / 16 - (int) position.getZ() / 16);
if (distance > 4) CommandCore.INSTANCE.move(position);
}
@Inject(at = @At("HEAD"), method = "sendChatMessage", cancellable = true)
private void sendChatMessage (String message, CallbackInfo ci) {
final CommandManager commandManager = CommandManager.INSTANCE;
if (message.startsWith(commandManager.prefix)) {
commandManager.executeCommand(message.substring(commandManager.prefix.length()));
ci.cancel();
}
}
}

View file

@ -11,25 +11,25 @@ import net.minecraft.client.gui.widget.TextFieldWidget;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import land.chipmunk.chipmunkmod.command.CommandManager;
@Mixin(net.minecraft.client.gui.screen.ChatInputSuggestor.class)
public class ChatInputSuggestorMixin {
@Mixin(net.minecraft.client.gui.screen.CommandSuggestor.class)
public class CommandSuggestorMixin {
@Shadow
CompletableFuture<Suggestions> pendingSuggestions;
@Shadow
public boolean slashOptional;
@Shadow
public void show (boolean narrateFirstSuggestion) {}
// @Shadow
// public void show () {}
@Shadow
final TextFieldWidget textField;
public ChatInputSuggestorMixin () {
public CommandSuggestorMixin () {
textField = null;
}
@ -52,6 +52,6 @@ public class ChatInputSuggestorMixin {
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
pendingSuggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(reader, commandSource), cursor);
show(true);
// show();
}
}

View file

@ -64,7 +64,7 @@ public class CommandCore {
relEnd.getZ() + origin.getZ()
);
client.getNetworkHandler().sendChatCommand(command);
client.player.sendChatMessage("/" + command);
}
public void incrementCurrentBlock () {

View file

@ -52,8 +52,8 @@ public class SelfCare {
return;
}
if (!player.hasPermissionLevel(2)) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); }
else if (!client.player.isCreative()) networkHandler.sendChatCommand("gamemode creative");
if (!player.hasPermissionLevel(2)) { if (serverHasCommand("op")) player.sendChatMessage("/op @s[type=player]"); }
else if (!client.player.isCreative()) player.sendChatMessage("/gamemode creative");
}
// TODO: Move this into a separate class related to server info gathering (and yes, I plan on making this d y n a m i c and require little to no configuration for most servers)

View file

@ -6,10 +6,7 @@
"mixins": [
],
"client": [
"ChatScreenMixin",
"ChatInputSuggestorMixin",
"ClientPlayNetworkHandlerAccessor",
"ClientConnectionMixin",
"CommandSuggestorMixin",
"ClientPlayerEntityMixin",
"ClientPlayNetworkHandlerMixin",
"MinecraftClientAccessor"

View file

@ -28,8 +28,8 @@
"depends": {
"fabricloader": ">=0.14.11",
"fabric-api": "*",
"minecraft": "~1.19.3",
"fabric": "*",
"minecraft": "~1.16.5",
"java": ">=17"
},
"suggests": {