Skip to content

Commit

Permalink
fix(魔法釋放系統和StdMagic及其實體): 修改了魔法相关类和方法,添加了限制器接口和实体效果限制器。
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 17, 2024
1 parent 30de9fe commit 6e23b9c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AllBlock {
public static final HashMap<String,Item> 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)));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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){

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@ public abstract class StdLimiterItem extends StdMagicItem {
public StdLimiterItem(Settings settings, EntityType<StdThrownMagic> entityType) {
super(settings, entityType);
}

@Override
public StdThrownMagic getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate) {
return null;
}

public abstract StdMagicLimiter getMagic();
}
Original file line number Diff line number Diff line change
@@ -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<StdThrownMagic> 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();
}
}

0 comments on commit 6e23b9c

Please sign in to comment.