Skip to content

Commit

Permalink
修复了物品模型注册和翻译问题,优化了代码结构。
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 19, 2024
1 parent 01a66e4 commit 2597bb5
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-19T19:43:43.0995063 Language
84f246a88b9c3dc4c5d0c98a56c4de5529eabe74 assets\the_origin_of_magic\lang\en_us.json
// 1.19.2 2024-04-19T22:45:49.3401001 Language
cf9144aa31d03773d984551199f36d4c66351a1f assets\the_origin_of_magic\lang\en_us.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-19T19:43:43.0964229 Block Loot Tables
// 1.19.2 2024-04-19T22:45:49.3370978 Block Loot Tables
fe57f13449a11436bbede8c37e01bd0d1cd87191 data\the_origin_of_magic\loot_tables\blocks\magic_workbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// 1.19.2 2024-04-19T22:45:49.3434062 Models
02d3ff4716d16f7c5a4dd4432d1b98f744a13f02 assets\the_origin_of_magic\models\item\blood_essence.json
03b1f5cc891077d36d38a8d98d2ffe49396f8229 assets\the_origin_of_magic\models\item\water_magic_element.json
2 changes: 2 additions & 0 deletions src/main/generated/assets/the_origin_of_magic/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"block.the_origin_of_magic.magic_workbench": "Magic Workbench",
"item.the_origin_of_magic.blood_essence": "Blood Essence",
"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",
"item.the_origin_of_magic.test_staff": "Test Staff",
"item.the_origin_of_magic.water_magic_element": "Water Magic Element",
"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.magic_work_station.staff_state": "Staff State",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "the_origin_of_magic:item/blood_essence"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "the_origin_of_magic:item/water_magic_element"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;

public class AllBlock {

public static final HashMap<String,Item> BlockItems = new HashMap<>();
public static 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")
Expand Down
70 changes: 60 additions & 10 deletions src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.ictye.the_origin_of_magic.Contents;

import com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem.UndeadEntityLimiterItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem;
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;
import com.ictye.the_origin_of_magic.the_origin_of_magic;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.data.client.Model;
import net.minecraft.data.client.Models;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand All @@ -33,30 +36,77 @@ public class AllItem {
/**
* 所有法杖
*/
public static final Item DEADWOOD_STAFF = new DeadwoodStaff(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup).maxDamage(100).rarity(Rarity.COMMON));
public static final Item TEST_STAFF = new TestStaff(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup).maxDamage(300).rarity(Rarity.RARE)); // 測試法杖
public static final Item DEADWOOD_STAFF = new DeadwoodStaff(new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
.maxDamage(100)
.rarity(Rarity.COMMON));
public static final Item TEST_STAFF = new TestStaff(new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
.maxDamage(300)
.rarity(Rarity.RARE)); // 測試法杖
/**
* 所有魔法
*/
public static final Item TEST_MAGIC = new TestMagicEntityItem(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup), AllEntity.TEST_MAGIC_ENTITY_TYPE); // 測試魔法
public static final Item TEST_MAGIC = createMagic("Test Magic","test_magic",new TestMagicEntityItem(new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup), AllEntity.TEST_MAGIC_ENTITY_TYPE)); // 測試魔法

public static final Item HOGLIN_ENTITY_LIMITER = new UndeadEntityLimiterItem(new FabricItemSettings().maxCount(1).group(TheOriginOfMagicItemGroup).maxDamage(100).rarity(Rarity.COMMON),null);
public static final Item HOGLIN_ENTITY_LIMITER = createMagic("Hoglin Entity Limiter","hoglin_entity_limiter",new UndeadEntityLimiterItem(new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
.maxDamage(100)
.rarity(Rarity.COMMON),null));

/**
* 所有材料
*/

public static final Item BLOOD_ESSENCE = new Item(new FabricItemSettings()
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));

public static final Item WATER_MAGIC_ELEMENT = new Item(new FabricItemSettings()
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));

public static final Map<String, Item> ItemMap = Map.of(

/**
* 物品ID列表
*/
public static Map<String, Item> ItemMap = Map.of(
"deadwood_staff",DEADWOOD_STAFF,
"test_staff",TEST_STAFF,
"test_magic",TEST_MAGIC,
"hoglin_entity_limiter", HOGLIN_ENTITY_LIMITER
"blood_essence",BLOOD_ESSENCE,
"water_magic_element",WATER_MAGIC_ELEMENT
);

public static final Map<String, Item> ItemTrans = Map.of(
/**
* 物品英文翻譯列表
*/
public static Map<String, Item> ItemTransMap = Map.of(
"Deadwood Staff",DEADWOOD_STAFF,
"Test Staff",TEST_STAFF,
"Test Magic",TEST_MAGIC,
"Hoglin Entity Limiter", HOGLIN_ENTITY_LIMITER
"Blood Essence", BLOOD_ESSENCE,
"Water Magic Element",WATER_MAGIC_ELEMENT
);

/**
* 物品模型列表
*/
public static Map< Item,Model> ItemModelMap = Map.of(
BLOOD_ESSENCE,Models.GENERATED,
WATER_MAGIC_ELEMENT,Models.GENERATED
);

private static Item createMagic(String name, String id, StdMagicItem magicItem){
ItemMap.put(id,magicItem);
ItemModelMap.put(magicItem,Models.GENERATED);
ItemTransMap.put(name,magicItem);
return magicItem;
}

private static void registerItem(String name, Item item){
Registry.register(Registry.ITEM, new Identifier(the_origin_of_magic.Mod_Id, name), item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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;
Expand All @@ -12,7 +11,7 @@ public class HostileEntityLimiter extends StdMagicLimiter {
public boolean canEffect(@Nullable EntityHitResult entityHitResult, @Nullable HitResult hitResult, @Nullable BlockHitResult blockHitResult) {
// 判斷是否為亡靈生物
if (entityHitResult != null) {
return entityHitResult.getEntity() instanceof ZombieEntity;
return entityHitResult.getEntity() instanceof HoglinEntity;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem;

public interface StdMagicItemInterface {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.item.Item;
import net.minecraft.world.World;

public abstract class StdMagicItem extends Item {
public abstract class StdMagicItem extends Item implements StdMagicInterface{

private final EntityType<StdThrownMagic> magicEntityType;
public StdMagicItem(Settings settings, EntityType<StdThrownMagic> entityType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* </pre>
* */
public abstract class StdStaff extends Item {
@SuppressWarnings("UnusedAssignment")
private MagicInventory inventory = new MagicInventory(getSize());

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ictye.the_origin_of_magic.infrastructure.Datagens;

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;

Expand All @@ -15,12 +14,10 @@ protected DefaultLangGens(FabricDataGenerator dataGenerator) {
@Override
public void generateTranslations(TranslationBuilder translationBuilder) {
// 生成代碼内翻譯
for(String name : AllItem.ItemTrans.keySet()){
translationBuilder.add(AllItem.ItemTrans.get(name), name);
for(String name : AllItem.ItemTransMap.keySet()){
translationBuilder.add(AllItem.ItemTransMap.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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ictye.the_origin_of_magic.infrastructure.Datagens;

import com.ictye.the_origin_of_magic.Contents.AllItem;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.data.client.ItemModelGenerator;
import net.minecraft.item.Item;

public class ItemModelGen extends FabricModelProvider {
public ItemModelGen(FabricDataGenerator dataGenerator) {
super(dataGenerator);
}

@Override
public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {

}

@Override
public void generateItemModels(ItemModelGenerator itemModelGenerator) {
// 生成物品模型
for(Item item : AllItem.ItemModelMap.keySet()){
itemModelGenerator.register(item, AllItem.ItemModelMap.get(item));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public class ModDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {

// 在這裏出注冊生成器
fabricDataGenerator.addProvider(DefaultLangGens::new);
fabricDataGenerator.addProvider(BlockLootTableGens::new);
fabricDataGenerator.addProvider(ItemModelGen::new);

try {
fabricDataGenerator.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.network.PacketByteBuf;

public class SyncHUDS2CPacket {
@SuppressWarnings("unused")
public static void receive(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buffer, PacketSender responseSender) {
PlayerEntity playerEntity = client.player;
MagicAbilitiesManager magicAbilitiesManager = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager;

public interface PlayerEntityMixinInterfaces {
public MagicAbilitiesManager the_origin_of_magic$getMagicAbilitiesManager();
MagicAbilitiesManager the_origin_of_magic$getMagicAbilitiesManager();
}

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"com.ictye.the_origin_of_magic.GameTest.GameTestMain"
],
"fabric-datagen": [
"com.ictye.the_origin_of_magic.infrastructure.Datagen.ModDataGenerator"
"com.ictye.the_origin_of_magic.infrastructure.Datagens.ModDataGenerator"
]
},
"mixins": [
Expand Down

0 comments on commit 2597bb5

Please sign in to comment.