9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 03:19:14 +00:00

Merge pull request #43 from Xiao-MoMi/dev

Anvil & Repair Recipes
This commit is contained in:
XiaoMoMi
2025-03-16 05:19:55 +08:00
committed by GitHub
32 changed files with 803 additions and 166 deletions

View File

@@ -3,7 +3,7 @@ items:
material: paper
custom-model-data: 3001
data:
display-name: "<!i><i18n:item.chinese_lantern>"
item-name: "<!i><i18n:item.chinese_lantern>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/chinese_lantern"

View File

@@ -3,7 +3,7 @@ items:
material: paper
custom-model-data: 3000
data:
display-name: "<!i><i18n:item.fairy_flower>"
item-name: "<!i><i18n:item.fairy_flower>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/fairy_flower"

View File

@@ -3,7 +3,7 @@ items:
material: paper
custom-model-data: 2000
data:
display-name: "<!i><i18n:item.bench>"
item-name: "<!i><i18n:item.bench>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/bench"
@@ -49,7 +49,7 @@ items:
material: paper
custom-model-data: 2001
data:
display-name: "<!i><i18n:item.table_lamp>"
item-name: "<!i><i18n:item.table_lamp>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/table_lamp"
@@ -93,7 +93,7 @@ items:
material: paper
custom-model-data: 2002
data:
display-name: "<!i><i18n:item.wooden_chair>"
item-name: "<!i><i18n:item.wooden_chair>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/wooden_chair"

View File

@@ -2,8 +2,11 @@ items:
default:topaz_rod:
material: fishing_rod
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_rod>"
item-name: "<!i><#FF8C00><i18n:item.topaz_rod>"
tooltip-style: minecraft:topaz
model:
template: models:fishing_rod_2d
@@ -15,8 +18,11 @@ items:
default:topaz_bow:
material: bow
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_bow>"
item-name: "<!i><#FF8C00><i18n:item.topaz_bow>"
tooltip-style: minecraft:topaz
model:
template: models:bow_2d
@@ -32,8 +38,11 @@ items:
default:topaz_crossbow:
material: crossbow
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_crossbow>"
item-name: "<!i><#FF8C00><i18n:item.topaz_crossbow>"
tooltip-style: minecraft:topaz
model:
template: models:crossbow_2d
@@ -53,8 +62,11 @@ items:
default:topaz_pickaxe:
material: golden_pickaxe
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_pickaxe>"
item-name: "<!i><#FF8C00><i18n:item.topaz_pickaxe>"
tooltip-style: minecraft:topaz
components:
minecraft:max_damage: 64
@@ -68,8 +80,11 @@ items:
default:topaz_axe:
material: golden_axe
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_axe>"
item-name: "<!i><#FF8C00><i18n:item.topaz_axe>"
tooltip-style: minecraft:topaz
components:
minecraft:max_damage: 64
@@ -83,8 +98,11 @@ items:
default:topaz_hoe:
material: golden_hoe
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_hoe>"
item-name: "<!i><#FF8C00><i18n:item.topaz_hoe>"
tooltip-style: minecraft:topaz
components:
minecraft:max_damage: 64
@@ -98,8 +116,11 @@ items:
default:topaz_shovel:
material: golden_shovel
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_shovel>"
item-name: "<!i><#FF8C00><i18n:item.topaz_shovel>"
tooltip-style: minecraft:topaz
components:
minecraft:max_damage: 64
@@ -113,8 +134,11 @@ items:
default:topaz_sword:
material: golden_sword
custom-model-data: 1000
settings:
tags:
- "topaz_tools"
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_sword>"
item-name: "<!i><#FF8C00><i18n:item.topaz_sword>"
tooltip-style: minecraft:topaz
components:
minecraft:max_damage: 64
@@ -151,21 +175,126 @@ templates:
material: "chainmail_{part}"
custom-model-data: 1000
data:
display-name: "<!i><#FF8C00><i18n:item.topaz_{part}>"
item-name: "<!i><#FF8C00><i18n:item.topaz_{part}>"
tooltip-style: minecraft:topaz
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
settings:
tags:
- "topaz_tools"
equippable:
slot: "{slot}"
asset-id: topaz
humanoid: "minecraft:topaz"
humanoid-leggings: "minecraft:topaz"
model:
type: minecraft:select
property: minecraft:trim_material
fallback:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
cases:
- when: minecraft:quartz
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_quartz_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_quartz"
- when: minecraft:iron
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_iron_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_iron"
- when: minecraft:netherite
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_netherite_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_netherite"
- when: minecraft:redstone
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_redstone_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_redstone"
- when: minecraft:copper
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_copper_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_copper"
- when: minecraft:gold
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_gold_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_gold"
- when: minecraft:emerald
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_emerald_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_emerald"
- when: minecraft:diamond
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_diamond_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_diamond"
- when: minecraft:lapis
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_lapis_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_lapis"
- when: minecraft:amethyst
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_amethyst_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_amethyst"
- when: minecraft:resin
model:
type: minecraft:model
path: "minecraft:item/custom/topaz_{part}_resin_trim"
generation:
parent: "minecraft:item/generated"
textures:
"layer0": "minecraft:item/custom/topaz_{part}"
"layer1": "minecraft:trims/items/{part}_trim_resin"
recipes#11:
default:topaz_shovel:

View File

@@ -3,7 +3,7 @@ items:
material: paper
custom-model-data: 1010
data:
display-name: "<!i><i18n:item.topaz_ore>"
item-name: "<!i><i18n:item.topaz_ore>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/topaz_ore"
@@ -16,7 +16,7 @@ items:
material: paper
custom-model-data: 1011
data:
display-name: "<!i><i18n:item.deepslate_topaz_ore>"
item-name: "<!i><i18n:item.deepslate_topaz_ore>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/deepslate_topaz_ore"
@@ -28,8 +28,13 @@ items:
default:topaz:
material: paper
custom-model-data: 1012
settings:
anvil-repair-item:
- target:
- "#topaz_tools"
percent: 0.25
data:
display-name: "<!i><#FF8C00><i18n:item.topaz>"
item-name: "<!i><#FF8C00><i18n:item.topaz>"
model:
template: models:generated
arguments:

View File

@@ -9,7 +9,7 @@ items:
- "minecraft:logs"
- "minecraft:logs_that_burn"
data:
display-name: "<!i><i18n:item.palm_log>"
item-name: "<!i><i18n:item.palm_log>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/palm_log"
@@ -55,7 +55,7 @@ items:
- "minecraft:logs"
- "minecraft:logs_that_burn"
data:
display-name: "<!i><i18n:item.stripped_palm_log>"
item-name: "<!i><i18n:item.stripped_palm_log>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/stripped_palm_log"
@@ -98,7 +98,7 @@ items:
- "minecraft:logs"
- "minecraft:logs_that_burn"
data:
display-name: "<!i><i18n:item.palm_wood>"
item-name: "<!i><i18n:item.palm_wood>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/palm_wood"
@@ -144,7 +144,7 @@ items:
- "minecraft:logs"
- "minecraft:logs_that_burn"
data:
display-name: "<!i><i18n:item.stripped_palm_wood>"
item-name: "<!i><i18n:item.stripped_palm_wood>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/stripped_palm_wood"
@@ -186,7 +186,7 @@ items:
- "minecraft:planks"
- "minecraft:wooden_tool_materials"
data:
display-name: "<!i><i18n:item.palm_planks>"
item-name: "<!i><i18n:item.palm_planks>"
model:
type: "minecraft:model"
path: "minecraft:item/custom/palm_planks"
@@ -218,7 +218,7 @@ items:
settings:
fuel-time: 100
data:
display-name: "<!i><i18n:item.palm_sapling>"
item-name: "<!i><i18n:item.palm_sapling>"
model:
template: models:generated
arguments:
@@ -271,7 +271,7 @@ items:
material: oak_leaves
custom-model-data: 1000
data:
display-name: "<!i><i18n:item.palm_leaves>"
item-name: "<!i><i18n:item.palm_leaves>"
components:
minecraft:block_state:
distance: "1"

View File

@@ -1,5 +1,4 @@
{
"credit": "XiaoMoMi",
"textures": {
"0": "block/custom/fairy_flower_1",
"particle": "block/custom/fairy_flower_1"

View File

@@ -1,9 +1,7 @@
{
"credit": "MadewithBlockbench",
"texture_size": [64, 64],
"textures": {
"0": "item/custom/bench",
"particle": "item/custom/bench"
"0": "item/custom/bench"
},
"elements": [
{

View File

@@ -1,9 +1,7 @@
{
"credit": "Made with Blockbench",
"texture_size": [32, 32],
"textures": {
"0": "item/custom/table_lamp",
"particle": "item/custom/table_lamp"
"0": "item/custom/table_lamp"
},
"elements": [
{

View File

@@ -1,8 +1,7 @@
{
"credit": "Made with Blockbench",
"texture_size": [32, 32],
"textures": {
"1": "item/custom/wooden_chair"
"0": "item/custom/wooden_chair"
},
"elements": [
{
@@ -10,12 +9,12 @@
"to": [5.25, 7.25, 5.25],
"rotation": {"angle": 0, "axis": "y", "origin": [4.5, 4, 4.5]},
"faces": {
"north": {"uv": [15.5, 0.5, 16, 4], "texture": "#1"},
"east": {"uv": [15, 0.5, 15.5, 4], "texture": "#1"},
"south": {"uv": [15, 0.5, 15.5, 4], "texture": "#1"},
"west": {"uv": [15.5, 0.5, 16, 4], "texture": "#1"},
"up": {"uv": [16, 0.5, 15.5, 0], "texture": "#1"},
"down": {"uv": [15.5, 0, 15, 0.5], "texture": "#1"}
"north": {"uv": [15.5, 0.5, 16, 4], "texture": "#0"},
"east": {"uv": [15, 0.5, 15.5, 4], "texture": "#0"},
"south": {"uv": [15, 0.5, 15.5, 4], "texture": "#0"},
"west": {"uv": [15.5, 0.5, 16, 4], "texture": "#0"},
"up": {"uv": [16, 0.5, 15.5, 0], "texture": "#0"},
"down": {"uv": [15.5, 0, 15, 0.5], "texture": "#0"}
}
},
{
@@ -23,12 +22,12 @@
"to": [12.25, 7.25, 5.25],
"rotation": {"angle": 0, "axis": "y", "origin": [11.5, 3.5, 4.5]},
"faces": {
"north": {"uv": [16, 0.5, 15.5, 4], "texture": "#1"},
"east": {"uv": [16, 0.5, 15.5, 4], "texture": "#1"},
"south": {"uv": [15.5, 0.5, 15, 4], "texture": "#1"},
"west": {"uv": [15.5, 0.5, 15, 4], "texture": "#1"},
"up": {"uv": [15.5, 0.5, 16, 0], "texture": "#1"},
"down": {"uv": [15, 0, 15.5, 0.5], "texture": "#1"}
"north": {"uv": [16, 0.5, 15.5, 4], "texture": "#0"},
"east": {"uv": [16, 0.5, 15.5, 4], "texture": "#0"},
"south": {"uv": [15.5, 0.5, 15, 4], "texture": "#0"},
"west": {"uv": [15.5, 0.5, 15, 4], "texture": "#0"},
"up": {"uv": [15.5, 0.5, 16, 0], "texture": "#0"},
"down": {"uv": [15, 0, 15.5, 0.5], "texture": "#0"}
}
},
{
@@ -36,12 +35,12 @@
"to": [12.25, 7.25, 12.25],
"rotation": {"angle": 0, "axis": "y", "origin": [11.5, 4, 11.5]},
"faces": {
"north": {"uv": [15, 0.5, 15.5, 4], "texture": "#1"},
"east": {"uv": [15.5, 0.5, 16, 4], "texture": "#1"},
"south": {"uv": [15.5, 0.5, 16, 4], "texture": "#1"},
"west": {"uv": [15, 0.5, 15.5, 4], "texture": "#1"},
"up": {"uv": [15.5, 0, 16, 0.5], "texture": "#1"},
"down": {"uv": [15, 0.5, 15.5, 0], "texture": "#1"}
"north": {"uv": [15, 0.5, 15.5, 4], "texture": "#0"},
"east": {"uv": [15.5, 0.5, 16, 4], "texture": "#0"},
"south": {"uv": [15.5, 0.5, 16, 4], "texture": "#0"},
"west": {"uv": [15, 0.5, 15.5, 4], "texture": "#0"},
"up": {"uv": [15.5, 0, 16, 0.5], "texture": "#0"},
"down": {"uv": [15, 0.5, 15.5, 0], "texture": "#0"}
}
},
{
@@ -49,12 +48,12 @@
"to": [5.25, 7.25, 12.25],
"rotation": {"angle": 0, "axis": "y", "origin": [4.5, 4, 11.5]},
"faces": {
"north": {"uv": [15.5, 0.5, 15, 4], "texture": "#1"},
"east": {"uv": [15.5, 0.5, 15, 4], "texture": "#1"},
"south": {"uv": [16, 0.5, 15.5, 4], "texture": "#1"},
"west": {"uv": [16, 0.5, 15.5, 4], "texture": "#1"},
"up": {"uv": [16, 0, 15.5, 0.5], "texture": "#1"},
"down": {"uv": [15.5, 0.5, 15, 0], "texture": "#1"}
"north": {"uv": [15.5, 0.5, 15, 4], "texture": "#0"},
"east": {"uv": [15.5, 0.5, 15, 4], "texture": "#0"},
"south": {"uv": [16, 0.5, 15.5, 4], "texture": "#0"},
"west": {"uv": [16, 0.5, 15.5, 4], "texture": "#0"},
"up": {"uv": [16, 0, 15.5, 0.5], "texture": "#0"},
"down": {"uv": [15.5, 0.5, 15, 0], "texture": "#0"}
}
},
{
@@ -62,12 +61,12 @@
"to": [12, 17, 12],
"rotation": {"angle": 0, "axis": "y", "origin": [4, 9, 14]},
"faces": {
"north": {"uv": [4, 5, 0, 9], "texture": "#1"},
"east": {"uv": [0, 0, 0, 4], "texture": "#1"},
"south": {"uv": [0, 5, 4, 9], "texture": "#1"},
"west": {"uv": [0, 0, 0, 4], "texture": "#1"},
"up": {"uv": [4, 0, 0, 0], "texture": "#1"},
"down": {"uv": [4, 0, 0, 0], "texture": "#1"}
"north": {"uv": [4, 5, 0, 9], "texture": "#0"},
"east": {"uv": [0, 0, 0, 4], "texture": "#0"},
"south": {"uv": [0, 5, 4, 9], "texture": "#0"},
"west": {"uv": [0, 0, 0, 4], "texture": "#0"},
"up": {"uv": [4, 0, 0, 0], "texture": "#0"},
"down": {"uv": [4, 0, 0, 0], "texture": "#0"}
}
},
{
@@ -75,12 +74,12 @@
"to": [12, 18.5, 12.5],
"rotation": {"angle": 0, "axis": "y", "origin": [4, 17, 14]},
"faces": {
"north": {"uv": [8, 5, 4, 6], "texture": "#1"},
"east": {"uv": [8, 5, 8.5, 6], "texture": "#1"},
"south": {"uv": [4, 5, 8, 6], "texture": "#1"},
"west": {"uv": [8, 5, 8.5, 6], "texture": "#1"},
"up": {"uv": [8, 7, 4, 6.5], "texture": "#1"},
"down": {"uv": [8, 6, 4, 6.5], "texture": "#1"}
"north": {"uv": [8, 5, 4, 6], "texture": "#0"},
"east": {"uv": [8, 5, 8.5, 6], "texture": "#0"},
"south": {"uv": [4, 5, 8, 6], "texture": "#0"},
"west": {"uv": [8, 5, 8.5, 6], "texture": "#0"},
"up": {"uv": [8, 7, 4, 6.5], "texture": "#0"},
"down": {"uv": [8, 6, 4, 6.5], "texture": "#0"}
}
},
{
@@ -88,12 +87,12 @@
"to": [4, 19, 13],
"rotation": {"angle": 0, "axis": "y", "origin": [3, 9, 13]},
"faces": {
"north": {"uv": [0.5, 11, 1, 16], "texture": "#1"},
"east": {"uv": [2, 11, 3, 16], "texture": "#1"},
"south": {"uv": [0, 11, 0.5, 16], "texture": "#1"},
"west": {"uv": [1, 11, 2, 16], "texture": "#1"},
"up": {"uv": [2, 11, 1, 10.5], "rotation": 90, "texture": "#1"},
"down": {"uv": [2, 11, 3, 10.5], "rotation": 90, "texture": "#1"}
"north": {"uv": [0.5, 11, 1, 16], "texture": "#0"},
"east": {"uv": [2, 11, 3, 16], "texture": "#0"},
"south": {"uv": [0, 11, 0.5, 16], "texture": "#0"},
"west": {"uv": [1, 11, 2, 16], "texture": "#0"},
"up": {"uv": [2, 11, 1, 10.5], "rotation": 90, "texture": "#0"},
"down": {"uv": [2, 11, 3, 10.5], "rotation": 90, "texture": "#0"}
}
},
{
@@ -101,12 +100,12 @@
"to": [13, 19, 13],
"rotation": {"angle": 0, "axis": "y", "origin": [13, 9, 13]},
"faces": {
"north": {"uv": [1, 11, 0.5, 16], "texture": "#1"},
"east": {"uv": [2, 11, 1, 16], "texture": "#1"},
"south": {"uv": [0.5, 11, 0, 16], "texture": "#1"},
"west": {"uv": [3, 11, 2, 16], "texture": "#1"},
"up": {"uv": [2, 10.5, 1, 11], "rotation": 90, "texture": "#1"},
"down": {"uv": [2, 10.5, 3, 11], "rotation": 90, "texture": "#1"}
"north": {"uv": [1, 11, 0.5, 16], "texture": "#0"},
"east": {"uv": [2, 11, 1, 16], "texture": "#0"},
"south": {"uv": [0.5, 11, 0, 16], "texture": "#0"},
"west": {"uv": [3, 11, 2, 16], "texture": "#0"},
"up": {"uv": [2, 10.5, 1, 11], "rotation": 90, "texture": "#0"},
"down": {"uv": [2, 10.5, 3, 11], "rotation": 90, "texture": "#0"}
}
},
{
@@ -114,12 +113,12 @@
"to": [13, 9, 13],
"rotation": {"angle": 0, "axis": "y", "origin": [3, 7, 5]},
"faces": {
"north": {"uv": [10, 2, 15, 3], "texture": "#1"},
"east": {"uv": [10, 0, 15, 1], "texture": "#1"},
"south": {"uv": [10, 1, 15, 2], "texture": "#1"},
"west": {"uv": [15, 0, 10, 1], "texture": "#1"},
"up": {"uv": [5, 5, 0, 0], "texture": "#1"},
"down": {"uv": [10, 0, 5, 5], "texture": "#1"}
"north": {"uv": [10, 2, 15, 3], "texture": "#0"},
"east": {"uv": [10, 0, 15, 1], "texture": "#0"},
"south": {"uv": [10, 1, 15, 2], "texture": "#0"},
"west": {"uv": [15, 0, 10, 1], "texture": "#0"},
"up": {"uv": [5, 5, 0, 0], "texture": "#0"},
"down": {"uv": [10, 0, 5, 5], "texture": "#0"}
}
}
],

View File

@@ -65,7 +65,7 @@ templates:
material: arrow
custom-model-data: "{model_data}"
data:
display-name: "{name}"
item-name: "{name}"
lore: "{lore}"
model:
template: models:generated
@@ -117,28 +117,28 @@ items:
material: arrow
custom-model-data: 1000
data:
display-name: "<!i><#FAFAD2><i18n:internal.next_recipe>"
item-name: "<!i><#FAFAD2><i18n:internal.next_recipe>"
lore:
- "<!i><#F5F5F5><arg:current_page>/<arg:max_page>"
internal:next_recipe_1:
material: arrow
custom-model-data: 1001
data:
display-name: "<!i><#808080><i18n:internal.next_recipe>"
item-name: "<!i><#808080><i18n:internal.next_recipe>"
lore:
- "<!i><#696969><arg:current_page>/<arg:max_page>"
internal:previous_recipe_0:
material: arrow
custom-model-data: 1002
data:
display-name: "<!i><#FAFAD2><i18n:internal.previous_recipe>"
item-name: "<!i><#FAFAD2><i18n:internal.previous_recipe>"
lore:
- "<!i><#F5F5F5><arg:current_page>/<arg:max_page>"
internal:previous_recipe_1:
material: arrow
custom-model-data: 1003
data:
display-name: "<!i><#808080><i18n:internal.previous_recipe>"
item-name: "<!i><#808080><i18n:internal.previous_recipe>"
lore:
- "<!i><#696969><arg:current_page>/<arg:max_page>"
internal:get_item:

View File

@@ -1,11 +1,40 @@
package net.momirealms.craftengine.bukkit.util;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.Nullable;
public class LegacyInventoryUtils {
public static Inventory getTopInventory(Player player) {
return player.getOpenInventory().getTopInventory();
}
public static void setRepairCost(AnvilInventory anvilInventory, int repairCost) {
anvilInventory.setRepairCost(repairCost);
}
public static void setRepairCostAmount(AnvilInventory anvilInventory, int amount) {
anvilInventory.setRepairCostAmount(amount);
}
@Nullable
public static String getRenameText(AnvilInventory anvilInventory) {
return anvilInventory.getRenameText();
}
public static int getMaxRepairCost(AnvilInventory anvilInventory) {
return anvilInventory.getMaximumRepairCost();
}
public static int getRepairCost(AnvilInventory anvilInventory) {
return anvilInventory.getRepairCost();
}
public static InventoryView getView(PrepareAnvilEvent event) {
return event.getView();
}
}

View File

@@ -21,6 +21,8 @@ import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.pack.misc.EquipmentGeneration;
import net.momirealms.craftengine.core.pack.model.*;
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
import net.momirealms.craftengine.core.pack.model.select.ChargeTypeSelectProperty;
import net.momirealms.craftengine.core.pack.model.select.TrimMaterialSelectProperty;
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
@@ -454,13 +456,19 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
for (Map.Entry<Either<String, List<String>>, ItemModel> entry : model.whenMap().entrySet()) {
List<String> cases = entry.getKey().fallbackOrMapPrimary(List::of);
for (String caseValue : cases) {
Number legacyValue = predicate.toLegacyValue(caseValue);
if (predicate instanceof TrimMaterialSelectProperty property && property.isArmor(materialId)) {
if (legacyValue.floatValue() > 1f) {
continue;
}
}
Map<String, Object> merged = mergePredicates(
parentPredicates,
predicateId,
predicate.toLegacyValue(caseValue)
legacyValue
);
// Additional check for crossbow
if (materialId.equals(ItemKeys.CROSSBOW)) {
if (predicate instanceof ChargeTypeSelectProperty && materialId.equals(ItemKeys.CROSSBOW)) {
merged = mergePredicates(
merged,
"charged",
@@ -477,19 +485,32 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
}
}
// Additional check for crossbow
if (model.fallBack() != null && materialId.equals(ItemKeys.CROSSBOW)) {
Map<String, Object> merged = mergePredicates(
parentPredicates,
"charged",
0
);
processModelRecursively(
model.fallBack(),
merged,
resultList,
materialId,
customModelData
);
if (model.fallBack() != null) {
if (predicate instanceof ChargeTypeSelectProperty && materialId.equals(ItemKeys.CROSSBOW)) {
processModelRecursively(
model.fallBack(),
mergePredicates(
parentPredicates,
"charged",
0
),
resultList,
materialId,
customModelData
);
} else if (predicate instanceof TrimMaterialSelectProperty property && property.isArmor(materialId)) {
processModelRecursively(
model.fallBack(),
mergePredicates(
parentPredicates,
"trim_type",
0f
),
resultList,
materialId,
customModelData
);
}
}
}
}

View File

@@ -62,7 +62,7 @@ public class ComponentItemFactory extends BukkitItemFactory {
}
@Override
protected void displayName(ItemWrapper<ItemStack> item, String json) {
protected void customName(ItemWrapper<ItemStack> item, String json) {
if (json == null) {
item.removeComponent(ComponentKeys.CUSTOM_NAME);
} else {
@@ -71,7 +71,7 @@ public class ComponentItemFactory extends BukkitItemFactory {
}
@Override
protected Optional<String> displayName(ItemWrapper<ItemStack> item) {
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.CUSTOM_NAME)) return Optional.empty();
return Optional.ofNullable(
(String) ComponentType.encodeJava(
@@ -272,4 +272,19 @@ public class ComponentItemFactory extends BukkitItemFactory {
item.setComponent(ComponentKeys.MAX_STACK_SIZE, maxStackSize);
}
}
@Override
protected void repairCost(ItemWrapper<ItemStack> item, Integer data) {
if (data == null) {
item.removeComponent(ComponentKeys.REPAIR_COST);
} else {
item.setComponent(ComponentKeys.REPAIR_COST, data);
}
}
@Override
protected Optional<Integer> repairCost(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.REPAIR_COST)) return Optional.empty();
return Optional.ofNullable((Integer) ComponentType.encodeJava(ComponentKeys.REPAIR_COST, item.getComponent(ComponentKeys.REPAIR_COST)).orElse(null));
}
}

View File

@@ -23,7 +23,7 @@ public class UniversalItemFactory extends BukkitItemFactory {
}
@Override
protected void displayName(ItemWrapper<ItemStack> item, String json) {
protected void customName(ItemWrapper<ItemStack> item, String json) {
if (json != null) {
item.set(json, "display", "Name");
} else {
@@ -32,19 +32,19 @@ public class UniversalItemFactory extends BukkitItemFactory {
}
@Override
protected Optional<String> displayName(ItemWrapper<ItemStack> item) {
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
if (!item.hasTag("display", "Name")) return Optional.empty();
return Optional.of(item.get("display", "Name"));
}
@Override
protected void itemName(ItemWrapper<ItemStack> item, String json) {
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
customName(item, json);
}
@Override
protected Optional<String> itemName(ItemWrapper<ItemStack> item) {
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
return customName(item);
}
@Override
@@ -218,4 +218,15 @@ public class UniversalItemFactory extends BukkitItemFactory {
@Override
protected void maxStackSize(ItemWrapper<ItemStack> item, Integer maxStackSize) {
}
@Override
protected void repairCost(ItemWrapper<ItemStack> item, Integer data) {
item.set(data, "RepairCost");
}
@Override
protected Optional<Integer> repairCost(ItemWrapper<ItemStack> item) {
if (!item.hasTag("RepairCost")) return Optional.empty();
return Optional.of(item.get("RepairCost"));
}
}

View File

@@ -1,15 +1,17 @@
package net.momirealms.craftengine.bukkit.item.recipe;
import com.destroystokyo.paper.event.inventory.PrepareResultEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.bukkit.util.LegacyInventoryUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemBuildContext;
import net.momirealms.craftengine.core.item.ItemManager;
import net.momirealms.craftengine.core.item.*;
import net.momirealms.craftengine.core.item.recipe.CustomCampfireRecipe;
import net.momirealms.craftengine.core.item.recipe.OptimizedIDItem;
import net.momirealms.craftengine.core.item.recipe.Recipe;
@@ -19,8 +21,7 @@ import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -34,11 +35,13 @@ import org.bukkit.event.block.*;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.*;
import org.bukkit.inventory.view.AnvilView;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@SuppressWarnings("DuplicatedCode")
public class RecipeEventListener implements Listener {
private static final OptimizedIDItem<ItemStack> EMPTY = new OptimizedIDItem<>(null, null);
private final ItemManager<ItemStack> itemManager;
@@ -364,6 +367,7 @@ public class RecipeEventListener implements Listener {
}
// for 1.21.2+
@SuppressWarnings("UnstableApiUsage")
@EventHandler(ignoreCancelled = true)
public void onCampfireCook(CampfireStartEvent event) {
if (!ConfigManager.enableRecipeSystem()) return;
@@ -402,6 +406,8 @@ public class RecipeEventListener implements Listener {
Material type = event.getBlock().getType();
if (type != Material.CAMPFIRE && type != Material.SOUL_CAMPFIRE) return;
CampfireRecipe recipe = (CampfireRecipe) event.getRecipe();
if (recipe == null) return;
Key recipeId = new Key(recipe.getKey().namespace(), recipe.getKey().value());
boolean isCustom = this.recipeManager.isCustomRecipe(recipeId);
@@ -430,7 +436,7 @@ public class RecipeEventListener implements Listener {
// Paper only
@EventHandler
public void onPrepareResult(PrepareResultEvent event) {
if (!ConfigManager.enableRecipeSystem()) return;
// if (!ConfigManager.enableRecipeSystem()) return;
if (event.getInventory() instanceof CartographyInventory cartographyInventory) {
if (ItemUtils.hasCustomItem(cartographyInventory.getStorageContents())) {
event.setResult(new ItemStack(Material.AIR));
@@ -438,18 +444,298 @@ public class RecipeEventListener implements Listener {
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onAnvilCombineItems(PrepareAnvilEvent event) {
AnvilInventory inventory = event.getInventory();
ItemStack first = inventory.getFirstItem();
ItemStack second = inventory.getSecondItem();
if (first == null || second == null) return;
Item<ItemStack> wrappedFirst = BukkitItemManager.instance().wrap(first);
boolean firstCustom = wrappedFirst.isCustomItem();
Item<ItemStack> wrappedSecond = BukkitItemManager.instance().wrap(second);
boolean secondCustom = wrappedSecond.isCustomItem();
// both are vanilla items
if (!firstCustom && !secondCustom) {
return;
}
// both of them are custom items
// if the second is an enchanted book, then apply it
if (wrappedSecond.vanillaId().equals(ItemKeys.ENCHANTED_BOOK)) {
return;
}
// one of them is vanilla item
if (!firstCustom || !secondCustom) {
// block "vanilla + custom" recipes
event.setResult(null);
return;
}
// not the same item
if (!wrappedFirst.customId().equals(wrappedSecond.customId())) {
event.setResult(null);
return;
}
// can not repair
wrappedFirst.getCustomItem().ifPresent(it -> {
if (!it.settings().canRepair()) {
event.setResult(null);
}
});
}
@SuppressWarnings("UnstableApiUsage")
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onAnvilRepairItems(PrepareAnvilEvent event) {
AnvilInventory inventory = event.getInventory();
ItemStack first = inventory.getFirstItem();
ItemStack second = inventory.getSecondItem();
if (first == null || second == null) return;
Item<ItemStack> wrappedSecond = BukkitItemManager.instance().wrap(second);
// if the second slot is not a custom item, ignore it
Optional<CustomItem<ItemStack>> customItemOptional = plugin.itemManager().getCustomItem(wrappedSecond.id());
if (customItemOptional.isEmpty()) {
return;
}
CustomItem<ItemStack> customItem = customItemOptional.get();
List<AnvilRepairItem> repairItems = customItem.settings().repairItems();
// if the second slot is not a repair item, ignore it
if (repairItems.isEmpty()) {
return;
}
Item<ItemStack> wrappedFirst = BukkitItemManager.instance().wrap(first);
int maxDamage = wrappedFirst.maxDamage().orElse(0);
int damage = wrappedFirst.damage().orElse(0);
// not a repairable item
if (damage == 0 || maxDamage == 0) return;
Key firstId = wrappedFirst.id();
Optional<CustomItem<ItemStack>> optionalCustomTool = wrappedFirst.getCustomItem();
// can not repair
if (optionalCustomTool.isPresent() && !optionalCustomTool.get().settings().canRepair()) {
return;
}
AnvilRepairItem repairItem = null;
for (AnvilRepairItem item : repairItems) {
for (String target : item.targets()) {
if (target.charAt(0) == '#') {
Key tag = Key.of(target.substring(1));
if (optionalCustomTool.isPresent() && optionalCustomTool.get().is(tag)) {
repairItem = item;
break;
}
if (wrappedFirst.is(tag)) {
repairItem = item;
break;
}
} else if (target.equals(firstId.toString())) {
repairItem = item;
break;
}
}
}
// no repair item matching
if (repairItem == null) {
return;
}
boolean hasResult = true;
int realDurabilityPerItem = (int) (repairItem.amount() + repairItem.percent() * maxDamage);
int consumeMaxAmount = damage / realDurabilityPerItem + 1;
int actualConsumedAmount = Math.min(consumeMaxAmount, wrappedSecond.count());
int actualRepairAmount = actualConsumedAmount * realDurabilityPerItem;
int damageAfter = Math.max(damage - actualRepairAmount, 0);
wrappedFirst.damage(damageAfter);
String renameText;
int maxRepairCost;
int previousCost;
if (VersionHelper.isVersionNewerThan1_21_2()) {
AnvilView anvilView = event.getView();
renameText = anvilView.getRenameText();
maxRepairCost = anvilView.getMaximumRepairCost();
previousCost = anvilView.getRepairCost();
} else {
renameText = LegacyInventoryUtils.getRenameText(inventory);
maxRepairCost = LegacyInventoryUtils.getMaxRepairCost(inventory);
previousCost = LegacyInventoryUtils.getRepairCost(inventory);
}
int repairCost = actualConsumedAmount;
int repairPenalty = wrappedFirst.repairCost().orElse(0) + wrappedSecond.repairCost().orElse(0);
if (renameText != null && !renameText.isBlank()) {
try {
if (!renameText.equals(Reflections.method$Component$getString.invoke(ComponentUtils.jsonToMinecraft(wrappedFirst.hoverName().orElse(AdventureHelper.EMPTY_COMPONENT))))) {
wrappedFirst.customName(AdventureHelper.componentToJson(Component.text(renameText)));
repairCost += 1;
} else if (repairCost == 0) {
hasResult = false;
}
} catch (ReflectiveOperationException e) {
plugin.logger().warn("Failed to get hover name", e);
}
} else if (VersionHelper.isVersionNewerThan1_20_5() && wrappedFirst.hasComponent(ComponentKeys.CUSTOM_NAME)) {
repairCost += 1;
wrappedFirst.customName(null);
} else if (!VersionHelper.isVersionNewerThan1_20_5() && wrappedFirst.hasTag("display", "Name")) {
repairCost += 1;
wrappedFirst.customName(null);
}
int finalCost = repairCost + repairPenalty;
// To fix some client side visual issues
try {
Object anvilMenu;
if (VersionHelper.isVersionNewerThan1_21()) {
anvilMenu = Reflections.field$CraftInventoryView$container.get(event.getView());
} else {
anvilMenu = Reflections.field$CraftInventoryAnvil$menu.get(inventory);
}
Reflections.method$AbstractContainerMenu$broadcastFullState.invoke(anvilMenu);
} catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to broadcast changes", e);
}
if (VersionHelper.isVersionNewerThan1_21()) {
AnvilView anvilView = event.getView();
anvilView.setRepairCost(finalCost);
anvilView.setRepairItemCountCost(actualConsumedAmount);
} else {
LegacyInventoryUtils.setRepairCost(inventory, finalCost);
LegacyInventoryUtils.setRepairCostAmount(inventory, actualConsumedAmount);
}
Player player;
try {
player = (Player) Reflections.method$InventoryView$getPlayer.invoke(VersionHelper.isVersionNewerThan1_21() ? event.getView() : LegacyInventoryUtils.getView(event));
} catch (ReflectiveOperationException e) {
plugin.logger().warn("Failed to get inventory viewer", e);
return;
}
if (finalCost >= maxRepairCost && !plugin.adapt(player).canInstabuild()) {
hasResult = false;
}
if (hasResult) {
int afterPenalty = wrappedFirst.repairCost().orElse(0);
int anotherPenalty = wrappedSecond.repairCost().orElse(0);
if (afterPenalty < anotherPenalty) {
afterPenalty = anotherPenalty;
}
afterPenalty = calculateIncreasedRepairCost(afterPenalty);
wrappedFirst.repairCost(afterPenalty);
event.setResult(wrappedFirst.loadCopy());
}
}
public static int calculateIncreasedRepairCost(int cost) {
return (int) Math.min((long) cost * 2L + 1L, 2147483647L);
}
// only handle repair items for the moment
@EventHandler(ignoreCancelled = true)
public void onSpecialRecipe(PrepareItemCraftEvent event) {
if (!ConfigManager.enableRecipeSystem()) return;
// if (!ConfigManager.enableRecipeSystem()) return;
org.bukkit.inventory.Recipe recipe = event.getRecipe();
if (recipe == null)
return;
if (!(recipe instanceof ComplexRecipe))
if (!(recipe instanceof ComplexRecipe complexRecipe))
return;
CraftingInventory inventory = event.getInventory();
if (ItemUtils.hasCustomItem(inventory.getMatrix())) {
inventory.setResult(null);
boolean hasCustomItem = ItemUtils.hasCustomItem(inventory.getMatrix());
if (!hasCustomItem) {
return;
}
if (!Reflections.clazz$CraftComplexRecipe.isInstance(complexRecipe)) {
inventory.setResult(null);
return;
}
try {
Object mcRecipe = Reflections.field$CraftComplexRecipe$recipe.get(complexRecipe);
if (!Reflections.clazz$RepairItemRecipe.isInstance(mcRecipe)) {
inventory.setResult(null);
return;
}
// repair item
ItemStack[] itemStacks = inventory.getMatrix();
Pair<ItemStack, ItemStack> onlyTwoItems = getTheOnlyTwoItem(itemStacks);
if (onlyTwoItems.left() == null || onlyTwoItems.right() == null) {
inventory.setResult(null);
return;
}
Item<ItemStack> left = plugin.itemManager().wrap(onlyTwoItems.left());
Item<ItemStack> right = plugin.itemManager().wrap(onlyTwoItems.right());
if (!left.id().equals(right.id())) {
inventory.setResult(null);
return;
}
int totalDamage = right.damage().orElse(0) + left.damage().orElse(0);
int totalMaxDamage = left.maxDamage().get() + right.maxDamage().get();
// should be impossible, but take care
if (totalDamage >= totalMaxDamage) {
inventory.setResult(null);
return;
}
Player player;
try {
player = (Player) Reflections.method$InventoryView$getPlayer.invoke(event.getView());
} catch (ReflectiveOperationException e) {
plugin.logger().warn("Failed to get inventory viewer", e);
return;
}
Optional<CustomItem<ItemStack>> customItemOptional = plugin.itemManager().getCustomItem(left.id());
if (customItemOptional.isEmpty()) {
inventory.setResult(null);
return;
}
CustomItem<ItemStack> customItem = customItemOptional.get();
if (!customItem.settings().canRepair()) {
inventory.setResult(null);
return;
}
Item<ItemStack> newItem = customItem.buildItem(ItemBuildContext.of(plugin.adapt(player), ContextHolder.EMPTY));
int remainingDurability = totalMaxDamage - totalDamage;
int newItemDamage = Math.max(0, newItem.maxDamage().get() - remainingDurability);
newItem.damage(newItemDamage);
inventory.setResult(newItem.load());
} catch (Exception e) {
this.plugin.logger().warn("Failed to handle minecraft custom recipe", e);
}
}
private Pair<ItemStack, ItemStack> getTheOnlyTwoItem(ItemStack[] matrix) {
ItemStack first = null;
ItemStack second = null;
for (ItemStack itemStack : matrix) {
if (itemStack == null) continue;
if (first == null) {
first = itemStack;
} else if (second == null) {
second = itemStack;
}
}
return new Pair<>(first, second);
}
@EventHandler(ignoreCancelled = true)

View File

@@ -10,6 +10,10 @@ public class ComponentUtils {
public static Object adventureToMinecraft(Component component) {
String json = AdventureHelper.componentToJson(component);
return jsonToMinecraft(json);
}
public static Object jsonToMinecraft(String json) {
if (VersionHelper.isVersionNewerThan1_20_5()) {
try {
return Reflections.method$Component$Serializer$fromJson.invoke(null, json, Reflections.instance$MinecraftRegistry);

View File

@@ -72,6 +72,12 @@ public class Reflections {
)
);
public static final Method method$Component$getString = requireNonNull(
ReflectionUtils.getMethod(
clazz$Component, String.class, new String[]{"getString", "a"}
)
);
public static final Class<?> clazz$RandomSource = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("util.RandomSource")
@@ -4722,6 +4728,18 @@ public class Reflections {
)
);
public static final Method method$AbstractContainerMenu$broadcastChanges = requireNonNull(
ReflectionUtils.getMethod(
clazz$AbstractContainerMenu, void.class, new String[]{ "broadcastChanges", "d" }
)
);
public static final Method method$AbstractContainerMenu$broadcastFullState = requireNonNull(
ReflectionUtils.getMethod(
clazz$AbstractContainerMenu, void.class, new String[]{ "broadcastFullState", "e" }
)
);
public static final Class<?> clazz$CraftContainer = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleCBClass("inventory.CraftContainer")
@@ -4860,4 +4878,59 @@ public class Reflections {
clazz$FluidState, clazz$Fluid
)
);
public static final Class<?> clazz$CraftComplexRecipe = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleCBClass("inventory.CraftComplexRecipe")
)
);
public static final Class<?> clazz$CustomRecipe = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("world.item.crafting.CustomRecipe"),
BukkitReflectionUtils.assembleMCClass("world.item.crafting.IRecipeComplex")
)
);
public static final Class<?> clazz$RepairItemRecipe = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("world.item.crafting.RepairItemRecipe"),
BukkitReflectionUtils.assembleMCClass("world.item.crafting.RecipeRepair")
)
);
public static final Field field$CraftComplexRecipe$recipe = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$CraftComplexRecipe, clazz$CustomRecipe, 0
)
);
public static final Class<?> clazz$CraftInventoryAnvil = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleCBClass("inventory.CraftInventoryAnvil")
)
);
public static final Class<?> clazz$AnvilMenu = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("world.inventory.AnvilMenu"),
BukkitReflectionUtils.assembleMCClass("world.inventory.ContainerAnvil")
)
);
// 1.21+
public static final Class<?> clazz$CraftInventoryView =
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleCBClass("inventory.CraftInventoryView")
);
// 1.21+
public static final Field field$CraftInventoryView$container = Optional.ofNullable(clazz$CraftInventoryView)
.map(it -> ReflectionUtils.getDeclaredField(it, 0)).orElse(null);
// 1.20-1.20.6
public static final Field field$CraftInventoryAnvil$menu =
ReflectionUtils.getDeclaredField(
clazz$CraftInventoryAnvil, clazz$AnvilMenu, 0
);
}

View File

@@ -26,6 +26,17 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
return this.factory.damage(this.item);
}
@Override
public Item<I> repairCost(Integer data) {
this.factory.repairCost(this.item, data);
return this;
}
@Override
public Optional<Integer> repairCost() {
return this.factory.repairCost(this.item);
}
@Override
public Item<I> maxDamage(Integer data) {
this.factory.maxDamage(this.item, data);
@@ -96,8 +107,8 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
}
@Override
public Optional<String> displayName() {
return this.factory.displayName(this.item);
public Optional<String> customName() {
return this.factory.customName(this.item);
}
@Override
@@ -128,8 +139,8 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
}
@Override
public Item<I> displayName(String displayName) {
this.factory.displayName(this.item, displayName);
public Item<I> customName(String displayName) {
this.factory.customName(this.item, displayName);
return this;
}
@Override

View File

@@ -168,7 +168,11 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
registerDataFunction((obj) -> {
String name = obj.toString();
return new DisplayNameModifier<>(name);
}, "name", "display-name", "custom-name");
}, "custom-name");
registerDataFunction((obj) -> {
String name = obj.toString();
return new ItemNameModifier<>(name);
}, "item-name", "display-name");
registerDataFunction((obj) -> {
List<String> name = MiscUtils.getAsStringList(obj);
return new LoreModifier<>(name);
@@ -197,12 +201,6 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
String pattern = data.get("pattern").toString().toLowerCase(Locale.ENGLISH);
return new TrimModifier<>(material, pattern);
}, "trim");
if (VersionHelper.isVersionNewerThan1_20_5()) {
registerDataFunction((obj) -> {
String name = obj.toString();
return new ItemNameModifier<>(name);
}, "item-name");
}
if (VersionHelper.isVersionNewerThan1_20_5()) {
registerDataFunction((obj) -> {
Map<String, Object> data = MiscUtils.castToMap(obj, false);

View File

@@ -0,0 +1,6 @@
package net.momirealms.craftengine.core.item;
import java.util.List;
public record AnvilRepairItem(List<String> targets, int amount, double percent) {
}

View File

@@ -19,4 +19,5 @@ public class ComponentKeys {
public static final String TOOLTIP_STYLE = Key.key("minecraft", "tooltip_style").asString();
public static final String JUKEBOX_PLAYABLE = Key.key("minecraft", "jukebox_playable").asString();
public static final String TRIM = Key.key("minecraft", "trim").asString();
public static final String REPAIR_COST = Key.key("minecraft", "repair_cost").asString();
}

View File

@@ -19,6 +19,10 @@ public interface CustomItem<I> extends BuildableItem<I> {
ItemSettings settings();
default boolean is(Key tag) {
return settings().tags().contains(tag);
}
default Item<I> buildItem(Player player) {
return buildItem(new ItemBuildContext(player, ContextHolder.EMPTY));
}

View File

@@ -41,13 +41,21 @@ public interface Item<I> {
Optional<Integer> damage();
Item<I> repairCost(Integer data);
Optional<Integer> repairCost();
Item<I> maxDamage(Integer data);
Optional<Integer> maxDamage();
Item<I> displayName(String displayName);
Item<I> customName(String displayName);
Optional<String> displayName();
Optional<String> customName();
default Optional<String> hoverName() {
return customName().or(this::itemName);
}
Item<I> itemName(String itemName);

View File

@@ -49,9 +49,9 @@ public abstract class ItemFactory<P extends Plugin, W extends ItemWrapper<I>, I>
protected abstract Optional<Integer> customModelData(ItemWrapper<I> item);
protected abstract void displayName(ItemWrapper<I> item, String json);
protected abstract void customName(ItemWrapper<I> item, String json);
protected abstract Optional<String> displayName(ItemWrapper<I> item);
protected abstract Optional<String> customName(ItemWrapper<I> item);
protected abstract void itemName(ItemWrapper<I> item, String json);
@@ -104,4 +104,8 @@ public abstract class ItemFactory<P extends Plugin, W extends ItemWrapper<I>, I>
protected abstract boolean is(ItemWrapper<I> item, Key itemTag);
protected abstract boolean isBlockItem(ItemWrapper<I> item);
protected abstract void repairCost(ItemWrapper<I> item, Integer data);
protected abstract Optional<Integer> repairCost(ItemWrapper<I> item);
}

View File

@@ -16,13 +16,15 @@ public class ItemSettings {
Set<Key> tags = Set.of();
@Nullable
EquipmentGeneration equipment;
boolean canRepair = true;
List<AnvilRepairItem> anvilRepairItems = List.of();
private ItemSettings() {}
public <I> List<ItemModifier<I>> modifiers() {
ArrayList<ItemModifier<I>> modifiers = new ArrayList<>();
if (VersionHelper.isVersionNewerThan1_21_2() && this.equipment != null && this.equipment.modernData() != null) modifiers.add(new EquippableModifier<>(this.equipment.modernData()));
// TODO 1.20
return modifiers;
}
@@ -39,6 +41,8 @@ public class ItemSettings {
newSettings.fuelTime = settings.fuelTime;
newSettings.tags = settings.tags;
newSettings.equipment = settings.equipment;
newSettings.canRepair = settings.canRepair;
newSettings.anvilRepairItems = settings.anvilRepairItems;
return newSettings;
}
@@ -54,6 +58,10 @@ public class ItemSettings {
return settings;
}
public boolean canRepair() {
return canRepair;
}
public int fuelTime() {
return fuelTime;
}
@@ -62,11 +70,25 @@ public class ItemSettings {
return tags;
}
public List<AnvilRepairItem> repairItems() {
return anvilRepairItems;
}
@Nullable
public EquipmentGeneration equipment() {
return equipment;
}
public ItemSettings repairItems(List<AnvilRepairItem> items) {
this.anvilRepairItems = items;
return this;
}
public ItemSettings canRepair(boolean canRepair) {
this.canRepair = canRepair;
return this;
}
public ItemSettings fuelTime(int fuelTime) {
this.fuelTime = fuelTime;
return this;
@@ -98,6 +120,21 @@ public class ItemSettings {
private static final Map<String, ItemSettings.Modifier.Factory> FACTORIES = new HashMap<>();
static {
registerFactory("repairable", (value -> {
boolean bool = (boolean) value;
return settings -> settings.canRepair(bool);
}));
registerFactory("anvil-repair-item", (value -> {
@SuppressWarnings("unchecked")
List<Map<String, Object>> materials = (List<Map<String, Object>>) value;
List<AnvilRepairItem> anvilRepairItemList = new ArrayList<>();
for (Map<String, Object> material : materials) {
int amount = MiscUtils.getAsInt(material.getOrDefault("amount", 0));
double percent = MiscUtils.getAsDouble(material.getOrDefault("percent", 0));
anvilRepairItemList.add(new AnvilRepairItem(MiscUtils.getAsStringList(material.get("target")), amount, percent));
}
return settings -> settings.repairItems(anvilRepairItemList);
}));
registerFactory("fuel-time", (value -> {
int intValue = MiscUtils.getAsInt(value);
return settings -> settings.fuelTime(intValue);

View File

@@ -19,6 +19,6 @@ public class DisplayNameModifier<I> implements ItemModifier<I> {
@Override
public void apply(Item<I> item, ItemBuildContext context) {
item.displayName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(this.argument, context.tagResolvers())));
item.customName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(this.argument, context.tagResolvers())));
}
}

View File

@@ -2,14 +2,14 @@ package net.momirealms.craftengine.core.pack;
public class LoadingSequence {
public static final int TEMPLATE = 0;
public static final int BLOCK = 10;
public static final int ITEM = 20;
public static final int FURNITURE = 30;
public static final int FONT = 40;
public static final int RECIPE = 50;
public static final int CATEGORY = 60;
public static final int TRANSLATION = 70;
public static final int LANG = 80;
public static final int LANG = 10;
public static final int TRANSLATION = 20;
public static final int BLOCK = 30;
public static final int ITEM = 40;
public static final int FURNITURE = 50;
public static final int FONT = 60;
public static final int RECIPE = 70;
public static final int CATEGORY = 80;
public static final int SOUND = 90;
public static final int JUKEBOX_SONG = 100;
}

View File

@@ -22,7 +22,7 @@ public class TrimMaterialSelectProperty implements SelectProperty, LegacyModelPr
LEGACY_TRIM_DATA.put("minecraft:lapis", 0.9f);
LEGACY_TRIM_DATA.put("minecraft:amethyst", 1.0f);
// INVALID
LEGACY_TRIM_DATA.put("minecraft:resin", 0F);
LEGACY_TRIM_DATA.put("minecraft:resin", 1.1F);
}
@Override
@@ -37,9 +37,8 @@ public class TrimMaterialSelectProperty implements SelectProperty, LegacyModelPr
@Override
public String legacyPredicateId(Key material) {
String s = material.toString();
if (s.contains("helmet") || s.contains("chestplate") || s.contains("leggings") || s.contains("boots")) {
return "trim";
if (isArmor(material)) {
return "trim_type";
}
return null;
}
@@ -53,6 +52,11 @@ public class TrimMaterialSelectProperty implements SelectProperty, LegacyModelPr
return f;
}
public boolean isArmor(Key material) {
String s = material.toString();
return s.contains("helmet") || s.contains("chestplate") || s.contains("leggings") || s.contains("boots");
}
public static class Factory implements SelectPropertyFactory {
@Override

View File

@@ -135,7 +135,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
this.plugin.logger().warn("Can't not find item " + it.icon() + " for category icon");
return null;
}
item.displayName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(it.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.customName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(it.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.lore(it.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList());
item.load();
return new ItemWithAction(item, (element, click) -> {
@@ -217,7 +217,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
this.plugin.logger().warn("Can't not find item " + subCategory.icon() + " for category icon");
return null;
}
item.displayName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.customName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.lore(subCategory.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList());
item.load();
return new ItemWithAction(item, (element, click) -> {

View File

@@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
* Helper class for handling Adventure components and related functionalities.
*/
public class AdventureHelper {
public static final String EMPTY_COMPONENT = componentToJson(Component.empty());
private final MiniMessage miniMessage;
private final MiniMessage miniMessageStrict;
private final GsonComponentSerializer gsonComponentSerializer;

View File

@@ -10,10 +10,7 @@ import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.ScheduledTickAccess;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.Fallable;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.shapes.CollisionContext;