Buckets:
| package com.example.examplemod; | |
| import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; | |
| import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; | |
| import net.minecraft.server.MinecraftServer; | |
| import net.minecraft.text.Text; | |
| /** | |
| * Example event listeners. Register these inside ModInitializer#onInitialize(). | |
| * Event API has not had breaking changes across 1.21.7 - 1.21.11. | |
| */ | |
| public final class ExampleEvents { | |
| private ExampleEvents() {} | |
| public static void register() { | |
| // Fires right before a block is broken; return false to cancel it. | |
| PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, entity) -> { | |
| if (state.getBlock() == ExampleMod.EXAMPLE_BLOCK) { | |
| player.sendMessage(Text.literal("You're breaking the example block!"), true); | |
| } | |
| return true; // allow the break | |
| }); | |
| // Fires once per server tick (20x/sec). Useful for timers, scheduled tasks, etc. | |
| ServerTickEvents.END_SERVER_TICK.register(ExampleEvents::onServerTick); | |
| } | |
| private static int tickCounter = 0; | |
| private static void onServerTick(MinecraftServer server) { | |
| tickCounter++; | |
| if (tickCounter % 200 == 0) { // every 10 seconds | |
| server.getPlayerManager().broadcast( | |
| Text.literal("Server has been running for " + (tickCounter / 20) + " seconds."), | |
| false | |
| ); | |
| } | |
| } | |
| } | |
Xet Storage Details
- Size:
- 1.47 kB
- Xet hash:
- 962b027ff052df52729fc46457cb94d6edaa1a220bf5affe932b6b79ded2d929
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.