diff --git a/src/client/java/net/kelsoncraft/test/KelsonCraftTestClient.java b/src/client/java/net/kelsoncraft/test/KelsonCraftTestClient.java index 3ed48bb..c915a37 100644 --- a/src/client/java/net/kelsoncraft/test/KelsonCraftTestClient.java +++ b/src/client/java/net/kelsoncraft/test/KelsonCraftTestClient.java @@ -1,33 +1,48 @@ package net.kelsoncraft.test; 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.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.fabricmc.fabric.mixin.client.rendering.EntityRenderersMixin; import net.kelsoncraft.test.item.CustomItems; import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.LightningEntityRenderer; import net.minecraft.entity.EntityType; import net.minecraft.entity.LightningEntity; +import net.minecraft.inventory.EnderChestInventory; import net.minecraft.item.ItemStack; import net.minecraft.predicate.entity.LightningBoltPredicate; import net.minecraft.text.Text; import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.Vec3d; public class KelsonCraftTestClient implements ClientModInitializer { @Override 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/ // 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 UseItemCallback.EVENT.register((player, world, unused) ->{ 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. 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() //LightningEntityRenderer lightning1 = new LightningEntityRenderer(new EntityRendererFactory.Context()); diff --git a/src/main/java/net/kelsoncraft/test/CommandTest.java b/src/main/java/net/kelsoncraft/test/CommandTest.java new file mode 100644 index 0000000..1f83338 --- /dev/null +++ b/src/main/java/net/kelsoncraft/test/CommandTest.java @@ -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; +// }))); +} diff --git a/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java b/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java index da82199..a330356 100644 --- a/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java +++ b/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java @@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.kelsoncraft.test.block.CustomBlocks; import net.kelsoncraft.test.item.CustomItems; import net.kelsoncraft.test.item.CustomItemGroups; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,6 +78,13 @@ public class KelsonCraftTest implements ModInitializer { 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 FuelRegistry.INSTANCE.add(CustomItems.CUSTOM_ITEM, 300);