first commit
build / build (push) Has been cancelled

This commit is contained in:
database-mysql committed 2026-10-19 02:16:09 +08:00
commit d3a684b6e4
19 files changed
+935

No files matched your search

@@ -0,0 +1,100 @@
package top.gtb520.java.mods.openfly.Commands;
import com.mojang.brigadier.Command;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class fly {
// 记录开启了飞行的玩家UUID
private static final Set<UUID> flyingPlayers = new HashSet<>();
public static void register() {
// 注册命令
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(
CommandManager.literal("fly")
// /fly - 切换自己的飞行状态(所有玩家可用)
.executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
if (player == null) {
context.getSource().sendFeedback(() -> Text.literal("该命令只能由玩家执行"), false);
return 0;
}
UUID playerId = player.getUuid();
if (flyingPlayers.contains(playerId)) {
disableFly(player);
context.getSource().sendFeedback(() -> Text.literal("已禁用飞行"), false);
} else {
enableFly(player);
context.getSource().sendFeedback(() -> Text.literal("已启用飞行"), false);
}
return Command.SINGLE_SUCCESS;
})
// /fly <player> - 切换指定玩家的飞行状态(需要OP权限)
.then(CommandManager.argument("player", EntityArgumentType.player())
.requires(source -> source.hasPermissionLevel(2))
.executes(context -> {
ServerPlayerEntity targetPlayer = EntityArgumentType.getPlayer(context, "player");
UUID playerId = targetPlayer.getUuid();
if (flyingPlayers.contains(playerId)) {
disableFly(targetPlayer);
context.getSource().sendFeedback(
() -> Text.literal("已禁用玩家 " + targetPlayer.getName().getString() + " 的飞行"), true);
} else {
enableFly(targetPlayer);
context.getSource().sendFeedback(
() -> Text.literal("已启用玩家 " + targetPlayer.getName().getString() + " 的飞行"), true);
}
return Command.SINGLE_SUCCESS;
}))
);
});
// 注册摔落伤害事件,取消飞行玩家的摔落伤害
ServerLivingEntityEvents.ALLOW_DAMAGE.register((entity, damageSource, amount) -> {
if (entity instanceof ServerPlayerEntity player) {
if (flyingPlayers.contains(player.getUuid())) {
// 如果是摔落伤害,取消它
if (damageSource.isOf(DamageTypes.FALL)) {
return false; // 返回false取消伤害
}
}
}
return true; // 其他情况正常受到伤害
});
}
private static void enableFly(ServerPlayerEntity player) {
flyingPlayers.add(player.getUuid());
player.getAbilities().allowFlying = true;
player.getAbilities().flying = true;
player.sendAbilitiesUpdate();
}
private static void disableFly(ServerPlayerEntity player) {
flyingPlayers.remove(player.getUuid());
player.getAbilities().allowFlying = false;
player.getAbilities().flying = false;
player.sendAbilitiesUpdate();
}
// 玩家加入时恢复飞行状态
public static void restoreFlyState(ServerPlayerEntity player) {
if (flyingPlayers.contains(player.getUuid())) {
player.getAbilities().allowFlying = true;
player.getAbilities().flying = true;
player.sendAbilitiesUpdate();
}
}
}
@@ -0,0 +1,41 @@
package top.gtb520.java.mods.openfly;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.gtb520.java.mods.openfly.Commands.fly;
public class OpenFly implements ModInitializer {
public static final String MOD_ID = "openfly";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
LOGGER.info("-----------OpenFly-----------");
LOGGER.info("\n" +
" ___ ___ \n" +
" / _ \\ _ __ ___ _ _ / __| ___ _ _ _ _ __ ___ \n" +
" | (_) | '_ \\/ -_) ' \\\\__ \\/ _ \\ || | '_/ _/ -_)\n" +
" \\___/| .__/\\___|_||_|___/\\___/\\_,_|_| \\__\\___|\n" +
" |_| \n");;
LOGGER.info("OpenFly Mod 加载中...");
// 注册飞行命令和摔落伤害事件
fly.register();
// 玩家加入时恢复飞行状态
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
fly.restoreFlyState(handler.getPlayer());
});
LOGGER.info("OpenFly Mod 加载完成!");
LOGGER.info("-----------OpenFly-----------");
}
public static Identifier id(String path) {
return Identifier.of(MOD_ID, path);
}
}
@@ -0,0 +1,11 @@
package top.gtb520.java.mods.openfly;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
public class OpenFlyDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
}
}
@@ -0,0 +1,15 @@
package top.gtb520.java.mods.openfly.mixin;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MinecraftServer.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "loadWorld")
private void init(CallbackInfo info) {
// This code is injected into the start of MinecraftServer.loadWorld()V
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

+34
View File
@@ -0,0 +1,34 @@
{
"schemaVersion": 1,
"id": "openfly",
"version": "${version}",
"name": "OpenFly",
"description": "This is an example description! Tell everyone what your mod is about!",
"authors": [
"Me!"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://git.opensource-studio.info/database-mysql/OpenFly.git"
},
"license": "Apache-2.0",
"icon": "assets/openfly/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"top.gtb520.java.mods.openfly.OpenFly"
],
"fabric-datagen": [
"top.gtb520.java.mods.openfly.OpenFlyDataGenerator"
]
},
"mixins": [
"openfly.mixins.json"
],
"depends": {
"fabricloader": ">=0.19.5",
"minecraft": "~1.21.8",
"java": ">=21",
"fabric-api": "*"
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"required": true,
"package": "top.gtb520.java.mods.openfly.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"requireAnnotations": true
}
}