9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 00:49:20 +00:00
This commit is contained in:
jhqwqmc
2025-09-24 16:31:48 +08:00
parent 10dbf3d590
commit d522cf105d
4 changed files with 437 additions and 554 deletions

View File

@@ -7,50 +7,43 @@ import net.momirealms.craftengine.core.block.BlockBehavior;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.sound.SoundData;
import net.momirealms.craftengine.core.util.Pair;
import net.momirealms.craftengine.core.util.RandomUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
public class ChimeBlockBehavior extends BukkitBlockBehavior {
public static final Factory FACTORY = new Factory();
private final SoundData hitSound;
private final boolean randomPitch;
private final float randomMultiplier;
private final List<Pair<SoundData, Float>> hitSounds;
public ChimeBlockBehavior(CustomBlock customBlock, SoundData hitSound, boolean randomPitch, float randomMultiplier) {
public ChimeBlockBehavior(CustomBlock customBlock, List<Pair<SoundData, Float>> hitSounds) {
super(customBlock);
this.hitSound = hitSound;
this.randomPitch = randomPitch;
this.randomMultiplier = randomMultiplier;
this.hitSounds = hitSounds;
}
@Override
public void onProjectileHit(Object thisBlock, Object[] args, Callable<Object> superMethod) {
Pair<SoundData, Float> hitSound = hitSounds.get(RandomUtils.generateRandomInt(0, hitSounds.size()));
Object blockPos = FastNMS.INSTANCE.field$BlockHitResult$blockPos(args[2]);
Object sound = FastNMS.INSTANCE.constructor$SoundEvent(KeyUtils.toResourceLocation(hitSound.id()), Optional.empty());
float pitch = hitSound.pitch().get();
if (randomPitch) {
pitch = pitch + RandomUtils.generateRandomInt(0, 1) * this.randomMultiplier;
}
FastNMS.INSTANCE.method$LevelAccessor$playSound(args[0], null, blockPos, sound, CoreReflections.instance$SoundSource$BLOCKS, hitSound.volume().get(), pitch);
Object sound = FastNMS.INSTANCE.constructor$SoundEvent(KeyUtils.toResourceLocation(hitSound.left().id()), Optional.empty());
float pitch = hitSound.left().pitch().get() + RandomUtils.generateRandomInt(0, 1) * hitSound.right();
FastNMS.INSTANCE.method$LevelAccessor$playSound(args[0], null, blockPos, sound, CoreReflections.instance$SoundSource$BLOCKS, hitSound.left().volume().get(), pitch);
}
public static class Factory implements BlockBehaviorFactory {
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
SoundData hitSound = SoundData.create(ResourceConfigUtils.requireNonNullOrThrow(arguments.get("hit-sound"), "warning.config.block.behavior.chime.missing_hit_sound"), SoundData.SoundValue.FIXED_1, SoundData.SoundValue.ranged(0.9f, 1f));
Map<String, Object> randomPitch = ResourceConfigUtils.getAsMapOrNull(arguments.get("random-pitch"), "random-pitch");
boolean enableRandomPitch = false;
float randomMultiplier = 1f;
if (randomPitch != null) {
enableRandomPitch = true;
randomMultiplier = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("multiplier", 1f), "multiplier");
}
return new ChimeBlockBehavior(block, hitSound, enableRandomPitch, randomMultiplier);
List<Pair<SoundData, Float>> hitSounds = ResourceConfigUtils.parseConfigAsList(arguments.get("hit-sounds"), map -> {
SoundData hitSound = SoundData.create(ResourceConfigUtils.requireNonNullOrThrow(arguments.get("sound"), "warning.config.block.behavior.chime.missing_hit_sound"), SoundData.SoundValue.FIXED_1, SoundData.SoundValue.ranged(0.9f, 1f));
float randomMultiplier = ResourceConfigUtils.getAsFloat(arguments.get("random-pitch-multiplier"), "random-pitch-multiplier");
return Pair.of(hitSound, randomMultiplier);
});
return new ChimeBlockBehavior(block, hitSounds);
}
}
}

View File

@@ -17,7 +17,30 @@ items:
parent: minecraft:block/custom/palm_log
behavior:
type: block_item
block: default:palm_log
block:
behavior:
type: strippable_block
stripped: default:stripped_palm_log
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
states:
template: default:block_state/pillar
arguments:
base_block: note_block
texture_top_path: minecraft:block/custom/palm_log_top
texture_side_path: minecraft:block/custom/palm_log
model_vertical_path: minecraft:block/custom/palm_log
model_horizontal_path: minecraft:block/custom/palm_log_horizontal
vanilla_id:
type: self_increase_int
from: 0
to: 2
internal_id:
type: self_increase_int
from: 0
to: 2
default:stripped_palm_log:
material: nether_brick
custom-model-data: 1001
@@ -36,7 +59,27 @@ items:
parent: minecraft:block/custom/stripped_palm_log
behavior:
type: block_item
block: default:stripped_palm_log
block:
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
states:
template: default:block_state/pillar
arguments:
base_block: note_block
texture_top_path: minecraft:block/custom/stripped_palm_log_top
texture_side_path: minecraft:block/custom/stripped_palm_log
model_vertical_path: minecraft:block/custom/stripped_palm_log
model_horizontal_path: minecraft:block/custom/stripped_palm_log_horizontal
vanilla_id:
type: self_increase_int
from: 3
to: 5
internal_id:
type: self_increase_int
from: 3
to: 5
default:palm_wood:
material: nether_brick
custom-model-data: 1002
@@ -55,7 +98,30 @@ items:
parent: minecraft:block/custom/palm_wood
behavior:
type: block_item
block: default:palm_wood
block:
behavior:
type: strippable_block
stripped: default:stripped_palm_wood
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
states:
template: default:block_state/pillar
arguments:
base_block: note_block
texture_top_path: minecraft:block/custom/palm_log
texture_side_path: minecraft:block/custom/palm_log
model_vertical_path: minecraft:block/custom/palm_wood
model_horizontal_path: minecraft:block/custom/palm_wood_horizontal
vanilla_id:
type: self_increase_int
from: 6
to: 8
internal_id:
type: self_increase_int
from: 6
to: 8
default:stripped_palm_wood:
material: nether_brick
custom-model-data: 1003
@@ -74,306 +140,11 @@ items:
parent: minecraft:block/custom/stripped_palm_wood
behavior:
type: block_item
block: default:stripped_palm_wood
default:palm_planks:
material: nether_brick
custom-model-data: 1004
settings:
fuel-time: 300
tags:
- minecraft:planks
- minecraft:wooden_tool_materials
data:
item-name: <!i><i18n:item.palm_planks>
model:
type: minecraft:model
path: minecraft:item/custom/palm_planks
generation:
parent: minecraft:block/custom/palm_planks
behavior:
type: block_item
block: default:palm_planks
default:palm_sapling:
material: nether_brick
custom-model-data: 1005
settings:
fuel-time: 100
data:
item-name: <!i><i18n:item.palm_sapling>
model:
template: default:model/generated
arguments:
model: minecraft:item/custom/palm_sapling
texture: minecraft:block/custom/palm_sapling
behavior:
type: block_item
block: default:palm_sapling
default:palm_leaves:
material: oak_leaves
custom-model-data: 1000
data:
item-name: <!i><i18n:item.palm_leaves>
components:
minecraft:block_state:
distance: "1"
persistent: "false"
waterlogged: "false"
model:
type: minecraft:model
path: minecraft:item/custom/palm_leaves
generation:
parent: minecraft:block/custom/palm_leaves
tints:
- type: minecraft:constant
value: -12012264
behavior:
type: block_item
block: default:palm_leaves
default:palm_trapdoor:
material: nether_brick
custom-model-data: 1006
data:
item-name: <!i><i18n:item.palm_trapdoor>
settings:
fuel-time: 300
model:
type: minecraft:model
path: minecraft:item/custom/palm_trapdoor
generation:
parent: minecraft:block/custom/palm_trapdoor_bottom
behavior:
type: block_item
block: default:palm_trapdoor
default:palm_door:
material: nether_brick
custom-model-data: 1007
data:
item-name: <!i><i18n:item.palm_door>
settings:
fuel-time: 200
model:
template: default:model/simplified_generated
arguments:
path: minecraft:item/custom/palm_door
behavior:
type: double_high_block_item
block: default:palm_door
default:palm_fence_gate:
material: nether_brick
custom-model-data: 1008
data:
item-name: <!i><i18n:item.palm_fence_gate>
settings:
fuel-time: 300
model:
type: minecraft:model
path: minecraft:item/custom/palm_fence_gate
generation:
parent: minecraft:block/custom/palm_fence_gate
behavior:
type: block_item
block: default:palm_fence_gate
default:palm_slab:
material: nether_brick
custom-model-data: 1009
data:
item-name: <!i><i18n:item.palm_slab>
settings:
fuel-time: 150
model:
type: minecraft:model
path: minecraft:item/custom/palm_slab
generation:
parent: minecraft:block/custom/palm_slab
behavior:
type: block_item
block: default:palm_slab
default:palm_stairs:
material: nether_brick
custom-model-data: 1013
model:
type: minecraft:model
path: minecraft:item/custom/palm_stairs
generation:
parent: minecraft:block/custom/palm_stairs
data:
item-name: <!i><i18n:item.palm_stairs>
settings:
fuel-time: 300
behavior:
type: block_item
block: default:palm_stairs
default:palm_pressure_plate:
material: nether_brick
custom-model-data: 1014
model:
type: minecraft:model
path: minecraft:item/custom/palm_pressure_plate
generation:
parent: minecraft:block/custom/palm_pressure_plate
data:
item-name: <!i><i18n:item.palm_pressure_plate>
settings:
fuel-time: 300
behavior:
type: block_item
block: default:palm_pressure_plate
default:palm_button:
material: nether_brick
custom-model-data: 1015
model:
type: minecraft:model
path: minecraft:item/custom/palm_button
generation:
parent: minecraft:block/button_inventory
textures:
texture: minecraft:block/custom/palm_planks
data:
item-name: <!i><i18n:item.palm_button>
settings:
fuel-time: 100
behavior:
type: block_item
block: default:palm_button
default:palm_button_pressed:
material: nether_brick
custom-model-data: 1016
model:
type: minecraft:model
path: minecraft:block/custom/palm_button_pressed
generation:
parent: minecraft:block/button_pressed
textures:
texture: minecraft:block/custom/palm_planks
default:palm_button_not_pressed:
material: nether_brick
custom-model-data: 1017
model:
type: minecraft:model
path: minecraft:block/custom/palm_button_not_pressed
generation:
parent: minecraft:block/button
textures:
texture: minecraft:block/custom/palm_planks
default:palm_fence:
material: nether_brick
custom-model-data: 1018
data:
item-name: <!i><i18n:item.palm_fence>
model:
type: minecraft:model
path: minecraft:item/custom/palm_fence_inventory
generation:
parent: minecraft:block/fence_inventory
textures:
texture: minecraft:block/custom/palm_planks
behavior:
type: block_item
block: default:palm_fence
default:palm_fence_post:
material: nether_brick
custom-model-data: 1019
model:
type: minecraft:model
path: minecraft:block/custom/palm_fence_post
generation:
parent: minecraft:block/fence_post
textures:
texture: minecraft:block/custom/palm_planks
default:palm_fence_side:
material: nether_brick
custom-model-data: 1020
model:
type: minecraft:model
path: minecraft:block/custom/palm_fence_side
generation:
parent: minecraft:block/custom/fence_side
textures:
texture: minecraft:block/custom/palm_planks
blocks:
default:palm_log:
behavior:
type: strippable_block
stripped: default:stripped_palm_log
block:
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
overrides:
map-color: 2
states:
template: default:block_state/pillar
arguments:
base_block: note_block
texture_top_path: minecraft:block/custom/palm_log_top
texture_side_path: minecraft:block/custom/palm_log
model_vertical_path: minecraft:block/custom/palm_log
model_horizontal_path: minecraft:block/custom/palm_log_horizontal
vanilla_id:
type: self_increase_int
from: 0
to: 2
internal_id:
type: self_increase_int
from: 0
to: 2
default:stripped_palm_log:
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
overrides:
map-color: 2
states:
template: default:block_state/pillar
arguments:
base_block: note_block
texture_top_path: minecraft:block/custom/stripped_palm_log_top
texture_side_path: minecraft:block/custom/stripped_palm_log
model_vertical_path: minecraft:block/custom/stripped_palm_log
model_horizontal_path: minecraft:block/custom/stripped_palm_log_horizontal
vanilla_id:
type: self_increase_int
from: 3
to: 5
internal_id:
type: self_increase_int
from: 3
to: 5
default:palm_wood:
behavior:
type: strippable_block
stripped: default:stripped_palm_wood
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
overrides:
map-color: 2
states:
template: default:block_state/pillar
arguments:
base_block: note_block
texture_top_path: minecraft:block/custom/palm_log
texture_side_path: minecraft:block/custom/palm_log
model_vertical_path: minecraft:block/custom/palm_wood
model_horizontal_path: minecraft:block/custom/palm_wood_horizontal
vanilla_id:
type: self_increase_int
from: 6
to: 8
internal_id:
type: self_increase_int
from: 6
to: 8
default:stripped_palm_wood:
loot:
template: default:loot_table/self
settings:
template: default:settings/wood
overrides:
map-color: 2
states:
template: default:block_state/pillar
arguments:
@@ -391,10 +162,25 @@ blocks:
from: 9
to: 11
default:palm_planks:
material: nether_brick
custom-model-data: 1004
settings:
fuel-time: 300
tags:
- minecraft:planks
- minecraft:wooden_tool_materials
data:
item-name: <!i><i18n:item.palm_planks>
model:
type: minecraft:model
path: minecraft:item/custom/palm_planks
generation:
parent: minecraft:block/custom/palm_planks
behavior:
type: block_item
block:
settings:
template: default:settings/planks
overrides:
map-color: 2
loot:
template: default:loot_table/self
state:
@@ -405,6 +191,20 @@ blocks:
id: 12
state: note_block:12
default:palm_sapling:
material: nether_brick
custom-model-data: 1005
settings:
fuel-time: 100
data:
item-name: <!i><i18n:item.palm_sapling>
model:
template: default:model/generated
arguments:
model: minecraft:item/custom/palm_sapling
texture: minecraft:block/custom/palm_sapling
behavior:
type: block_item
block:
settings:
template: default:settings/sapling
behaviors:
@@ -441,6 +241,26 @@ blocks:
appearance: default
id: 1
default:palm_leaves:
material: oak_leaves
custom-model-data: 1000
data:
item-name: <!i><i18n:item.palm_leaves>
components:
minecraft:block_state:
distance: '1'
persistent: 'false'
waterlogged: 'false'
model:
type: minecraft:model
path: minecraft:item/custom/palm_leaves
generation:
parent: minecraft:block/custom/palm_leaves
tints:
- type: minecraft:constant
value: -12012264
behavior:
type: block_item
block:
behavior:
type: leaves_block
loot:
@@ -450,8 +270,6 @@ blocks:
sapling: default:palm_sapling
settings:
template: default:settings/leaves
overrides:
map-color: 19
states:
template: default:block_state/leaves
arguments:
@@ -464,6 +282,20 @@ blocks:
from: 0
to: 27
default:palm_trapdoor:
material: nether_brick
custom-model-data: 1006
data:
item-name: <!i><i18n:item.palm_trapdoor>
settings:
fuel-time: 300
model:
type: minecraft:model
path: minecraft:item/custom/palm_trapdoor
generation:
parent: minecraft:block/custom/palm_trapdoor_bottom
behavior:
type: block_item
block:
behavior:
type: trapdoor_block
can-open-with-hand: true
@@ -505,6 +337,19 @@ blocks:
textures:
texture: minecraft:block/custom/palm_trapdoor
default:palm_door:
material: nether_brick
custom-model-data: 1007
data:
item-name: <!i><i18n:item.palm_door>
settings:
fuel-time: 200
model:
template: default:model/simplified_generated
arguments:
path: minecraft:item/custom/palm_door
behavior:
type: double_high_block_item
block:
behavior:
type: door_block
can-open-with-hand: true
@@ -567,6 +412,20 @@ blocks:
parent: minecraft:block/door_bottom_right_open
textures: *textures
default:palm_fence_gate:
material: nether_brick
custom-model-data: 1008
data:
item-name: <!i><i18n:item.palm_fence_gate>
settings:
fuel-time: 300
model:
type: minecraft:model
path: minecraft:item/custom/palm_fence_gate
generation:
parent: minecraft:block/custom/palm_fence_gate
behavior:
type: block_item
block:
behaviors:
type: fence_gate_block
can-open-with-hand: true
@@ -610,6 +469,20 @@ blocks:
parent: minecraft:block/template_fence_gate_wall_open
textures: *textures
default:palm_slab:
material: nether_brick
custom-model-data: 1009
data:
item-name: <!i><i18n:item.palm_slab>
settings:
fuel-time: 150
model:
type: minecraft:model
path: minecraft:item/custom/palm_slab
generation:
parent: minecraft:block/custom/palm_slab
behavior:
type: block_item
block:
behaviors:
type: slab_block
loot:
@@ -643,6 +516,20 @@ blocks:
textures: *textures
model_double_path: minecraft:block/custom/palm_planks
default:palm_stairs:
material: nether_brick
custom-model-data: 1013
model:
type: minecraft:model
path: minecraft:item/custom/palm_stairs
generation:
parent: minecraft:block/custom/palm_stairs
data:
item-name: <!i><i18n:item.palm_stairs>
settings:
fuel-time: 300
behavior:
type: block_item
block:
loot:
template: default:loot_table/self
settings:
@@ -679,6 +566,20 @@ blocks:
parent: minecraft:block/stairs
textures: *textures
default:palm_pressure_plate:
material: nether_brick
custom-model-data: 1014
model:
type: minecraft:model
path: minecraft:item/custom/palm_pressure_plate
generation:
parent: minecraft:block/custom/palm_pressure_plate
data:
item-name: <!i><i18n:item.palm_pressure_plate>
settings:
fuel-time: 300
behavior:
type: block_item
block:
loot:
template: default:loot_table/self
settings:
@@ -719,40 +620,45 @@ blocks:
parent: minecraft:block/pressure_plate_down
textures:
texture: minecraft:block/custom/palm_planks
default:palm_button:
loot:
template: default:loot_table/self
settings:
template:
- default:sound/wood
- default:hardness/button
overrides:
burnable: true
push-reaction: destroy
map-color: 2
instrument: harp
tags:
- minecraft:buttons
- minecraft:mineable/axe
- minecraft:wooden_buttons
behaviors:
- type: face_attached_horizontal_directional_block
- type: button_block
ticks-to-stay-pressed: 30
can-button-be-activated-by-arrows: true
sounds:
on: minecraft:block.wooden_button.click_on
off: minecraft:block.wooden_button.click_off
states:
template: default:block_state/button
arguments:
base_block: birch_button
pressed_item: default:palm_button_pressed
not_pressed_item: default:palm_button_not_pressed
internal_id:
type: self_increase_int
from: 0
to: 23
items#palm_fence:
default:palm_fence:
material: nether_brick
custom-model-data: 1018
data:
item-name: <!i><i18n:item.palm_fence>
model:
type: minecraft:model
path: minecraft:item/custom/palm_fence_inventory
generation:
parent: minecraft:block/fence_inventory
textures:
texture: minecraft:block/custom/palm_planks
behavior:
type: block_item
block: default:palm_fence
default:palm_fence_post:
material: nether_brick
custom-model-data: 1019
model:
type: minecraft:model
path: minecraft:block/custom/palm_fence_post
generation:
parent: minecraft:block/fence_post
textures:
texture: minecraft:block/custom/palm_planks
default:palm_fence_side:
material: nether_brick
custom-model-data: 1020
model:
type: minecraft:model
path: minecraft:block/custom/palm_fence_side
generation:
parent: minecraft:block/custom/fence_side
textures:
texture: minecraft:block/custom/palm_planks
blocks#palm_fence:
default:palm_fence:
loot:
template: default:loot_table/self

View File

@@ -54,10 +54,6 @@ i18n:
item.hami_melon_seeds: Hami Melon Seeds
item.palm_button: Palm Button
item.palm_fence: Palm Fence
item.infected_palm_log: Infected Palm Log
item.small_mushroom: Small Mushroom
item.medium_mushroom: Medium Mushroom
item.large_mushroom: Large Mushroom
category.default.name: Default Assets
category.default.lore: Contains the default configuration of CraftEngine
category.palm_tree: Palm Tree
@@ -121,10 +117,6 @@ i18n:
item.hami_melon_seeds: 哈密瓜种子
item.palm_button: 棕榈木按钮
item.palm_fence: 棕榈木栅栏
item.infected_palm_log: 菌蚀棕榈原木
item.small_mushroom: 小型蘑菇
item.medium_mushroom: 中型蘑菇
item.large_mushroom: 大型蘑菇
category.default.name: 默认资产
category.default.lore: 包含了CraftEngine的默认配置
category.palm_tree: 棕榈树
@@ -172,10 +164,6 @@ lang:
block_name:default:default:attached_hami_melon_stem: Hami Melon Stem
block_name:default:palm_button: Palm Button
block_name:default:palm_fence: Palm Fence
block_name:default:infected_palm_log: Infected Palm Log
block_name:default:small_mushroom: Small Mushroom
block_name:default:medium_mushroom: Medium Mushroom
block_name:default:large_mushroom: Large Mushroom
zh_cn:
block_name:default:chinese_lantern: 灯笼
block_name:default:netherite_anvil: 下界合金砧
@@ -211,7 +199,3 @@ lang:
block_name:default:default:attached_hami_melon_stem: 哈密瓜茎
block_name:default:palm_button: 棕榈木按钮
block_name:default:palm_fence: 棕榈木栅栏
block_name:default:infected_palm_log: 菌蚀棕榈原木
block_name:default:small_mushroom: 小型蘑菇
block_name:default:medium_mushroom: 中型蘑菇
block_name:default:large_mushroom: 大型蘑菇

View File

@@ -171,6 +171,6 @@ public abstract class Property<T extends Comparable<T>> {
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("name", this.name).add("clazz", this.clazz).add("values", this.possibleValues()).toString();
return this.getClass().getSimpleName() + "{clazz=" + this.clazz + ", name='" + this.name + "', values=" + this.possibleValues() + '}';
}
}