From e5ea759554d09f5fcb2bdd4914032d7b3f572014 Mon Sep 17 00:00:00 2001 From: ictye Date: Wed, 24 Apr 2024 22:37:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=9A=A8=E6=A9=9F?= =?UTF-8?q?=E7=99=BC=E7=94=9F=E5=99=A8=E7=9A=84=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../89b86ab0e66f527166d98df92ddbcf5416ed58f6 | 2 +- .../dc1d6e7286e7569a79007c10f809d49635ea1c49 | 2 +- .../f3798f81c7b6fecad2cbfec741314f8a66c0eca3 | 2 +- .../Entitys/Magics/ExplosionThrownMagic.java | 2 +- .../Entitys/Magics/MagicBullet.java | 6 ++- .../Entitys/Magics/StdThrownMagic.java | 2 +- .../foundation/Items/Staff/StdStaff.java | 53 ++++++++++--------- .../utils/Math/PRDRandom.java | 37 ++++++++++++- 8 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/main/generated/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6 b/src/main/generated/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6 index f645564..36c51f6 100644 --- a/src/main/generated/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6 +++ b/src/main/generated/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6 @@ -1,2 +1,2 @@ -// 1.19.2 2024-04-24T19:58:32.1577533 Language +// 1.19.2 2024-04-24T22:30:25.1810272 Language b6d01a692d2bbaa358f7d24d26a0c53dc9f1c2ea assets\the_origin_of_magic\lang\en_us.json diff --git a/src/main/generated/.cache/dc1d6e7286e7569a79007c10f809d49635ea1c49 b/src/main/generated/.cache/dc1d6e7286e7569a79007c10f809d49635ea1c49 index a04a7be..da39750 100644 --- a/src/main/generated/.cache/dc1d6e7286e7569a79007c10f809d49635ea1c49 +++ b/src/main/generated/.cache/dc1d6e7286e7569a79007c10f809d49635ea1c49 @@ -1,2 +1,2 @@ -// 1.19.2 2024-04-24T19:58:32.156254 Block Loot Tables +// 1.19.2 2024-04-24T22:30:25.1738852 Block Loot Tables fe57f13449a11436bbede8c37e01bd0d1cd87191 data\the_origin_of_magic\loot_tables\blocks\magic_workbench.json diff --git a/src/main/generated/.cache/f3798f81c7b6fecad2cbfec741314f8a66c0eca3 b/src/main/generated/.cache/f3798f81c7b6fecad2cbfec741314f8a66c0eca3 index 1b26116..c3acca0 100644 --- a/src/main/generated/.cache/f3798f81c7b6fecad2cbfec741314f8a66c0eca3 +++ b/src/main/generated/.cache/f3798f81c7b6fecad2cbfec741314f8a66c0eca3 @@ -1,4 +1,4 @@ -// 1.19.2 2024-04-24T19:58:32.1542548 Models +// 1.19.2 2024-04-24T22:30:25.1652519 Models 02d3ff4716d16f7c5a4dd4432d1b98f744a13f02 assets\the_origin_of_magic\models\item\blood_essence.json 105ea751d9d55fefa41f158e8e462c2e69f451ed assets\the_origin_of_magic\models\item\magic_life_time_up.json 781092579f171cf0db8317aa6267ad8e5cfbbd1f assets\the_origin_of_magic\models\item\fire_magic_element.json diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/ExplosionThrownMagic.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/ExplosionThrownMagic.java index 3a9a22f..2a75623 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/ExplosionThrownMagic.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/ExplosionThrownMagic.java @@ -50,7 +50,7 @@ protected void collision(HitResult hitResult) { public void remove(RemovalReason reason) { Vec3d pos = this.getPos(); if(reason != RemovalReason.KILLED){ - if(prdRandom.getBool()){ + if(prdRandom!=null && prdRandom.getBool()){ this.world.createExplosion(this, pos.getX(), pos.getY(), pos.getZ(), 5.0F * explosionRate, Explosion.DestructionType.BREAK); }else { this.world.createExplosion(this, pos.getX(), pos.getY(), pos.getZ(), 3.0F * explosionRate, Explosion.DestructionType.BREAK); diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/MagicBullet.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/MagicBullet.java index 55d8d43..d79f7ee 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/MagicBullet.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/MagicBullet.java @@ -43,7 +43,11 @@ public void tick() { @Override protected void onEntityHit(EntityHitResult entityHitResult) { - entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 4); + if(prdRandom!=null && prdRandom.getBool()){ + entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 7); + }else { + entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 4); + } super.onEntityHit(entityHitResult); } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/StdThrownMagic.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/StdThrownMagic.java index c6c2e40..e6d6058 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/StdThrownMagic.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/StdThrownMagic.java @@ -330,7 +330,7 @@ public MagicSetting explosionRate (float a){ } public MagicSetting random(PRDRandom random){ - prdRandom = random.copy(); + prdRandom = random; return this; } } 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 d189188..8b40950 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 @@ -131,6 +131,8 @@ public abstract class StdStaff extends Item { */ float Crate; + PRDRandom random; + public StdStaff(Settings settings) { super(settings); // 初始化各個參數 @@ -151,6 +153,7 @@ public StdStaff(Settings settings) { this.enchantability = 3; this.staffAgeRate = 1; this.Crate = 0.15f; + this.random = new PRDRandom(Crate); } @Override @@ -260,14 +263,9 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han user.getItemCooldownManager().set(this, getCoolingTime()); } - PRDRandom random; + ItemStack staffItemStack = user.getStackInHand(hand); NbtCompound nbt = staffItemStack.getNbt(); - if(nbt != null && nbt.contains("PRDRandom", NbtElement.COMPOUND_TYPE)){ - random = new PRDRandom(nbt); - } else { - random = new PRDRandom(Crate); - } MagicInventory Magics = this.getInventoryFromNbt(nbt); if (Magics.isEmpty()){ @@ -277,28 +275,33 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han return TypedActionResult.fail(user.getStackInHand(hand)); } }else { - if (!world.isClient) { - // 施放解析邏輯 - int count = getCastingNum(); // 可釋放的數量 - List magicList = summonMagic(Magics,user,world,count,random); - // 生成法術實體 - for(StdThrownMagic MagicEntity:magicList){ - - float finalSpeed = getSpeed(); // 計算最終速度 - float finalScattering = getScattering(); // 計算最終散射 - - MagicEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, finalSpeed, finalScattering); // 設置參數 - MagicAbilitiesManager magicAbilitiesManager = ((PlayerEntityMixinInterfaces)user).the_origin_of_magic$getMagicAbilitiesManager(); - MagicEntity.setAgeRate(this.staffAgeRate); - - if (magicAbilitiesManager.cast(user, MagicEntity, world)) { - // 生成法術實體并且破壞物品 - staffItemStack.damage(2, user, e -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); - } + float p = random.getP(); + random.setCallBack((a)->{ + if (staffItemStack.getNbt() != null) { + staffItemStack.setNbt(a.writeNbt(staffItemStack.getNbt())); + } + return 0f; + }); + // 施放解析邏輯 + int count = getCastingNum(); // 可釋放的數量 + List magicList = summonMagic(Magics,user,world,count,random); + // 生成法術實體 + for(StdThrownMagic MagicEntity:magicList){ + + float finalSpeed = getSpeed(); // 計算最終速度 + float finalScattering = getScattering(); // 計算最終散射 + + MagicEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, finalSpeed, finalScattering); // 設置參數 + MagicAbilitiesManager magicAbilitiesManager = ((PlayerEntityMixinInterfaces)user).the_origin_of_magic$getMagicAbilitiesManager(); + MagicEntity.setAgeRate(this.staffAgeRate); + + if (magicAbilitiesManager.cast(user, MagicEntity, world)) { + // 生成法術實體并且破壞物品 + random.setP(p); + staffItemStack.damage(2, user, e -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); } } } - random.writeNbt(staffItemStack.getNbt()); return TypedActionResult.success(user.getStackInHand(hand)); } diff --git a/src/main/java/com/ictye/the_origin_of_magic/utils/Math/PRDRandom.java b/src/main/java/com/ictye/the_origin_of_magic/utils/Math/PRDRandom.java index 055aa88..b595a99 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/utils/Math/PRDRandom.java +++ b/src/main/java/com/ictye/the_origin_of_magic/utils/Math/PRDRandom.java @@ -1,10 +1,12 @@ package com.ictye.the_origin_of_magic.utils.Math; +import com.ictye.the_origin_of_magic.the_origin_of_magic; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; /** * PRD偽隨機事件發生器 @@ -12,7 +14,13 @@ public class PRDRandom { private int count = 1; private float P = 0; + private PRDRandom father; private static final Map PRD_CMap = new HashMap<>(); + private Function CallBack = (P) -> { + return null; + }; + + private float p; /** * 構造PRD僞隨機事件發生器 @@ -20,20 +28,29 @@ public class PRDRandom { */ public PRDRandom(float P) { setP(P); + this.p=P; } public PRDRandom copy(){ - return new PRDRandom(this.toNBT()); + return new PRDRandom(this.toNBT(),this); + } + + private PRDRandom(NbtCompound nbt,PRDRandom father){ + this(nbt); + this.father = father; + this.p = father.getP(); } public PRDRandom(NbtCompound nbt){ if(nbt.contains("PRDRandom", NbtElement.COMPOUND_TYPE)){ NbtCompound PRD_Nbt = nbt.getCompound("PRDRandom"); setP(PRD_Nbt.getFloat("P")); + this.p = PRD_Nbt.getFloat("P"); setCount(PRD_Nbt.getInt("count")); }else{ if (nbt.contains("P", NbtElement.FLOAT_TYPE)){ setP(nbt.getFloat("P")); + this.p = nbt.getFloat("P"); } if (nbt.contains("count", NbtElement.INT_TYPE)){ setCount(nbt.getInt("count")); @@ -70,7 +87,6 @@ public void resetCount(){ * @param P 概率 */ public void setP(float P) { - resetCount(); float fP = Math.min(1,P); fP = Math.max(0,fP); fP = (float) (Math.ceil(fP * 100) / 100); @@ -86,14 +102,31 @@ public boolean getBool(){ count = Math.max(0,count); float c = PRD_CMap.get(getP()); if (random < count * c){ + the_origin_of_magic.LOGGER.info("PRD true"); resetCount(); + syncToFather(); return true; }else{ count++; + syncToFather(); return false; } } + private void onCountChange(){ + CallBack.apply(this); + } + + public void setCallBack(Function callBack) { + CallBack = callBack; + } + + private void syncToFather(){ + if (father != null){ + father.setCount(count); + } + } + public static void init(){ // 這段是自動生產的參數,實際在代碼裏面計算非常耗費性能!!!,就像你不應該動態生產PI常量一樣 PRD_CMap.put(0.0f,0.0f);