From 6e23b9ca055301c0faeff69325be74196d196230 Mon Sep 17 00:00:00 2001 From: ictye Date: Wed, 17 Apr 2024 12:57:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=AD=94=E6=B3=95=E9=87=8B=E6=94=BE?= =?UTF-8?q?=E7=B3=BB=E7=B5=B1=E5=92=8CStdMagic=E5=8F=8A=E5=85=B6=E5=AF=A6?= =?UTF-8?q?=E9=AB=94):=20=E4=BF=AE=E6=94=B9=E4=BA=86=E9=AD=94=E6=B3=95?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=B1=BB=E5=92=8C=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=99=90=E5=88=B6=E5=99=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=92=8C=E5=AE=9E=E4=BD=93=E6=95=88=E6=9E=9C=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=99=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ictye/the_origin_of_magic/Contents/AllBlock.java | 1 + .../ictye/the_origin_of_magic/Contents/AllItem.java | 1 - ...linEntityLimiter.java => HostileEntityLimiter.java} | 8 ++++++-- .../Entitys/Magics/Limiters/StdMagicLimiter.java | 3 ++- .../foundation/Entitys/Magics/StdThrownMagic.java | 2 ++ .../foundation/Entitys/Magics/TestThrownMagic.java | 3 +++ .../Items/Magic/LimiterItem/StdLimiterItem.java | 7 ------- .../Magic/LimiterItem/UndeadEntityLimiterItem.java | 10 +++++++--- 8 files changed, 21 insertions(+), 14 deletions(-) rename src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/{HoglinEntityLimiter.java => HostileEntityLimiter.java} (67%) diff --git a/src/main/java/com/ictye/the_origin_of_magic/Contents/AllBlock.java b/src/main/java/com/ictye/the_origin_of_magic/Contents/AllBlock.java index 1e547ab..9ce0412 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/Contents/AllBlock.java +++ b/src/main/java/com/ictye/the_origin_of_magic/Contents/AllBlock.java @@ -17,6 +17,7 @@ public class AllBlock { public static final HashMap BlockItems = new HashMap<>(); public static Block MAGIC_WORKSTATION = new MagicWorkstation(FabricBlockSettings.of(Material.STONE).strength(50.0f, 1200.0f).luminance(state -> 10)); + @SuppressWarnings("SameParameterValue") private static void registerBlock(String name, Block block){ Registry.register(Registry.BLOCK,new Identifier(the_origin_of_magic.Mod_Id, name),block); BlockItems.put(name,new BlockItem(block,new FabricItemSettings().group(AllItem.TheOriginOfMagicItemGroup))); diff --git a/src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java b/src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java index 3118e7a..940bb70 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java +++ b/src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java @@ -1,6 +1,5 @@ package com.ictye.the_origin_of_magic.Contents; -import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters.HoglinEntityLimiter; import com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem.UndeadEntityLimiterItem; import com.ictye.the_origin_of_magic.foundation.Items.Magic.TestMagicEntityItem; import com.ictye.the_origin_of_magic.foundation.Items.Staff.DeadwoodStaff; diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/HoglinEntityLimiter.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/HostileEntityLimiter.java similarity index 67% rename from src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/HoglinEntityLimiter.java rename to src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/HostileEntityLimiter.java index 5de0e5d..55b7b00 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/HoglinEntityLimiter.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/HostileEntityLimiter.java @@ -1,15 +1,19 @@ package com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters; import net.minecraft.entity.mob.HoglinEntity; +import net.minecraft.entity.mob.ZombieEntity; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; import org.jetbrains.annotations.Nullable; -public class HoglinEntityLimiter extends StdMagicLimiter { +public class HostileEntityLimiter extends StdMagicLimiter { @Override public boolean canEffect(@Nullable EntityHitResult entityHitResult, @Nullable HitResult hitResult, @Nullable BlockHitResult blockHitResult) { // 判斷是否為亡靈生物 - return super.canEffect(entityHitResult, hitResult, blockHitResult) && entityHitResult.getEntity() != null && entityHitResult.getEntity() instanceof HoglinEntity; + if (entityHitResult != null) { + return entityHitResult.getEntity() instanceof ZombieEntity; + } + return false; } } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/StdMagicLimiter.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/StdMagicLimiter.java index e1ed27f..7563651 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/StdMagicLimiter.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/Limiters/StdMagicLimiter.java @@ -1,12 +1,13 @@ package com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters; +import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagicInterface; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; import org.jetbrains.annotations.Nullable; //限制魔法,給魔法添加效果,限制魔法結果 -public class StdMagicLimiter { +public class StdMagicLimiter implements StdMagicInterface { public void onHit( @Nullable EntityHitResult entityHitResult, @Nullable HitResult hitResult, @Nullable BlockHitResult blockHitResult){ } 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 feee784..a93e1a3 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 @@ -77,10 +77,12 @@ protected void onCollision(HitResult hitResult) { HitResult.Type type = hitResult.getType(); if (type == HitResult.Type.ENTITY) { if (hitResult instanceof EntityHitResult && !(limiter.canEffect((EntityHitResult) hitResult, hitResult, null))) { + this.remove(RemovalReason.CHANGED_DIMENSION); return; } } else if (type == HitResult.Type.BLOCK) { if (hitResult instanceof BlockHitResult && !(limiter.canEffect(null, hitResult, (BlockHitResult) hitResult))) { + this.remove(RemovalReason.CHANGED_DIMENSION); return; } } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/TestThrownMagic.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/TestThrownMagic.java index 4d2b1c9..289043c 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/TestThrownMagic.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Entitys/Magics/TestThrownMagic.java @@ -41,6 +41,9 @@ protected void collision(HitResult hitResult) { /* * 撞擊后爆炸~ * */ + if (this.world.isClient){ + return; + } BlockPos pos = new BlockPos(hitResult.getPos()); this.world.createExplosion(this, pos.getX(), pos.getY(), pos.getZ(), 5.0F * exolisionRate, Explosion.DestructionType.BREAK); this.remove(RemovalReason.CHANGED_DIMENSION); diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/StdLimiterItem.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/StdLimiterItem.java index f3fd21c..b613814 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/StdLimiterItem.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/StdLimiterItem.java @@ -11,11 +11,4 @@ public abstract class StdLimiterItem extends StdMagicItem { public StdLimiterItem(Settings settings, EntityType entityType) { super(settings, entityType); } - - @Override - public StdThrownMagic getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate) { - return null; - } - - public abstract StdMagicLimiter getMagic(); } diff --git a/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/UndeadEntityLimiterItem.java b/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/UndeadEntityLimiterItem.java index 06a747f..09bd023 100644 --- a/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/UndeadEntityLimiterItem.java +++ b/src/main/java/com/ictye/the_origin_of_magic/foundation/Items/Magic/LimiterItem/UndeadEntityLimiterItem.java @@ -1,17 +1,21 @@ package com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem; -import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters.HoglinEntityLimiter; +import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters.HostileEntityLimiter; import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters.StdMagicLimiter; +import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagicInterface; import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic; import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.World; public class UndeadEntityLimiterItem extends StdLimiterItem{ public UndeadEntityLimiterItem(Settings settings, EntityType entityType) { super(settings, entityType); } + @Override - public StdMagicLimiter getMagic() { - return new HoglinEntityLimiter(); + public StdMagicInterface getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate) { + return new HostileEntityLimiter(); } }