Skip to content

Commit

Permalink
perf: 優化代碼
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 21, 2024
1 parent 8430b9d commit a4ad638
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-21T18:07:19.8219125 Language
15d5985ea35697dd10f2560105dbe46388d1a571 assets\the_origin_of_magic\lang\en_us.json
// 1.19.2 2024-04-21T20:00:12.9330783 Language
186c3f9c9fe92b38b1958905153cee3079c2fa03 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-21T18:07:19.8234132 Block Loot Tables
// 1.19.2 2024-04-21T20:00:12.9355771 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
@@ -1,9 +1,14 @@
// 1.19.2 2024-04-21T18:07:19.8199129 Models
// 1.19.2 2024-04-21T20:00:12.9375772 Models
02d3ff4716d16f7c5a4dd4432d1b98f744a13f02 assets\the_origin_of_magic\models\item\blood_essence.json
781092579f171cf0db8317aa6267ad8e5cfbbd1f assets\the_origin_of_magic\models\item\fire_magic_element.json
f54d22f024ca8dbc5f81e759c90de28d15c18b17 assets\the_origin_of_magic\models\item\kind_magic_element.json
52dda52229d5e92e940848b91862d354edf37ef0 assets\the_origin_of_magic\models\item\nature_magic_element.json
76b58d78d6d9e28c4af4f02ff147ddab4ff36cba assets\the_origin_of_magic\models\item\empty_magic_element.json
50c992db06feb825ceb8fe3bd063a7d5fcc83264 assets\the_origin_of_magic\models\item\explosion_magic.json
ddf4e605ac73f757f76bbfe39d60312b7042e7d9 assets\the_origin_of_magic\models\item\hostile_entity_limiter.json
14f7b54096acc0b1b7b588d72bd80df62d566018 assets\the_origin_of_magic\models\item\earth_magic_element.json
02d3ff4716d16f7c5a4dd4432d1b98f744a13f02 assets\the_origin_of_magic\models\item\blood_essence.json
da16015585e364c4561b91a3b83056d8c3646d1c assets\the_origin_of_magic\models\item\gold_magic_element.json
681374800d5b4991c2e8d6304781b89089bd379c assets\the_origin_of_magic\models\item\poison_magic.json
7091cce590f8bb481903e0177866dfcb338f42c0 assets\the_origin_of_magic\models\item\magic_core.json
03b1f5cc891077d36d38a8d98d2ffe49396f8229 assets\the_origin_of_magic\models\item\water_magic_element.json
ab49fab583c552ecda70edd5fe49219c058481cb assets\the_origin_of_magic\models\item\evil_magic_element.json
76b58d78d6d9e28c4af4f02ff147ddab4ff36cba assets\the_origin_of_magic\models\item\empty_magic_element.json
18 changes: 17 additions & 1 deletion src/main/generated/assets/the_origin_of_magic/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
{
"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.earth_magic_element": "Earth Magic Element",
"item.the_origin_of_magic.empty_magic_element": "Empty Magic Element",
"item.the_origin_of_magic.evil_magic_element": "Evil Magic Element",
"item.the_origin_of_magic.explosion_magic": "Explosion Magic",
"item.the_origin_of_magic.fire_magic_element": "Fire Magic Element",
"item.the_origin_of_magic.gold_magic_element": "Gold Magic Element",
"item.the_origin_of_magic.hostile_entity_limiter": "Hostile Entity Limiter",
"item.the_origin_of_magic.kind_magic_element": "Kind Magic Element",
"item.the_origin_of_magic.magic_core": "Magic Core",
"item.the_origin_of_magic.nature_magic_element": "Nature Magic Element",
"item.the_origin_of_magic.poison_magic": "Poison Magic",
"item.the_origin_of_magic.test_staff": "Test Staff",
"item.the_origin_of_magic.test_staff.tooltip": "Only For Codding Test",
"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",
"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",
"text.the_origin_of_magic.staff_casting": "Casting Num",
"text.the_origin_of_magic.staff_scattering": "Spell Scatter",
"text.the_origin_of_magic.undead_entity_limiter_item_tooltip1": "Causes all magic released to only take effect when hitting a ground target creature"
"text.the_origin_of_magic.undead_entity_limiter_item_tooltip1": "Makes magic only work when",
"text.the_origin_of_magic.undead_entity_limiter_item_tooltip2": "when it hits a hostile creature"
}
61 changes: 59 additions & 2 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 @@ -5,6 +5,7 @@
import com.ictye.the_origin_of_magic.foundation.Items.Magic.PoisonMagicEntityItem;
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.infrastructure.ModRegistrate;
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;
Expand All @@ -23,6 +24,7 @@
/**
* 所有物品和物品組都應該寫在這個類裏方便管理和調用
*/
@SuppressWarnings("unused")
public class AllItem {

//////////////////////////////////////////////////
Expand All @@ -31,7 +33,7 @@ public class AllItem {
* 主物品組
*/
public static final ItemGroup TheOriginOfMagicItemGroup = FabricItemGroupBuilder.build(new Identifier(the_origin_of_magic.Mod_Id,"normal"),
() ->new ItemStack(AllBlock.BlockItems.get("magic_workbench")));
() ->new ItemStack(ModRegistrate.BlockItems.get("magic_workbench")));
/////////////////////////////////////////////////
// 所有法杖
public static final Item DEADWOOD_STAFF = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
Expand Down Expand Up @@ -84,7 +86,7 @@ public class AllItem {
UndeadEntityLimiterItem::new,
"hostile_entity_limiter",
"Hostile Entity Limiter",
null,
Models.GENERATED,
new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
Expand Down Expand Up @@ -130,6 +132,43 @@ public class AllItem {
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));

/**
* 火元素魔法
*/
public static final Item FIRE_MAGIC_ELEMENT = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
Item::new,
"fire_magic_element",
"Fire Magic Element",
Models.GENERATED,
new FabricItemSettings()
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));

/**
* 金元素魔法
*/
public static final Item GOLD_MAGIC_ELEMENT = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
Item::new,
"gold_magic_element",
"Gold Magic Element",
Models.GENERATED,
new FabricItemSettings()
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));


/**
* 木元素魔法
*/
public static final Item NATURE_MAGIC_ELEMENT = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
Item::new,
"nature_magic_element",
"Nature Magic Element",
Models.GENERATED,
new FabricItemSettings()
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));

/**
* 空元素魔法
*/
Expand All @@ -142,6 +181,11 @@ public class AllItem {
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));



/**
* 邪惡魔法元素
*/
public static final Item EVIL_MAGIC_ELEMENT = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
Item::new,
"evil_magic_element",
Expand All @@ -151,6 +195,19 @@ public class AllItem {
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));

/**
* 善良魔法元素
*/
public static final Item KIND_MAGIC_ELEMENT = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
Item::new,
"kind_magic_element",
"Kind Magic Element",
Models.GENERATED,
new FabricItemSettings()
.group(TheOriginOfMagicItemGroup)
.rarity(Rarity.COMMON));


/**
* 魔法核心
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ public ClientPlayerMixin(World world, BlockPos pos, float yaw, GameProfile gameP

@SuppressWarnings("MissingUnique")
private final MagicAbilitiesManager magicAbilitiesManager = ((PlayerEntityMixinInterfaces)this).the_origin_of_magic$getMagicAbilitiesManager();


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.ictye.the_origin_of_magic.infrastructure.Datagens;

import com.ictye.the_origin_of_magic.Contents.AllBlock;
import com.ictye.the_origin_of_magic.infrastructure.ModRegistrate;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.minecraft.block.Block;

public class BlockLootTableGens extends FabricBlockLootTableProvider {

Expand All @@ -12,6 +13,11 @@ public BlockLootTableGens(FabricDataGenerator dataGenerator) {

@Override
protected void generateBlockLootTables() {
addDrop(AllBlock.MAGIC_WORKSTATION);
for (Block block : ModRegistrate.NormalBlockList) {
addDrop(block);
}
for (Block block : ModRegistrate.OreItemMap.keySet()) {
addDrop(block, ModRegistrate.OreItemMap.get(block));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +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.infrastructure.ModRegistrate;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;

Expand All @@ -14,8 +14,8 @@ protected DefaultLangGens(FabricDataGenerator dataGenerator) {
@Override
public void generateTranslations(TranslationBuilder translationBuilder) {
// 生成代碼内翻譯
for(String name : AllItem.ItemTransMap.keySet()){
translationBuilder.add(AllItem.ItemTransMap.get(name), name);
for(String name : ModRegistrate.ItemTransMap.keySet()){
translationBuilder.add(ModRegistrate.ItemTransMap.get(name), name);
}

// 添加預製的語言文件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

Expand All @@ -34,49 +33,13 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int
int x = (width - backgroundWidth) / 2;
int y = (height - backgroundHeight) / 2;
drawTexture(matrices,x,y - 2 ,0,0,backgroundWidth,backgroundHeight);

}

@Override
public Optional<Element> hoveredElement(double mouseX, double mouseY) {
return super.hoveredElement(mouseX, mouseY);
}

@Override
public void mouseMoved(double mouseX, double mouseY) {
super.mouseMoved(mouseX, mouseY);
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return super.mouseScrolled(mouseX, mouseY, amount);
}

@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
return super.keyReleased(keyCode, scanCode, modifiers);
}

@Override
public boolean charTyped(char chr, int modifiers) {
return super.charTyped(chr, modifiers);
}

@Override
public void setInitialFocus(@Nullable Element element) {
super.setInitialFocus(element);
}

@Override
public void focusOn(@Nullable Element element) {
super.focusOn(element);
}

@Override
public boolean changeFocus(boolean lookForwards) {
return super.changeFocus(lookForwards);
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
renderBackground(matrices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* <h2>模組内容注冊表</h2>
*
* <p>
* 這個類存放物品和方塊的初始化方法,方便在初始化的時候就完成注冊(原來的實在有點反人類)
* </p>
*
*/
public class ModRegistrate {
public ModRegistrate(){

Expand All @@ -38,6 +48,16 @@ public ModRegistrate(){
*/
public static final Map<String,Item> BlockItems = new HashMap<>();

/**
* 正常方塊,用於注冊掉落自身的列表
*/
public static final List<Block> NormalBlockList = new ArrayList<>();

/**
* 礦物注冊,注冊礦石和掉貨物的列表
*/
public static final Map<Block,Item> OreItemMap = new HashMap<>();

/**
* 注册物品
* @param item 物品
Expand Down Expand Up @@ -90,6 +110,29 @@ public Block blockBuilder(Function<Block.Settings,Block> block ,String id,String
BlockItems.put(id,blockItem);
ItemMap.put(id,blockItem);
ItemTransMap.put(name,blockItem);
NormalBlockList.add(block1);
Registry.register(Registry.ITEM, new Identifier(the_origin_of_magic.Mod_Id, id), blockItem);
Registry.register(Registry.BLOCK, new Identifier(the_origin_of_magic.Mod_Id, id), block1);
return block1;
}

/**
* 注册方塊(掉落礦物)
* @param block 方塊
* @param id ID
* @param name 名字
* @param settings 方塊設置
* @param dropItem 掉落物
* @param itemSettings 物品設置
* @return 方塊對象
*/
public Block blockBuilder(Function<Block.Settings,Block> block ,String id,String name,Block.Settings settings,Item dropItem,Item.Settings itemSettings){
Block block1 = block.apply(settings);
Item blockItem = new BlockItem(block1,itemSettings);
BlockItems.put(id,blockItem);
ItemMap.put(id,blockItem);
ItemTransMap.put(name,blockItem);
OreItemMap.put(block1,dropItem);
Registry.register(Registry.ITEM, new Identifier(the_origin_of_magic.Mod_Id, id), blockItem);
Registry.register(Registry.BLOCK, new Identifier(the_origin_of_magic.Mod_Id, id), block1);
return block1;
Expand All @@ -108,10 +151,22 @@ public Block blockBuilder(Function<Block.Settings,Block> block ,String id,Block.
return block1;
}

/**
* 注冊實體
* @param entityType 實體
* @param id 實體ID
* @return 實體
*/
public EntityType entityBuilder(EntityType entityType,String id){
Registry.register(Registry.ENTITY_TYPE,
new Identifier(the_origin_of_magic.Mod_Id, id),
entityType);
return entityType;
}

static class BlockType{
public static final int NORMAL_BLOCK = 1;

public static final int ORE_BLOCK = 2;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"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",
"text.the_origin_of_magic.undead_entity_limiter_item_tooltip1": "Causes all magic released to only take effect when hitting a ground target creature",
"text.the_origin_of_magic.undead_entity_limiter_item_tooltip1": "Makes magic only work when",
"text.the_origin_of_magic.undead_entity_limiter_item_tooltip2": "when it hits a hostile creature",
"itemGroup.the_origin_of_magic.normal": "The Origin Of The Magic",
"text.the_origin_of_magic.staff_casting": "Casting Num",
"item.the_origin_of_magic.test_staff.tooltip": "Only For Codding Test"
Expand Down

0 comments on commit a4ad638

Please sign in to comment.