Skip to content

Commit

Permalink
重構一下
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 19, 2024
1 parent 0f49aed commit 01a66e4
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,17 +44,21 @@ 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 {
return false;
}
}

/**
* 自然更新魔力
* @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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -36,10 +32,6 @@ protected PlayerEntityMixin(EntityType<? extends LivingEntity> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/the_origin_of_magic.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01a66e4

Please sign in to comment.