Add test1 command, add CommandTest.java which isn't implemented yet

This commit is contained in:
kelson8 2024-03-13 21:47:45 -04:00
parent 454c435edc
commit db76f97f6f
3 changed files with 42 additions and 1 deletions

View File

@ -1,33 +1,48 @@
package net.kelsoncraft.test; package net.kelsoncraft.test;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
import net.fabricmc.fabric.mixin.client.rendering.EntityRenderersMixin; import net.fabricmc.fabric.mixin.client.rendering.EntityRenderersMixin;
import net.kelsoncraft.test.item.CustomItems; import net.kelsoncraft.test.item.CustomItems;
import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.LightningEntityRenderer; import net.minecraft.client.render.entity.LightningEntityRenderer;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity; import net.minecraft.entity.LightningEntity;
import net.minecraft.inventory.EnderChestInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.predicate.entity.LightningBoltPredicate; import net.minecraft.predicate.entity.LightningBoltPredicate;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.Vec3d;
public class KelsonCraftTestClient implements ClientModInitializer { public class KelsonCraftTestClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
// This could be useful if I wanted to run something when a player gets in or out of a bed.
// EntitySleepEvents.START_SLEEPING
// EntitySleepEvents.STOP_SLEEPING
//EnderChestInventory
// Code below came from https://www.reddit.com/r/fabricmc/comments/qyt3jg/comment/hls4vep/ // Code below came from https://www.reddit.com/r/fabricmc/comments/qyt3jg/comment/hls4vep/
// This works, but it doesn't show the lightning strike. // This works, but it doesn't show the lightning strike.
// This runs whenever a player right clicks with the ruby, which is set in the if statement // This runs whenever a player right clicks with the ruby, which is set in the if statement
UseItemCallback.EVENT.register((player, world, unused) ->{ UseItemCallback.EVENT.register((player, world, unused) ->{
ItemStack mainHandItem = player.getMainHandStack(); // Get the item the player is holding in their main hand. ItemStack mainHandItem = player.getMainHandStack(); // Get the item the player is holding in their main hand.
if(player.getMainHandStack().getName().equals(Text.translatable("item.kelsoncraft-test.ruby"))){ // Check if item is a ruby. if(player.getMainHandStack().getName().equals(Text.translatable("item.kelsoncraft-test.ruby")) && !player.isSpectator()){ // Check if item is a ruby, and if the player is not in spectator mode.
LightningEntity lightning = new LightningEntity(EntityType.LIGHTNING_BOLT, world); // Create the lightning bolt. LightningEntity lightning = new LightningEntity(EntityType.LIGHTNING_BOLT, world); // Create the lightning bolt.
world.spawnEntity(lightning); // Spawn the lightning entity world.spawnEntity(lightning); // Spawn the lightning entity
//player.set
// This is how to get the player position
Vec3d playerPos = player.getPos();
//player.sendMessage(Text.of("Your coords are X: " + playerPos.x + " Y: " + playerPos.y + " Z: " + playerPos.z));
// This might be a way to make the lightning render in, I'm not sure how to use the EntityRendererFactory.Context() // This might be a way to make the lightning render in, I'm not sure how to use the EntityRendererFactory.Context()
//LightningEntityRenderer lightning1 = new LightningEntityRenderer(new EntityRendererFactory.Context()); //LightningEntityRenderer lightning1 = new LightningEntityRenderer(new EntityRendererFactory.Context());

View File

@ -0,0 +1,18 @@
package net.kelsoncraft.test;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.text.Text;
public class CommandTest {
// This doesn't work at all in other classes.
//
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("test")
// .executes(context -> {
// // For versions below 1.19, replace "Text.literal" with "new LiteralText".
// // For versions below 1.20, remode "() ->" directly.
// context.getSource().sendFeedback(() -> Text.literal("Called /test with no arguments"), false);
//
//
// return 1;
// })));
}

View File

@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.kelsoncraft.test.block.CustomBlocks; import net.kelsoncraft.test.block.CustomBlocks;
import net.kelsoncraft.test.item.CustomItems; import net.kelsoncraft.test.item.CustomItems;
import net.kelsoncraft.test.item.CustomItemGroups; import net.kelsoncraft.test.item.CustomItemGroups;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -77,6 +78,13 @@ public class KelsonCraftTest implements ModInitializer {
return 1; return 1;
}))); })));
// I wonder how to get the player name with a command.
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("test1")
.executes(context -> {
context.getSource().sendFeedback(() -> Text.literal("Hello player %s"), false);
return 1;
})));
// This is a way to use the item as fuel // This is a way to use the item as fuel
FuelRegistry.INSTANCE.add(CustomItems.CUSTOM_ITEM, 300); FuelRegistry.INSTANCE.add(CustomItems.CUSTOM_ITEM, 300);