MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Creates a block that lights up when a keybind is executed"
/* This mod creates a block that lights up when a specific keybind is executed. */ public class LightUpBlock extends Block { public LightUpBlock(AbstractBlock.Properties properties) { super(properties); } @Override public void onPlayerInteract(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { if (Keybinds.LIGHT_UP.consumeClick()) { world.setBlock(pos, state.setValue(BlockStateProperties.LIT, true), 3); } } } /* The keybind class is defined as follows: */ public class Keybinds { public static final KeyBinding LIGHT_UP = new KeyBinding("key.light_up", InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_L, "category.keys"); public static void register() { ClientRegistry.registerKeyBinding(LIGHT_UP); } } /* In your mod's main class, call Keybinds.register() in the doClientStuff method: */ @Mod.EventBusSubscriber(modid = YourMod.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class ClientEventBusSubscriber { @SubscribeEvent public static void onClientSetupEvent(FMLClientSetupEvent event) { Keybinds.register(); } } /* Note: Replace "YourMod.MODID" with your mod's modid and "YourMod" with your mod's main class name. Also, you need to import the necessary classes and handle the exceptions accordingly. */