Add test1 command, add craft command which is incomplete.

This commit is contained in:
kelson8 2024-03-19 06:07:17 -04:00
parent 71a15ee04d
commit d2d630a099
Signed by: kelson8
GPG Key ID: 3D738D9DD7239E13

View File

@ -2,8 +2,15 @@ package net.kelsoncraft.test;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.kelsoncraft.test.util.Messages; import net.kelsoncraft.test.util.Messages;
import net.minecraft.block.PlayerSkullBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SentMessage;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
// https://www.reddit.com/r/fabricmc/comments/r3bd47/fabric_execute_commands/ // https://www.reddit.com/r/fabricmc/comments/r3bd47/fabric_execute_commands/
@ -15,6 +22,31 @@ public class TestCommands {
public TestCommands() { public TestCommands() {
} }
// I'm not sure how to use this.
// private String getPlayer() {
//
// PlayerEntity playerEntity = new PlayerEntity() {
// @Override
// public boolean isSpectator() {
// return false;
// }
//
// @Override
// public boolean isCreative() {
// return false;
// }
// }
// return "";
// }
// This may crash the server.
// PlayerEntity player;
// This might be fun.
// PlayerSkullBlock playerSkullBlock = new PlayerSkullBlock();
// PlayerInventory playerInventory = new PlayerInventory(player);
// CraftingInventory craftingInventory = new CraftingInventory();
// This works like this, now I know how to add commands to other classes, add them like this then initialize them in the main class. // This works like this, now I know how to add commands to other classes, add them like this then initialize them in the main class.
public static void init() { public static void init() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("teleport") CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("teleport")
@ -33,6 +65,48 @@ public class TestCommands {
context.getSource().sendFeedback(() -> Text.literal(lightningMsg), false); context.getSource().sendFeedback(() -> Text.literal(lightningMsg), false);
return 1; return 1;
}))); })));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("test1")
.executes(context -> {
// // I don't know how to send a chat message with the below code. I need a message params
// SentMessage sentMessage = new SentMessage() {
// @Override
// public Text getContent() {
// return null;
// }
//
// @Override
// public void send(ServerPlayerEntity sender, boolean filterMaskEnabled, MessageType.Parameters params) {
//
// }
// };
// context.getSource().sendChatMessage(sentMessage, false, );
context.getSource().sendFeedback(() -> Text.literal("You will be exterminated!"), false);
return 1;
})));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("craft")
.executes(context -> {
// // I don't know how to send a chat message with the below code. I need a message params
// SentMessage sentMessage = new SentMessage() {
// @Override
// public Text getContent() {
// return null;
// }
//
// @Override
// public void send(ServerPlayerEntity sender, boolean filterMaskEnabled, MessageType.Parameters params) {
//
// }
// };
// context.getSource().sendChatMessage(sentMessage, false, );
return 1;
})));
} }
} }