Skip to content

Commit

Permalink
feat(entitys and limiter and magics): 增加限制器功能
Browse files Browse the repository at this point in the history
我們希望能有限制攻擊的東西

Closes 沒有經過驗證,不一定好使

[skip ci]
  • Loading branch information
northgreen committed Apr 17, 2024
1 parent a3ec711 commit 30de9fe
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ictye.the_origin_of_magic.Contents;

import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.TestThrownMagic;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
Expand All @@ -13,7 +14,7 @@

public class AllEntity {

public static final EntityType<StdMagic> TEST_MAGIC_ENTITY_TYPE= FabricEntityTypeBuilder.<StdMagic>create(SpawnGroup.MISC, com.ictye.the_origin_of_magic.foundation.Entitys.Magics.TestMagic::new)
public static final EntityType<StdThrownMagic> TEST_MAGIC_ENTITY_TYPE= FabricEntityTypeBuilder.<StdThrownMagic>create(SpawnGroup.MISC, TestThrownMagic::new)
.dimensions(EntityDimensions.fixed(0.25F, 0.25F))
.trackRangeBlocks(4).trackedUpdateRate(10)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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;
import com.ictye.the_origin_of_magic.foundation.Items.Staff.TestStaff;
Expand Down Expand Up @@ -37,6 +39,7 @@ public class AllItem {
*/
public static final Item TEST_MAGIC = new TestMagicEntityItem(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup), AllEntity.TEST_MAGIC_ENTITY_TYPE); // 測試魔法

public static final Item HOFLIN_ENTITY_LIMITER = new UndeadEntityLimiterItem(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup).maxDamage(100).rarity(Rarity.COMMON),null);
private static void registerItem(String name, Item item){
Registry.register(Registry.ITEM, new Identifier(the_origin_of_magic.Mod_Id, name), item);
}
Expand All @@ -50,5 +53,6 @@ public static void registerItems(){
registerItem("test_staff",TEST_STAFF);
registerItem("test_magic",TEST_MAGIC);
registerItem("deadwood_staff",DEADWOOD_STAFF);
registerItem("hoglin_entity_limiter", HOFLIN_ENTITY_LIMITER);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters;

import net.minecraft.entity.mob.HoglinEntity;
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 {
@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ public void onHit( @Nullable EntityHitResult entityHitResult, @Nullable HitResul
public boolean canEffect(@Nullable EntityHitResult entityHitResult, @Nullable HitResult hitResult, @Nullable BlockHitResult blockHitResult){
return true;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.ictye.the_origin_of_magic.foundation.Entitys.Magics;

public interface StdMagicInterface {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class StdMagic extends ThrownEntity implements FlyingItemEntity {
public abstract class StdThrownMagic extends ThrownEntity implements FlyingItemEntity,StdMagicInterface {

/**
* 附加魔法計數
Expand All @@ -24,7 +24,7 @@ public abstract class StdMagic extends ThrownEntity implements FlyingItemEntity
/**
* 附加魔法列表
*/
private List<StdMagic> magic;
private List<StdThrownMagic> magic;

private final List<StdMagicLimiter> limiters = new ArrayList<>();

Expand All @@ -44,23 +44,23 @@ public int getAdditionalTrigger() {
* 設置附加魔法
* @param magics 魔法列表
*/
public void setAdditionTrigger(List<StdMagic> magics){
public void setAdditionTrigger(List<StdThrownMagic> magics){
this.magic = magics;
}

protected StdMagic(EntityType<? extends ThrownEntity> entityType, World world) {
protected StdThrownMagic(EntityType<? extends ThrownEntity> entityType, World world) {
super(entityType, world);
}

protected StdMagic(EntityType<? extends ThrownEntity> type, double x, double y, double z, World world) {
protected StdThrownMagic(EntityType<? extends ThrownEntity> type, double x, double y, double z, World world) {
super(type, x, y, z, world);
}

protected StdMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world) {
protected StdThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world) {
super(type, owner, world);
}

public StdMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float exolisionRate) {
public StdThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float exolisionRate) {
this(type, owner, world);
this.exolisionRate = exolisionRate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;

public class TestMagic extends StdMagic {
public class TestThrownMagic extends StdThrownMagic {

private float exolisionRate;

Expand All @@ -20,17 +20,17 @@ protected float getGravity() {
return 0.0F;
}

public TestMagic(EntityType<? extends ThrownEntity> entityType, World world) {
public TestThrownMagic(EntityType<? extends ThrownEntity> entityType, World world) {
super(entityType, world);
this.exolisionRate = 1.0F;
}

public TestMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world) {
public TestThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world) {
super(type, owner, world);
this.exolisionRate = 1.0F;
}

public TestMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float exolisionRate) {
public TestThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float exolisionRate) {
this(type, owner, world);
this.exolisionRate = exolisionRate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem;

import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagic;
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 net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class StdLimiterItem extends StdMagicItem {
public StdLimiterItem(Settings settings, EntityType<StdMagic> entityType) {
public abstract class StdLimiterItem extends StdMagicItem {
public StdLimiterItem(Settings settings, EntityType<StdThrownMagic> entityType) {
super(settings, entityType);
}

@Override
public StdMagic getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate) {
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
@@ -0,0 +1,17 @@
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.StdMagicLimiter;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import net.minecraft.entity.EntityType;

public class UndeadEntityLimiterItem extends StdLimiterItem{
public UndeadEntityLimiterItem(Settings settings, EntityType<StdThrownMagic> entityType) {
super(settings, entityType);
}

@Override
public StdMagicLimiter getMagic() {
return new HoglinEntityLimiter();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.ictye.the_origin_of_magic.foundation.Items.Magic;

import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagic;
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.item.Item;
import net.minecraft.world.World;

public abstract class StdMagicItem extends Item {

private final EntityType<StdMagic> magicEntityType;
public StdMagicItem(Settings settings, EntityType<StdMagic> entityType) {
private final EntityType<StdThrownMagic> magicEntityType;
public StdMagicItem(Settings settings, EntityType<StdThrownMagic> entityType) {
super(settings);
this.magicEntityType = entityType;
}

abstract public StdMagic getMagic(PlayerEntity user, World world,float exolisionRate,int hartRate);
abstract public StdMagicInterface getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.ictye.the_origin_of_magic.foundation.Items.Magic;

import com.ictye.the_origin_of_magic.Contents.AllEntity;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.TestMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.TestThrownMagic;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class TestMagicEntityItem extends StdMagicItem {

private final EntityType<StdMagic> magicEntityType = AllEntity.TEST_MAGIC_ENTITY_TYPE;
public TestMagicEntityItem(Settings settings, EntityType<StdMagic> entityType) {
private final EntityType<StdThrownMagic> magicEntityType = AllEntity.TEST_MAGIC_ENTITY_TYPE;
public TestMagicEntityItem(Settings settings, EntityType<StdThrownMagic> entityType) {
super(settings, entityType);
}

@Override
public StdMagic getMagic(PlayerEntity user, World world,float exolisionRate,int hartRate) {
return new TestMagic(magicEntityType,user,world,exolisionRate);
public StdThrownMagic getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate) {
return new TestThrownMagic(magicEntityType,user,world,exolisionRate);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ictye.the_origin_of_magic.foundation.Items.Staff;

import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdMagic;
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.utils.MagicInventory;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -283,9 +284,9 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
if (!world.isClient) {
// 施放解析邏輯
int count = getCastingNum(); // 可釋放的數量
List<StdMagic> magicList = summonMagic(Magics,user,world,count);
List<StdThrownMagic> magicList = summonMagic(Magics,user,world,count);
// 生成法術實體
for(StdMagic MagicEntity:magicList){
for(StdThrownMagic MagicEntity:magicList){
float finalSpeed = getSpeed(); // 計算最終速度
float finalScattering = getScattering(); // 計算最終散射
MagicEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, finalSpeed, finalScattering); // 設置參數
Expand All @@ -306,13 +307,13 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
* @param world 世界
* @return 法術列表
*/
private List<StdMagic> summonMagic(MagicInventory inventory, PlayerEntity user , World world, int count){
private List<StdThrownMagic> summonMagic(MagicInventory inventory, PlayerEntity user , World world, int count){
/*
FIXME:
在解析附加魔法的時候存在邏輯錯誤,可能導致死循環
*/

List<StdMagic> magicItemList = new ArrayList<>();
List<StdThrownMagic> magicItemList = new ArrayList<>();
int startSlot = castCount; // 起始格子

do {
Expand All @@ -323,15 +324,21 @@ private List<StdMagic> summonMagic(MagicInventory inventory, PlayerEntity user ,
updateCastCount();
continue;
}
StdMagic MagicEntity = ((StdMagicItem)magicItem).getMagic(user,world,exolisionRate,hartRate);
int addition = MagicEntity.getAdditionalTrigger();
// 處理有附加的法術
if(addition > 0){
MagicEntity.setAdditionTrigger(summonMagic(inventory,user,world,addition));
if(((StdMagicItem)magicItem).getMagic(user,world,exolisionRate,hartRate) instanceof StdThrownMagic MagicEntity){
int addition = MagicEntity.getAdditionalTrigger();
// 處理有附加的法術
if(addition > 0){
MagicEntity.setAdditionTrigger(summonMagic(inventory,user,world,addition));
}
count --;
updateCastCount();
magicItemList.add(MagicEntity);
}else if(((StdMagicItem)magicItem).getMagic(user,world,exolisionRate,hartRate) instanceof StdMagicLimiter limiter){
StdThrownMagic lastmagic = magicItemList.get(magicItemList.size()-1);
lastmagic.addLimiter(limiter);
count --;
updateCastCount();
}
count --;
updateCastCount();
magicItemList.add(MagicEntity);
}while (count > 0 && startSlot != castCount );
return magicItemList;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "the_origin_of_magic:item/hoglin_entity_limiter"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 30de9fe

Please sign in to comment.