-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 添加魔法能力管理系统,实现魔法实体生成与消耗,优化玩家交互体验。
- Loading branch information
1 parent
ffb2ab9
commit 6d1cf61
Showing
14 changed files
with
239 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,4 +118,4 @@ loom { | |
} | ||
} | ||
} | ||
assemble.dependsOn runDatagen | ||
assemble.dependsOn runDatagen |
2 changes: 1 addition & 1 deletion
2
src/main/generated/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.19.2 2024-04-17T20:37:27.0952932 Language | ||
// 1.19.2 2024-04-19T10:01:41.7140308 Language | ||
84f246a88b9c3dc4c5d0c98a56c4de5529eabe74 assets\the_origin_of_magic\lang\en_us.json |
2 changes: 1 addition & 1 deletion
2
src/main/generated/.cache/dc1d6e7286e7569a79007c10f809d49635ea1c49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.19.2 2024-04-17T20:37:27.0967981 Block Loot Tables | ||
// 1.19.2 2024-04-19T10:01:41.7110246 Block Loot Tables | ||
fe57f13449a11436bbede8c37e01bd0d1cd87191 data\the_origin_of_magic\loot_tables\blocks\magic_workbench.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.ictye.the_origin_of_magic.foundation.mixin; | ||
|
||
|
||
import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; | ||
import com.ictye.the_origin_of_magic.utils.PlayerEntityMixinInterfaces; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(PlayerEntity.class) | ||
public abstract class PlayerEntityMixin implements PlayerEntityMixinInterfaces { | ||
|
||
@Unique | ||
protected MagicAbilitiesManager magicAbilitiesManager = new MagicAbilitiesManager(); | ||
|
||
|
||
public MagicAbilitiesManager the_origin_of_magic$getMagicAbilitiesManager() { | ||
return this.magicAbilitiesManager; | ||
} | ||
|
||
@Inject(method = "tick",at = @At("HEAD")) | ||
@SuppressWarnings("ConstantValue") | ||
public void tick(CallbackInfo ci){ | ||
if((Object)this instanceof ServerPlayerEntity player){ | ||
this.magicAbilitiesManager.update(player); | ||
} | ||
} | ||
|
||
@Inject(method = "writeCustomDataToNbt",at = @At("HEAD")) | ||
public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci){ | ||
magicAbilitiesManager.writeNbt(nbt); | ||
} | ||
|
||
@Inject(method = "readCustomDataFromNbt",at = @At("HEAD")) | ||
public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci){ | ||
magicAbilitiesManager.readNbt(nbt); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/PlayerHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ictye.the_origin_of_magic.foundation.mixin; | ||
|
||
import com.ictye.the_origin_of_magic.infrastructure.GUI.MagicLevelHud; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawableHelper; | ||
import net.minecraft.client.gui.hud.InGameHud; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(InGameHud.class) | ||
public abstract class PlayerHudMixin extends DrawableHelper{ | ||
|
||
|
||
|
||
@Shadow @Final private MinecraftClient client; | ||
|
||
@Shadow protected abstract PlayerEntity getCameraPlayer(); | ||
|
||
@Shadow private int ticks; | ||
|
||
@Inject(method = "renderStatusBars", at = @At(value = "HEAD")) | ||
private void renderStatusBars(MatrixStack matrices, CallbackInfo ci){ | ||
MagicLevelHud.renderThirstHud(matrices, client, this.getCameraPlayer(), ticks); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/ictye/the_origin_of_magic/foundation/mixin/mixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.ictye.the_origin_of_magic.foundation.mixin; | ||
|
||
public class mixin { | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/ictye/the_origin_of_magic/foundation/player/MagicAbilitiesManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.ictye.the_origin_of_magic.foundation.player; | ||
|
||
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.world.GameRules; | ||
import net.minecraft.world.World; | ||
|
||
public class MagicAbilitiesManager { | ||
private float magicLevel = 20; | ||
|
||
private int magicRate = 1; | ||
|
||
private int magicTickTimmer = 0; | ||
|
||
public float getMagicLevel() { | ||
return magicLevel; | ||
} | ||
|
||
/** | ||
* 生成魔法實體 | ||
* @param player 玩家 | ||
* @param magic 魔法 | ||
* @param world 世界 | ||
* @return 是否成功 | ||
*/ | ||
public boolean cast(PlayerEntity player, StdThrownMagic magic , World world){ | ||
float neededMagic = magic.getMagicRate() * magicRate; | ||
if(player.isCreative()){ | ||
return world.spawnEntity(magic); | ||
} | ||
if(magicLevel>neededMagic){ | ||
magicLevel -= neededMagic; | ||
return world.spawnEntity(magic); | ||
}else { | ||
return false; | ||
} | ||
} | ||
|
||
public void update(PlayerEntity player){ | ||
magicTickTimmer++; | ||
if (!player.getHungerManager().isNotFull() && player.world.getGameRules().getBoolean(GameRules.NATURAL_REGENERATION) && magicLevel < 20&& magicTickTimmer > 10){ | ||
magicLevel += 0.5; | ||
magicTickTimmer = 0; | ||
} | ||
} | ||
|
||
public void writeNbt(NbtCompound nbt){ | ||
nbt.putInt("magicRate", magicRate); | ||
nbt.putInt("magicTickTimmer", magicTickTimmer); | ||
nbt.putFloat("magicLevel", magicLevel); | ||
} | ||
|
||
public void readNbt(NbtCompound nbt){ | ||
if(nbt.contains("magicLevel", NbtElement.FLOAT_TYPE)){ | ||
magicRate = nbt.getInt("magicRate"); | ||
magicTickTimmer = nbt.getInt("magicTickTimmer"); | ||
magicLevel = nbt.getFloat("magicLevel"); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/ictye/the_origin_of_magic/infrastructure/GUI/MagicLevelHud.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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.utils.PlayerEntityMixinInterfaces; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawableHelper; | ||
import net.minecraft.client.render.GameRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class MagicLevelHud { | ||
|
||
private static final Identifier magicTexture = new Identifier("the_origin_of_magic", "textures/gui/magic_power_image.png"); | ||
public static void renderThirstHud(MatrixStack matrixStack, MinecraftClient client, PlayerEntity playerEntity, int ticks) { | ||
if (playerEntity != null && !playerEntity.isCreative() && !playerEntity.isSpectator()) { | ||
int width = client.getWindow().getScaledWidth() / 2; | ||
int height = client.getWindow().getScaledHeight(); | ||
int bounceFactor = 0; | ||
|
||
// Defining the texture | ||
RenderSystem.setShader(GameRenderer::getPositionTexShader); | ||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); | ||
RenderSystem.setShaderTexture(0, magicTexture); | ||
|
||
MagicAbilitiesManager magicAbilitiesManager = ((PlayerEntityMixinInterfaces)playerEntity).the_origin_of_magic$getMagicAbilitiesManager(); | ||
|
||
float magicLevel = magicAbilitiesManager.getMagicLevel(); | ||
|
||
// 繪製空圖標 | ||
for(int i = 0; i<10; i++){ | ||
DrawableHelper.drawTexture(matrixStack | ||
, width + 82 - (i * 9) + i, (height - 49 + bounceFactor) - 1 | ||
, 9, 0 | ||
, 9, 9 | ||
, 27, 9); | ||
} | ||
|
||
// 繪製半個魔力 | ||
|
||
for (int i = 0; i < 20; i++) { | ||
if(magicLevel!=0){ | ||
if (((magicLevel + 1) / 2) > i){ | ||
DrawableHelper.drawTexture( | ||
matrixStack, | ||
width + 82 - (i * 9) + i , (height - 49) - 1, | ||
18, 0, | ||
9, 9, | ||
27, 9); | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < 20; i++) { | ||
if(magicLevel!=0){ | ||
if ((magicLevel / 2) > i){ | ||
DrawableHelper.drawTexture( | ||
matrixStack, | ||
width + 82 - (i * 9) + i , (height - 49) - 1, | ||
0, 0, | ||
9, 9, | ||
27, 9); | ||
} | ||
} | ||
} | ||
|
||
RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/com/ictye/the_origin_of_magic/utils/PlayerEntityMixinInterfaces.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.ictye.the_origin_of_magic.utils; | ||
|
||
import com.ictye.the_origin_of_magic.foundation.player.MagicAbilitiesManager; | ||
|
||
public interface PlayerEntityMixinInterfaces { | ||
MagicAbilitiesManager the_origin_of_magic$getMagicAbilitiesManager(); | ||
} |
Binary file added
BIN
+395 Bytes
src/main/resources/assets/the_origin_of_magic/textures/gui/magic_power_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters