From 01a66e4d814490929c6d7dd912fa582d108e8f50 Mon Sep 17 00:00:00 2001 From: ictye Date: Fri, 19 Apr 2024 21:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=A7=8B=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foundation/Items/Staff/StdStaff.java | 2 +- .../MagicAbilitiesManager.java | 10 +++++++--- .../foundation/mixin/{ => HUD}/PlayerHudMixin.java | 2 +- .../mixin/{ => PlayerEntity}/ClientPlayerMixin.java | 4 ++-- .../mixin/{ => PlayerEntity}/PlayerEntityMixin.java | 12 ++---------- .../mixin/{ => PlayerEntity}/SeriverEntityMixin.java | 8 ++++---- .../the_origin_of_magic/foundation/mixin/mixin.java | 4 ---- .../BlockLootTableGens.java} | 6 +++--- .../DefaultLangGens.java} | 7 ++++--- .../{Datagen => Datagens}/ModDataGenerator.java | 6 +++--- .../infrastructure/GUI/MagicLevelHud.java | 2 +- .../infrastructure/netWork/NetWorkReg.java | 8 +++++++- .../infrastructure/netWork/NetworkIDFinder.java | 5 +---- .../infrastructure/netWork/SyncHUDS2CPacket.java | 2 +- .../utils/PlayerEntityMixinInterfaces.java | 2 +- src/main/resources/the_origin_of_magic.mixins.json | 7 ++++--- 16 files changed, 42 insertions(+), 45 deletions(-) rename src/main/java/com/ictye/the_origin_of_magic/foundation/{player => PlayerAbilities}/MagicAbilitiesManager.java (86%) rename src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/{ => HUD}/PlayerHudMixin.java (94%) rename src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/{ => PlayerEntity}/ClientPlayerMixin.java (84%) rename src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/{ => PlayerEntity}/PlayerEntityMixin.java (75%) rename src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/{ => PlayerEntity}/SeriverEntityMixin.java (90%) delete mode 100644 src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/mixin.java rename src/main/java/com/ictye/the_origin_of_magic/infrastructure/{Datagen/BlockLootTable.java => Datagens/BlockLootTableGens.java} (64%) rename src/main/java/com/ictye/the_origin_of_magic/infrastructure/{Datagen/DefaultLang.java => Datagens/DefaultLangGens.java} (84%) rename src/main/java/com/ictye/the_origin_of_magic/infrastructure/{Datagen => Datagens}/ModDataGenerator.java (71%) diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Staff/StdStaff.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Staff/StdStaff.java index 84803b6..89a5be6 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Staff/StdStaff.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Staff/StdStaff.java @@ -3,7 +3,7 @@ import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters.StdMagicLimiter; import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic; import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; import com.ictye.the_origin_of_magic.utils.MagicInventory; import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/player/MagicAbilitiesManager.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/PlayerAbilities/MagicAbilitiesManager.java similarity index 86% rename from src/main/java/com/ictye/the_origin_of_magic/foundation/player/MagicAbilitiesManager.java rename to src/main/java/com/ictye/the_origin_of_magic/foundation/PlayerAbilities/MagicAbilitiesManager.java index 3e9171e..31703e4 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/player/MagicAbilitiesManager.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/PlayerAbilities/MagicAbilitiesManager.java @@ -1,4 +1,4 @@ -package com.ictye.the_origin_of_magic.foundation.player; +package com.ictye.the_origin_of_magic.foundation.PlayerAbilities; import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic; import com.ictye.the_origin_of_magic.infrastructure.netWork.NetworkIDFinder; @@ -44,7 +44,7 @@ public boolean cast(PlayerEntity player, StdThrownMagic magic , World world){ if(player instanceof ServerPlayerEntity serverPlayerEntity){ PacketByteBuf buffer = PacketByteBufs.create(); buffer.writeFloat(magicLevel); - ServerPlayNetworking.send(serverPlayerEntity, NetworkIDFinder.SYNC_HUD_ID, buffer); + ServerPlayNetworking.send(serverPlayerEntity, NetworkIDFinder.SYNC_MAGIC_HUD_ID, buffer); } return world.spawnEntity(magic); }else { @@ -52,9 +52,13 @@ public boolean cast(PlayerEntity player, StdThrownMagic magic , World world){ } } + /** + * 自然更新魔力 + * @param player 玩家 + */ public void update(PlayerEntity player){ magicTickTimmer++; - if (!player.getHungerManager().isNotFull() && player.world.getGameRules().getBoolean(GameRules.NATURAL_REGENERATION) && magicLevel < 20&& magicTickTimmer > 10){ + if (!(player.getHungerManager().getFoodLevel() < 10) && player.world.getGameRules().getBoolean(GameRules.NATURAL_REGENERATION) && magicLevel < 20&& magicTickTimmer > 10){ magicLevel += 0.5; magicTickTimmer = 0; } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerHudMixin.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/HUD/PlayerHudMixin.java similarity index 94% rename from src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerHudMixin.java rename to src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/HUD/PlayerHudMixin.java index 80a1a3a..3195fde 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerHudMixin.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/HUD/PlayerHudMixin.java @@ -1,4 +1,4 @@ -package com.ictye.the_origin_of_magic.foundation.mixin; +package com.ictye.the_origin_of_magic.foundation.mixin.HUD; import com.ictye.the_origin_of_magic.infrastructure.GUI.MagicLevelHud; import net.minecraft.client.MinecraftClient; diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/ClientPlayerMixin.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/ClientPlayerMixin.java similarity index 84% rename from src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/ClientPlayerMixin.java rename to src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/ClientPlayerMixin.java index 68c509e..c1b6bcf 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/ClientPlayerMixin.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/ClientPlayerMixin.java @@ -1,6 +1,6 @@ -package com.ictye.the_origin_of_magic.foundation.mixin; +package com.ictye.the_origin_of_magic.foundation.mixin.PlayerEntity; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; import com.mojang.authlib.GameProfile; import net.minecraft.client.network.ClientPlayerEntity; diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntityMixin.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/PlayerEntityMixin.java similarity index 75% rename from src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntityMixin.java rename to src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/PlayerEntityMixin.java index 337257e..da54a1e 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/PlayerEntityMixin.java @@ -1,16 +1,12 @@ -package com.ictye.the_origin_of_magic.foundation.mixin; +package com.ictye.the_origin_of_magic.foundation.mixin.PlayerEntity; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; -import com.ictye.the_origin_of_magic.infrastructure.netWork.NetworkIDFinder; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -36,10 +32,6 @@ protected PlayerEntityMixin(EntityType entityType, World @SuppressWarnings("ConstantValue") public void tick(CallbackInfo ci){ if((Object)this instanceof ServerPlayerEntity player){ - PacketByteBuf buffer = PacketByteBufs.create(); - buffer.writeFloat(this.magicAbilitiesManager.getMagicLevel()); - ServerPlayNetworking.send(player, NetworkIDFinder.SYNC_HUD_ID, buffer); - this.magicAbilitiesManager.update(player); } } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/SeriverEntityMixin.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/SeriverEntityMixin.java similarity index 90% rename from src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/SeriverEntityMixin.java rename to src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/SeriverEntityMixin.java index e29db30..a548bca 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/SeriverEntityMixin.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntity/SeriverEntityMixin.java @@ -1,6 +1,6 @@ -package com.ictye.the_origin_of_magic.foundation.mixin; +package com.ictye.the_origin_of_magic.foundation.mixin.PlayerEntity; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; import com.ictye.the_origin_of_magic.infrastructure.netWork.NetworkIDFinder; import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; import com.mojang.authlib.GameProfile; @@ -30,10 +30,10 @@ public SeriverEntityMixin(World world, BlockPos pos, float yaw, GameProfile game public void playerTick(CallbackInfo ci) { // ServerPlayerEntity ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) (Object) this; - PacketByteBuf buffer = PacketByteBufs.create(); buffer.writeFloat(this.magicAbilitiesManager.getMagicLevel()); - ServerPlayNetworking.send(serverPlayerEntity, NetworkIDFinder.SYNC_HUD_ID, buffer); + ServerPlayNetworking.send(serverPlayerEntity, NetworkIDFinder.SYNC_MAGIC_HUD_ID, buffer); + } } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/mixin.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/mixin.java deleted file mode 100644 index db54092..0000000 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/mixin.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.ictye.the_origin_of_magic.foundation.mixin; - -public class mixin { -} diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/BlockLootTable.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/BlockLootTableGens.java similarity index 64% rename from src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/BlockLootTable.java rename to src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/BlockLootTableGens.java index 2def680..7a2ae6f 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/BlockLootTable.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/BlockLootTableGens.java @@ -1,12 +1,12 @@ -package com.ictye.the_origin_of_magic.infrastructure.Datagen; +package com.ictye.the_origin_of_magic.infrastructure.Datagens; import com.ictye.the_origin_of_magic.Contents.AllBlock; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; -public class BlockLootTable extends FabricBlockLootTableProvider { +public class BlockLootTableGens extends FabricBlockLootTableProvider { - public BlockLootTable(FabricDataGenerator dataGenerator) { + public BlockLootTableGens(FabricDataGenerator dataGenerator) { super(dataGenerator); } diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/DefaultLang.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/DefaultLangGens.java similarity index 84% rename from src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/DefaultLang.java rename to src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/DefaultLangGens.java index 019ae6d..71ce577 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/DefaultLang.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/DefaultLangGens.java @@ -1,13 +1,14 @@ -package com.ictye.the_origin_of_magic.infrastructure.Datagen; +package com.ictye.the_origin_of_magic.infrastructure.Datagens; import com.ictye.the_origin_of_magic.Contents.AllItem; import com.ictye.the_origin_of_magic.the_origin_of_magic; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; + import java.nio.file.Path; -public class DefaultLang extends FabricLanguageProvider { - protected DefaultLang(FabricDataGenerator dataGenerator) { +public class DefaultLangGens extends FabricLanguageProvider { + protected DefaultLangGens(FabricDataGenerator dataGenerator) { super(dataGenerator, "en_us"); } diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/ModDataGenerator.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/ModDataGenerator.java similarity index 71% rename from src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/ModDataGenerator.java rename to src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/ModDataGenerator.java index 3af357e..5565d98 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagen/ModDataGenerator.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/Datagens/ModDataGenerator.java @@ -1,4 +1,4 @@ -package com.ictye.the_origin_of_magic.infrastructure.Datagen; +package com.ictye.the_origin_of_magic.infrastructure.Datagens; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; @@ -9,8 +9,8 @@ public class ModDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { - fabricDataGenerator.addProvider(DefaultLang::new); - fabricDataGenerator.addProvider(BlockLootTable::new); + fabricDataGenerator.addProvider(DefaultLangGens::new); + fabricDataGenerator.addProvider(BlockLootTableGens::new); try { fabricDataGenerator.run(); diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/GUI/MagicLevelHud.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/GUI/MagicLevelHud.java index 2685107..b73f439 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/GUI/MagicLevelHud.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/GUI/MagicLevelHud.java @@ -1,6 +1,6 @@ package com.ictye.the_origin_of_magic.infrastructure.GUI; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.api.EnvType; diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetWorkReg.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetWorkReg.java index 479ba40..7ed6142 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetWorkReg.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetWorkReg.java @@ -3,10 +3,16 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; public class NetWorkReg { + /** + * Register all packets to be sent from the client to the server. + */ public static void registerC2SPackets() { } + /** + * Register all packets to be sent from the server to the client. + */ public static void registerS2CPackets() { - ClientPlayNetworking.registerGlobalReceiver(NetworkIDFinder.SYNC_HUD_ID, SyncHUDS2CPacket::receive); + ClientPlayNetworking.registerGlobalReceiver(NetworkIDFinder.SYNC_MAGIC_HUD_ID, SyncHUDS2CPacket::receive); } } diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetworkIDFinder.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetworkIDFinder.java index 0c2c0a9..e431540 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetworkIDFinder.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/NetworkIDFinder.java @@ -4,8 +4,5 @@ import net.minecraft.util.Identifier; public class NetworkIDFinder { - public static final Identifier DRINK_WATER_ID = new Identifier(the_origin_of_magic.Mod_Id, "drink_water"); - public static final Identifier SWING_HAND_ID = new Identifier(the_origin_of_magic.Mod_Id, "swing_hand"); - public static final Identifier SYNC_THIRST_ID = new Identifier(the_origin_of_magic.Mod_Id, "sync_thirst"); - public static final Identifier SYNC_HUD_ID = new Identifier(the_origin_of_magic.Mod_Id, "sync_hud"); + public static final Identifier SYNC_MAGIC_HUD_ID = new Identifier(the_origin_of_magic.Mod_Id, "sync_hud"); } diff --git a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/SyncHUDS2CPacket.java b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/SyncHUDS2CPacket.java index 2626a25..aab478a 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/SyncHUDS2CPacket.java +++ b/src/main/java/com/ictye/the_origin_of_magic/infrastructure/netWork/SyncHUDS2CPacket.java @@ -1,6 +1,6 @@ package com.ictye.the_origin_of_magic.infrastructure.netWork; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.MinecraftClient; diff --git a/src/main/java/com/ictye/the_origin_of_magic/utils/PlayerEntityMixinInterfaces.java b/src/main/java/com/ictye/the_origin_of_magic/utils/PlayerEntityMixinInterfaces.java index 3453659..8f67cc1 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/utils/PlayerEntityMixinInterfaces.java +++ b/src/main/java/com/ictye/the_origin_of_magic/utils/PlayerEntityMixinInterfaces.java @@ -1,6 +1,6 @@ package com.ictye.the_origin_of_magic.utils; -import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; +import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager; public interface PlayerEntityMixinInterfaces { public MagicAbilitiesManager the_origin_of_magic$getMagicAbilitiesManager(); diff --git a/src/main/resources/the_origin_of_magic.mixins.json b/src/main/resources/the_origin_of_magic.mixins.json index 2f85445..0f9dddd 100644 --- a/src/main/resources/the_origin_of_magic.mixins.json +++ b/src/main/resources/the_origin_of_magic.mixins.json @@ -4,11 +4,12 @@ "package": "com.ictye.the_origin_of_magic.foundation.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "PlayerEntityMixin" + "PlayerEntity.PlayerEntityMixin", + "PlayerEntity.SeriverEntityMixin" ], "client": [ - "ClientPlayerMixin", - "PlayerHudMixin" + "HUD.PlayerHudMixin", + "PlayerEntity.ClientPlayerMixin" ], "injectors": { "defaultRequire": 1