Skip to content

Commit

Permalink
feat(法術釋放相關):
Browse files Browse the repository at this point in the history
修复了法杖施法逻辑,优化了物品栏管理,并生成了语言和战利品表(方塊自身掉落)数据代碼内生成。
  • Loading branch information
northgreen committed Apr 17, 2024
1 parent 6e23b9c commit 1b9afa1
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.19.2 2024-04-17T20:37:27.0952932 Language
84f246a88b9c3dc4c5d0c98a56c4de5529eabe74 assets\the_origin_of_magic\lang\en_us.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"item.the_origin_of_magic.test_staff": "Test Staff",
"item.the_origin_of_magic.deadwood_staff": "Deadwood Staff",
"block.the_origin_of_magic.magic_workbench": "Magic Workbench",
"text.the_origin_of_magic.magic_work_station.staff_state": "Staff State",
"item.the_origin_of_magic.deadwood_staff": "Deadwood Staff",
"item.the_origin_of_magic.hoglin_entity_limiter": "Hoglin Entity Limiter",
"item.the_origin_of_magic.test_magic": "Test Magic",
"text.the_origin_of_magic.not_staff": "This is not a staff , have no magic energy.So you can't edit it with magic work station",
"item.the_origin_of_magic.test_staff": "Test Staff",
"itemGroup.the_origin_of_magic.normal": "The Origin Of The Magic",
"text.the_origin_of_magic.empty_staff": "Maybe...... I means that the staff on your hand is empty,no magic in it and can't cast any magic,you need to use the Magic Workbench to edit this staff",
"text.the_origin_of_magic.staff_scattering": "Spell Scatter",
"text.the_origin_of_magic.magic_work_station.staff_state": "Staff State",
"text.the_origin_of_magic.not_staff": "This is not a staff , have no magic energy.So you can't edit it with magic work station",
"text.the_origin_of_magic.staff_capacity": "Staff Capacity",
"itemGroup.the_origin_of_magic.normal": "The Origin Of The Magic",
"text.the_origin_of_magic.staff_casting": "Casting Num"
"text.the_origin_of_magic.staff_casting": "Casting Num",
"text.the_origin_of_magic.staff_scattering": "Spell Scatter"
}
30 changes: 23 additions & 7 deletions src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.util.Rarity;
import net.minecraft.util.registry.Registry;

import java.util.Map;

/**
* 所有物品和物品組都應該寫在這個類裏方便管理和調用
*/
Expand All @@ -38,7 +40,23 @@ 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);
public static final Item HOGLIN_ENTITY_LIMITER = new UndeadEntityLimiterItem(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup).maxDamage(100).rarity(Rarity.COMMON),null);


public static final Map<String, Item> ItemMap = Map.of(
"deadwood_staff",DEADWOOD_STAFF,
"test_staff",TEST_STAFF,
"test_magic",TEST_MAGIC,
"hoglin_entity_limiter", HOGLIN_ENTITY_LIMITER
);

public static final Map<String, Item> ItemTrans = Map.of(
"Deadwood Staff",DEADWOOD_STAFF,
"Test Staff",TEST_STAFF,
"Test Magic",TEST_MAGIC,
"Hoglin Entity Limiter", HOGLIN_ENTITY_LIMITER
);

private static void registerItem(String name, Item item){
Registry.register(Registry.ITEM, new Identifier(the_origin_of_magic.Mod_Id, name), item);
}
Expand All @@ -47,11 +65,9 @@ public static void registerItems(){
for (String name : AllBlock.BlockItems.keySet()) {
registerItem(name, AllBlock.BlockItems.get(name));
}

// 注冊其他物品
registerItem("test_staff",TEST_STAFF);
registerItem("test_magic",TEST_MAGIC);
registerItem("deadwood_staff",DEADWOOD_STAFF);
registerItem("hoglin_entity_limiter", HOFLIN_ENTITY_LIMITER);
// 注冊物品
for (String name : ItemMap.keySet()) {
registerItem(name, ItemMap.get(name));
}
}
}
11 changes: 0 additions & 11 deletions src/main/java/com/ictye/the_origin_of_magic/ModDataGenerator.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
List<StdThrownMagic> magicList = summonMagic(Magics,user,world,count);
// 生成法術實體
for(StdThrownMagic MagicEntity:magicList){

float finalSpeed = getSpeed(); // 計算最終速度
float finalScattering = getScattering(); // 計算最終散射

MagicEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, finalSpeed, finalScattering); // 設置參數
if(world.spawnEntity(MagicEntity)){
// 生成法術實體并且破壞物品
Expand All @@ -308,20 +310,13 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
* @return 法術列表
*/
private List<StdThrownMagic> summonMagic(MagicInventory inventory, PlayerEntity user , World world, int count){
/*
FIXME:
在解析附加魔法的時候存在邏輯錯誤,可能導致死循環
*/

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

do {
ItemStack magic = inventory.getStack(castCount); // 獲取魔法物品堆棧
Item magicItem = magic.getItem(); // 魔法物品
//檢查是否為空
if (magicItem == Items.AIR || magic == ItemStack.EMPTY){
updateCastCount();
for(int i = inventory.size() + 1; i > 0 && count > 0 ;i --){
Item magicItem = inventory.next().getItem(); // 魔法物品
if (magicItem == Items.AIR){
continue;
}
if(((StdMagicItem)magicItem).getMagic(user,world,exolisionRate,hartRate) instanceof StdThrownMagic MagicEntity){
Expand All @@ -330,16 +325,19 @@ private List<StdThrownMagic> summonMagic(MagicInventory inventory, PlayerEntity
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--;
} if(((StdMagicItem)magicItem).getMagic(user,world,exolisionRate,hartRate) instanceof StdMagicLimiter limiter){
limiterList.add(limiter);
count--;
}
}while (count > 0 && startSlot != castCount );
}

for(StdMagicLimiter limiter :limiterList){
for(StdThrownMagic magic :magicItemList){
magic.addLimiter(limiter);
}
}
return magicItemList;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ictye.the_origin_of_magic.infrastructure.Datagen;

import com.ictye.the_origin_of_magic.Contents.AllBlock;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;

public class BlockLootTable extends FabricBlockLootTableProvider {

public BlockLootTable(FabricDataGenerator dataGenerator) {
super(dataGenerator);
}

@Override
protected void generateBlockLootTables() {
addDrop(AllBlock.MAGIC_WORKSTATION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ictye.the_origin_of_magic.infrastructure.Datagen;

import com.ictye.the_origin_of_magic.Contents.AllItem;
import com.ictye.the_origin_of_magic.the_origin_of_magic;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
import java.nio.file.Path;

public class DefaultLang extends FabricLanguageProvider {
protected DefaultLang(FabricDataGenerator dataGenerator) {
super(dataGenerator, "en_us");
}

@Override
public void generateTranslations(TranslationBuilder translationBuilder) {
// 生成代碼内翻譯
for(String name : AllItem.ItemTrans.keySet()){
translationBuilder.add(AllItem.ItemTrans.get(name), name);
}

the_origin_of_magic.LOGGER.info("Adding existing language file!");

// 添加預製的語言文件
try {
Path existingFilePath = dataGenerator.getModContainer().findPath("assets/the_origin_of_magic/lang/en_us.existing.json").get();
translationBuilder.add(existingFilePath);
} catch (Exception e) {
throw new RuntimeException("Failed to add existing language file!", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ictye.the_origin_of_magic.infrastructure.Datagen;

import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

import java.io.IOException;

public class ModDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {

fabricDataGenerator.addProvider(DefaultLang::new);
fabricDataGenerator.addProvider(BlockLootTable::new);

try {
fabricDataGenerator.run();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

/**
* 存放魔法的物品欄,用於法術施放什麽的
* 支持隊列操作,可以循環
*/
public class MagicInventory extends SimpleInventory {

int count = 0;

public MagicInventory(int size) {
super(size);
}
Expand All @@ -25,4 +28,24 @@ public boolean canInsert(ItemStack stack) {
return super.canInsert(stack) && stack.getItem() instanceof StdMagicItem;
}

private void updateCastCount(){
if (size() != 1){
if (count + 1 > size()){
count = -1;
updateCastCount();
}else {
count = count + 1;
}
}
}

public ItemStack next(){
int c = count;
updateCastCount();
return getStack(c);
}

public void resetCount(){
count = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"block.the_origin_of_magic.magic_workbench": "Magic Workbench",
"text.the_origin_of_magic.magic_work_station.staff_state": "Staff State",
"text.the_origin_of_magic.not_staff": "This is not a staff , have no magic energy.So you can't edit it with magic work station",
"text.the_origin_of_magic.empty_staff": "Maybe...... I means that the staff on your hand is empty,no magic in it and can't cast any magic,you need to use the Magic Workbench to edit this staff",
"text.the_origin_of_magic.staff_scattering": "Spell Scatter",
"text.the_origin_of_magic.staff_capacity": "Staff Capacity",
"itemGroup.the_origin_of_magic.normal": "The Origin Of The Magic",
"text.the_origin_of_magic.staff_casting": "Casting Num"
}
11 changes: 6 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
],
"main": [
"com.ictye.the_origin_of_magic.the_origin_of_magic"
],"fabric-gametest": [
],
"fabric-gametest": [
"com.ictye.the_origin_of_magic.GameTest.GameTestMain"
],
"fabric-datagen": [
"com.ictye.the_origin_of_magic.infrastructure.Datagen.ModDataGenerator"
]
},
"mixins": [
Expand All @@ -33,8 +37,5 @@
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}"
},
"fabric-datagen": [
"com.ictye.the_origin_of_magic.ModDataGenerator"
]
}
}

0 comments on commit 1b9afa1

Please sign in to comment.