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

改进block-state

This commit is contained in:
XiaoMoMi
2025-10-08 20:20:23 +08:00
parent a254cf7e53
commit 3c63e02ee9
11 changed files with 53 additions and 8 deletions

View File

@@ -21,8 +21,8 @@ public enum AutoStateGroup {
LOWER_TRIPWIRE("lower_tripwire", Set.of(BlockKeys.TRIPWIRE), (w) -> w.getProperty("attached")),
HIGHER_TRIPWIRE("higher_tripwire", Set.of(BlockKeys.TRIPWIRE), (w) -> !(boolean) w.getProperty("attached")),
NOTE_BLOCK("note_block", Set.of(BlockKeys.NOTE_BLOCK), (w) -> true),
BROWN_MUSHROOM("brown_mushroom", Set.of(BlockKeys.BROWN_MUSHROOM_BLOCK), (w) -> true),
RED_MUSHROOM("red_mushroom", Set.of(BlockKeys.RED_MUSHROOM_BLOCK), (w) -> true),
BROWN_MUSHROOM("brown_mushroom_block", Set.of(BlockKeys.BROWN_MUSHROOM_BLOCK), (w) -> true),
RED_MUSHROOM("red_mushroom_block", Set.of(BlockKeys.RED_MUSHROOM_BLOCK), (w) -> true),
MUSHROOM_STEM("mushroom_stem", Set.of(BlockKeys.MUSHROOM_STEM), (w) -> true),
TRIPWIRE("tripwire", Set.of(BlockKeys.TRIPWIRE), (w) -> true),
SUGAR_CANE("sugar_cane", Set.of(BlockKeys.SUGAR_CANE), (w) -> true),

View File

@@ -25,6 +25,8 @@ public interface BlockStateWrapper extends Comparable<BlockStateWrapper> {
String getAsString();
boolean isCustom();
@Override
default int compareTo(@NotNull BlockStateWrapper o) {
return Integer.compare(registryId(), o.registryId());

View File

@@ -0,0 +1,6 @@
package net.momirealms.craftengine.core.block;
public interface CustomBlockStateWrapper {
BlockStateWrapper visualBlockState();
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.core.item.modifier;
import net.momirealms.craftengine.core.block.BlockStateWrapper;
import net.momirealms.craftengine.core.block.CustomBlockStateWrapper;
import net.momirealms.craftengine.core.item.ComponentKeys;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemBuildContext;
@@ -12,6 +13,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class BlockStateModifier<I> implements SimpleNetworkItemDataModifier<I> {
@@ -62,10 +64,14 @@ public class BlockStateModifier<I> implements SimpleNetworkItemDataModifier<I> {
String stateString = arg.toString();
return new BlockStateModifier<>(LazyReference.lazyReference(() -> {
BlockStateWrapper blockState = CraftEngine.instance().blockManager().createBlockState(stateString);
if (blockState instanceof CustomBlockStateWrapper customBlockStateWrapper) {
blockState = customBlockStateWrapper.visualBlockState();
}
if (blockState != null) {
Map<String, String> properties = new HashMap<>(4);
for (String property : blockState.getPropertyNames()) {
properties.put(property, blockState.getProperty(property));
Object value = blockState.getProperty(property);
properties.put(property, String.valueOf(value).toLowerCase(Locale.ROOT));
}
return properties;
}