9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-26 10:29:20 +00:00

添加快乐恶魂碰撞箱

This commit is contained in:
jhqwqmc
2025-12-03 07:38:36 +08:00
parent 34cb3936b0
commit 7082020220
57 changed files with 359 additions and 152 deletions

View File

@@ -78,7 +78,7 @@ public abstract class BlockBehavior {
return (boolean) superMethod.call();
}
// 1.20-1.20.4 BlockState state, BlockGetter world, BlockPos pos, PathComputationType id
// 1.20-1.20.4 BlockState state, BlockGetter world, BlockPos pos, PathComputationType type
// 1.20.5+ BlockState state, PathComputationType pathComputationType
public boolean isPathFindable(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
return (boolean) superMethod.call();

View File

@@ -4,7 +4,7 @@ import java.util.concurrent.Callable;
public interface IsPathFindableBlockBehavior {
// 1.20-1.20.4 BlockState state, BlockGetter world, BlockPos pos, PathComputationType id
// 1.20-1.20.4 BlockState state, BlockGetter world, BlockPos pos, PathComputationType type
// 1.20.5+ BlockState state, PathComputationType pathComputationType
boolean isPathFindable(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception;
}

View File

@@ -15,14 +15,15 @@ public abstract class BlockEntityElementConfigs {
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
public static final Key ITEM = Key.of("craftengine:item");
public static void register(Key key, BlockEntityElementConfigFactory type) {
((WritableRegistry<BlockEntityElementConfigFactory>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE)
public static void register(Key key, BlockEntityElementConfigFactory<?> type) {
((WritableRegistry<BlockEntityElementConfigFactory<?>>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE)
.register(ResourceKey.create(Registries.BLOCK_ENTITY_ELEMENT_TYPE.location(), key), type);
}
public static <E extends BlockEntityElement> BlockEntityElementConfig<E> fromMap(Map<String, Object> arguments) {
Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(it -> Key.withDefaultNamespace(it, "craftengine")).orElse(ITEM_DISPLAY);
BlockEntityElementConfigFactory factory = BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE.getValue(type);
@SuppressWarnings("unchecked")
BlockEntityElementConfigFactory<E> factory = (BlockEntityElementConfigFactory<E>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE.getValue(type);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.entity_renderer.invalid_type", type.toString());
}

View File

@@ -48,6 +48,7 @@ public interface FurnitureConfig {
if (optionalVariant.isPresent()) {
variantName = optionalVariant.get();
} else {
@SuppressWarnings("deprecation")
Optional<AnchorType> optionalAnchorType = accessor.anchorType();
if (optionalAnchorType.isPresent()) {
variantName = optionalAnchorType.get().name().toLowerCase(Locale.ROOT);

View File

@@ -106,6 +106,7 @@ public class FurnitureDataAccessor {
this.data.putString(VARIANT, variant);
}
@SuppressWarnings("deprecation")
@ApiStatus.Obsolete
public Optional<AnchorType> anchorType() {
if (this.data.containsKey(ANCHOR_TYPE)) return Optional.of(AnchorType.byId(this.data.getInt(ANCHOR_TYPE)));
@@ -113,7 +114,7 @@ public class FurnitureDataAccessor {
}
@ApiStatus.Obsolete
public FurnitureDataAccessor anchorType(AnchorType type) {
public FurnitureDataAccessor anchorType(@SuppressWarnings("deprecation") AnchorType type) {
this.data.putInt(ANCHOR_TYPE, type.getId());
return this;
}

View File

@@ -15,14 +15,15 @@ public class FurnitureElementConfigs {
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
public static final Key ITEM = Key.of("craftengine:item");
public static void register(Key key, FurnitureElementConfigFactory type) {
((WritableRegistry<FurnitureElementConfigFactory>) BuiltInRegistries.FURNITURE_ELEMENT_TYPE)
public static void register(Key key, FurnitureElementConfigFactory<?> type) {
((WritableRegistry<FurnitureElementConfigFactory<?>>) BuiltInRegistries.FURNITURE_ELEMENT_TYPE)
.register(ResourceKey.create(Registries.FURNITURE_ELEMENT_TYPE.location(), key), type);
}
public static <E extends FurnitureElement> FurnitureElementConfig<E> fromMap(Map<String, Object> arguments) {
Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(it -> Key.withDefaultNamespace(it, "craftengine")).orElse(ITEM_DISPLAY);
FurnitureElementConfigFactory factory = BuiltInRegistries.FURNITURE_ELEMENT_TYPE.getValue(type);
@SuppressWarnings("unchecked")
FurnitureElementConfigFactory<E> factory = (FurnitureElementConfigFactory<E>) BuiltInRegistries.FURNITURE_ELEMENT_TYPE.getValue(type);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.furniture.element.invalid_type", type.toString());
}

View File

@@ -17,14 +17,15 @@ public class FurnitureHitBoxTypes {
public static final Key VIRTUAL = Key.of("minecraft:virtual");
public static final Key CUSTOM = Key.of("minecraft:custom");
public static void register(Key key, FurnitureHitBoxConfigFactory factory) {
((WritableRegistry<FurnitureHitBoxConfigFactory>) BuiltInRegistries.FURNITURE_HITBOX_TYPE)
public static void register(Key key, FurnitureHitBoxConfigFactory<?> factory) {
((WritableRegistry<FurnitureHitBoxConfigFactory<?>>) BuiltInRegistries.FURNITURE_HITBOX_TYPE)
.register(ResourceKey.create(Registries.FURNITURE_HITBOX_TYPE.location(), key), factory);
}
public static <H extends FurnitureHitBox> FurnitureHitBoxConfig<H> fromMap(Map<String, Object> arguments) {
Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(Key::of).orElse(FurnitureHitBoxTypes.INTERACTION);
FurnitureHitBoxConfigFactory factory = BuiltInRegistries.FURNITURE_HITBOX_TYPE.getValue(type);
@SuppressWarnings("unchecked")
FurnitureHitBoxConfigFactory<H> factory = (FurnitureHitBoxConfigFactory<H>) BuiltInRegistries.FURNITURE_HITBOX_TYPE.getValue(type);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.invalid_type", type.toString());
}

View File

@@ -28,7 +28,7 @@ import java.util.Optional;
* This interface provides methods for managing item properties such as custom model data,
* damage, display name, lore, enchantments, and tags.
*
* @param <I> the id of the item implementation
* @param <I> the type of the item implementation
*/
public interface Item<I> {

View File

@@ -446,8 +446,8 @@ public class ItemSettings {
Key customTridentItemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("item"), "warning.config.item.settings.projectile.missing_item"));
ItemDisplayContext displayType = ItemDisplayContext.valueOf(args.getOrDefault("display-transform", "NONE").toString().toUpperCase(Locale.ENGLISH));
Billboard billboard = Billboard.valueOf(args.getOrDefault("billboard", "FIXED").toString().toUpperCase(Locale.ENGLISH));
Vector3f translation = ResourceConfigUtils.getAsVector3f(args.getOrDefault("translation", "0"), "translation");
Vector3f scale = ResourceConfigUtils.getAsVector3f(args.getOrDefault("scale", "1"), "scale");
Vector3f translation = ResourceConfigUtils.getAsVector3f(args.getOrDefault("translation", 0), "translation");
Vector3f scale = ResourceConfigUtils.getAsVector3f(args.getOrDefault("scale", 1), "scale");
Quaternionf rotation = ResourceConfigUtils.getAsQuaternionf(ResourceConfigUtils.get(args, "rotation"), "rotation");
double range = ResourceConfigUtils.getAsDouble(args.getOrDefault("range", 1), "range");
return settings -> settings.projectileMeta(new ProjectileMeta(customTridentItemId, displayType, billboard, scale, translation, rotation, range));

View File

@@ -190,7 +190,7 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
@Override
public CustomSmithingTransformRecipe<A> readMap(Key id, Map<String, Object> arguments) {
List<String> base = MiscUtils.getAsStringList(arguments.get("base"));
List<String> template = MiscUtils.getAsStringList(arguments.get("template-id"));
List<String> template = MiscUtils.getAsStringList(arguments.get("template-type"));
List<String> addition = MiscUtils.getAsStringList(arguments.get("addition"));
boolean mergeComponents = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("merge-components", true), "merge-components");
boolean mergeEnchantments = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("merge-enchantments", false), "merge-enchantments");

View File

@@ -141,7 +141,7 @@ public class CustomSmithingTrimRecipe<T> extends AbstractRecipe<T>
@Override
public CustomSmithingTrimRecipe<A> readMap(Key id, Map<String, Object> arguments) {
List<String> base = MiscUtils.getAsStringList(arguments.get("base"));
List<String> template = MiscUtils.getAsStringList(arguments.get("template-id"));
List<String> template = MiscUtils.getAsStringList(arguments.get("template-type"));
List<String> addition = MiscUtils.getAsStringList(arguments.get("addition"));
Key pattern = VersionHelper.isOrAbove1_21_5() ? Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), "warning.config.recipe.smithing_trim.missing_pattern")) : null;
return new CustomSmithingTrimRecipe<>(id,

View File

@@ -87,12 +87,12 @@ public class ApplyBonusCountFunction<T> extends AbstractLootConditionalFunction<
public static Formula fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new NullPointerException("number id cannot be null");
throw new NullPointerException("number type cannot be null");
}
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
FormulaFactory factory = BuiltInRegistries.FORMULA_FACTORY.getValue(key);
if (factory == null) {
throw new IllegalArgumentException("Unknown formula id: " + type);
throw new IllegalArgumentException("Unknown formula type: " + type);
}
return factory.create(map);
}

View File

@@ -75,7 +75,7 @@ public class ItemModels {
Key key = Key.withDefaultNamespace(type, "minecraft");
ItemModelReader reader = BuiltInRegistries.ITEM_MODEL_READER.getValue(key);
if (reader == null) {
throw new IllegalArgumentException("Invalid item model id: " + key);
throw new IllegalArgumentException("Invalid item model type: " + key);
}
return reader.read(json);
}

View File

@@ -80,7 +80,7 @@ public class ConditionProperties {
Key key = Key.withDefaultNamespace(type, "minecraft");
ConditionPropertyReader reader = BuiltInRegistries.CONDITION_PROPERTY_READER.getValue(key);
if (reader == null) {
throw new IllegalArgumentException("Invalid condition property id: " + key);
throw new IllegalArgumentException("Invalid condition property type: " + key);
}
return reader.read(json);
}

View File

@@ -71,7 +71,7 @@ public class RangeDispatchProperties {
Key key = Key.withDefaultNamespace(type, "minecraft");
RangeDispatchPropertyReader reader = BuiltInRegistries.RANGE_DISPATCH_PROPERTY_READER.getValue(key);
if (reader == null) {
throw new IllegalArgumentException("Invalid range dispatch property id: " + key);
throw new IllegalArgumentException("Invalid range dispatch property type: " + key);
}
return reader.read(json);
}

View File

@@ -71,7 +71,7 @@ public class SelectProperties {
Key key = Key.withDefaultNamespace(type, "minecraft");
SelectPropertyReader reader = BuiltInRegistries.SELECT_PROPERTY_READER.getValue(key);
if (reader == null) {
throw new IllegalArgumentException("Invalid select property id: " + key);
throw new IllegalArgumentException("Invalid select property type: " + key);
}
return reader.read(json);
}

View File

@@ -45,7 +45,7 @@ public class SignSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
Key type = Key.of(arguments.get("type").toString());
String woodType = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("wood-id"), "warning.config.item.model.special.sign.missing_wood_type");
String woodType = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("wood-type"), "warning.config.item.model.special.sign.missing_wood_type");
String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.sign.missing_texture");
return new SignSpecialModel(type, woodType, texture);
}

View File

@@ -80,7 +80,7 @@ public class SpecialModels {
Key key = Key.withDefaultNamespace(type, "minecraft");
SpecialModelReader reader = BuiltInRegistries.SPECIAL_MODEL_READER.getValue(key);
if (reader == null) {
throw new IllegalArgumentException("Invalid special model id: " + key);
throw new IllegalArgumentException("Invalid special model type: " + key);
}
return reader.read(json);
}

View File

@@ -65,7 +65,7 @@ public class Tints {
Key key = Key.withDefaultNamespace(type, "minecraft");
TintReader reader = BuiltInRegistries.TINT_READER.getValue(key);
if (reader == null) {
throw new IllegalArgumentException("Invalid tint id: " + type);
throw new IllegalArgumentException("Invalid tint type: " + type);
}
return reader.read(json);
}

View File

@@ -36,7 +36,7 @@ public enum ObfA {
return type;
}
}
throw new IllegalArgumentException("Unknown resource id: " + xclf);
throw new IllegalArgumentException("Unknown resource type: " + xclf);
}
public static final byte[] VALUES = new byte[] {

View File

@@ -9,7 +9,7 @@ import java.util.UUID;
/**
* Simple implementation of {@link Sender} using a {@link SenderFactory}
*
* @param <T> the command sender id
* @param <T> the command sender type
*/
public final class AbstractSender<T> implements Sender {
private final Plugin plugin;

View File

@@ -448,10 +448,10 @@ public class Config {
// furniture
furniture$hide_base_entity = config.getBoolean("furniture.hide-base-entity", true);
furniture$collision_entity_type = ColliderType.valueOf(config.getString("furniture.collision-entity-id", "interaction").toUpperCase(Locale.ENGLISH));
furniture$collision_entity_type = ColliderType.valueOf(config.getString("furniture.collision-entity-type", "interaction").toUpperCase(Locale.ENGLISH));
// equipment
equipment$sacrificed_vanilla_armor$type = config.getString("equipment.sacrificed-vanilla-armor.id", "chainmail").toLowerCase(Locale.ENGLISH);
equipment$sacrificed_vanilla_armor$type = config.getString("equipment.sacrificed-vanilla-armor.type", "chainmail").toLowerCase(Locale.ENGLISH);
if (!AbstractPackManager.ALLOWED_VANILLA_EQUIPMENT.contains(equipment$sacrificed_vanilla_armor$type)) {
TranslationManager.instance().log("warning.config.equipment.invalid_sacrificed_armor", equipment$sacrificed_vanilla_armor$type);
equipment$sacrificed_vanilla_armor$type = "chainmail";

View File

@@ -259,7 +259,7 @@ public class StringKeyConstructor extends SafeConstructor {
if (value instanceof Number number) {
return number.byteValue();
}
throw new RuntimeException("Unexpected id: " + value.getClass().getName());
throw new RuntimeException("Unexpected type: " + value.getClass().getName());
}
}
@@ -271,7 +271,7 @@ public class StringKeyConstructor extends SafeConstructor {
if (value instanceof Number number) {
return number.shortValue();
}
throw new RuntimeException("Unexpected id: " + value.getClass().getName());
throw new RuntimeException("Unexpected type: " + value.getClass().getName());
}
}
@@ -283,7 +283,7 @@ public class StringKeyConstructor extends SafeConstructor {
if (value instanceof Number number) {
return number.longValue();
}
throw new RuntimeException("Unexpected id: " + value.getClass().getName());
throw new RuntimeException("Unexpected type: " + value.getClass().getName());
}
}
@@ -295,7 +295,7 @@ public class StringKeyConstructor extends SafeConstructor {
if (value instanceof Number number) {
return number.floatValue();
}
throw new RuntimeException("Unexpected id: " + value.getClass().getName());
throw new RuntimeException("Unexpected type: " + value.getClass().getName());
}
}
@@ -307,7 +307,7 @@ public class StringKeyConstructor extends SafeConstructor {
if (value instanceof Number number) {
return number.doubleValue();
}
throw new RuntimeException("Unexpected id: " + value.getClass().getName());
throw new RuntimeException("Unexpected type: " + value.getClass().getName());
}
}
}

View File

@@ -61,7 +61,7 @@ public class ExpressionTemplateArgument implements TemplateArgument {
public TemplateArgument create(Map<String, Object> arguments) {
return new ExpressionTemplateArgument(
arguments.getOrDefault("expression", "").toString(),
ValueType.valueOf(arguments.getOrDefault("value-id", "double").toString().toUpperCase(Locale.ROOT))
ValueType.valueOf(arguments.getOrDefault("value-type", "double").toString().toUpperCase(Locale.ROOT))
);
}
}

View File

@@ -58,7 +58,7 @@ public class TemplateArguments {
Key key = Key.withDefaultNamespace(type0, Key.DEFAULT_NAMESPACE);
TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key);
if (factory == null) {
throw new IllegalArgumentException("Unknown argument id: " + type);
throw new IllegalArgumentException("Unknown argument type: " + type);
}
return factory.create(map);
}

View File

@@ -43,7 +43,7 @@ public class DamageFunction<CTX extends Context> extends AbstractConditionalFunc
@Override
public Function<CTX> create(Map<String, Object> arguments) {
PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.getOrDefault("target", "self"), conditionFactory());
Key damageType = Key.of(ResourceConfigUtils.getAsStringOrNull(arguments.getOrDefault("damage-id", "generic")));
Key damageType = Key.of(ResourceConfigUtils.getAsStringOrNull(arguments.getOrDefault("damage-type", "generic")));
NumberProvider amount = NumberProviders.fromObject(arguments.getOrDefault("amount", 1f));
return new DamageFunction<>(selector, damageType, amount, getPredicates(arguments));
}

View File

@@ -65,7 +65,7 @@ public class OpenWindowFunction<CTX extends Context> extends AbstractConditional
@Override
public Function<CTX> create(Map<String, Object> arguments) {
String title = Optional.ofNullable(arguments.get("title")).map(String::valueOf).orElse(null);
String rawType = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("gui-id"), "warning.config.function.open_window.missing_gui_type");
String rawType = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("gui-type"), "warning.config.function.open_window.missing_gui_type");
try {
GuiType type = GuiType.valueOf(rawType.toUpperCase(Locale.ENGLISH));
return new OpenWindowFunction<>(getPredicates(arguments), PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), type, title);

View File

@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation")
public class ReplaceFurnitureFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final Key newFurnitureId;
private final NumberProvider x;
@@ -95,7 +96,7 @@ public class ReplaceFurnitureFunction<CTX extends Context> extends AbstractCondi
NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:furniture.z>"));
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", "<arg:furniture.pitch>"));
NumberProvider yaw = NumberProviders.fromObject(arguments.getOrDefault("yaw", "<arg:furniture.yaw>"));
AnchorType anchorType = ResourceConfigUtils.getAsEnum(arguments.get("anchor-id"), AnchorType.class, null);
AnchorType anchorType = ResourceConfigUtils.getAsEnum(arguments.get("anchor-type"), AnchorType.class, null);
boolean dropLoot = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("drop-loot", true), "drop-loot");
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
return new ReplaceFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, anchorType, dropLoot, playSound, getPredicates(arguments));

View File

@@ -87,7 +87,7 @@ public class SpawnFurnitureFunction<CTX extends Context> extends AbstractConditi
NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>"));
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", "<arg:position.pitch>"));
NumberProvider yaw = NumberProviders.fromObject(arguments.getOrDefault("yaw", "<arg:position.yaw>"));
String variant = ResourceConfigUtils.getAsStringOrNull(ResourceConfigUtils.get(arguments, "variant", "anchor-id"));
String variant = ResourceConfigUtils.getAsStringOrNull(ResourceConfigUtils.get(arguments, "variant", "anchor-type"));
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
return new SpawnFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, variant, playSound, getPredicates(arguments));
}

View File

@@ -63,7 +63,7 @@ public class ToastFunction<CTX extends Context> extends AbstractConditionalFunct
@Override
public Function<CTX> create(Map<String, Object> arguments) {
AdvancementType advancementType;
String advancementName = arguments.getOrDefault("advancement-id", "goal").toString();
String advancementName = arguments.getOrDefault("advancement-type", "goal").toString();
try {
advancementType = AdvancementType.valueOf(advancementName.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {

View File

@@ -53,7 +53,7 @@ public class LangData {
temp.put(result, entry.getValue());
}
},
() -> CraftEngine.instance().logger().warn("Unknown lang id: " + key)
() -> CraftEngine.instance().logger().warn("Unknown lang type: " + key)
);
} else {
temp.put(key, entry.getValue());

View File

@@ -89,10 +89,10 @@ public class BuiltInRegistries {
public static final Registry<ItemUpdaterType<?>> ITEM_UPDATER_TYPE = createConstantBoundRegistry(Registries.ITEM_UPDATER_TYPE, 16);
public static final Registry<NetworkCodec<FriendlyByteBuf, ? extends ModPacket>> MOD_PACKET = createConstantBoundRegistry(Registries.MOD_PACKET, 16);
public static final Registry<BlockEntityType<?>> BLOCK_ENTITY_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_TYPE, 64);
public static final Registry<BlockEntityElementConfigFactory> BLOCK_ENTITY_ELEMENT_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_ELEMENT_TYPE, 16);
public static final Registry<BlockEntityElementConfigFactory<?>> BLOCK_ENTITY_ELEMENT_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_ELEMENT_TYPE, 16);
public static final Registry<CraftRemainderFactory> CRAFT_REMAINDER_FACTORY = createConstantBoundRegistry(Registries.CRAFT_REMAINDER_FACTORY, 16);
public static final Registry<FurnitureElementConfigFactory> FURNITURE_ELEMENT_TYPE = createConstantBoundRegistry(Registries.FURNITURE_ELEMENT_TYPE, 16);
public static final Registry<FurnitureHitBoxConfigFactory> FURNITURE_HITBOX_TYPE = createConstantBoundRegistry(Registries.FURNITURE_HITBOX_TYPE, 16);
public static final Registry<FurnitureElementConfigFactory<?>> FURNITURE_ELEMENT_TYPE = createConstantBoundRegistry(Registries.FURNITURE_ELEMENT_TYPE, 16);
public static final Registry<FurnitureHitBoxConfigFactory<?>> FURNITURE_HITBOX_TYPE = createConstantBoundRegistry(Registries.FURNITURE_HITBOX_TYPE, 16);
private static <T> Registry<T> createConstantBoundRegistry(ResourceKey<? extends Registry<T>> key, int expectedSize) {
return new ConstantBoundRegistry<>(key, expectedSize);

View File

@@ -91,8 +91,8 @@ public class Registries {
public static final ResourceKey<Registry<ItemUpdaterType<?>>> ITEM_UPDATER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_updater_type"));
public static final ResourceKey<Registry<NetworkCodec<FriendlyByteBuf, ? extends ModPacket>>> MOD_PACKET = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("mod_packet_type"));
public static final ResourceKey<Registry<BlockEntityType<?>>> BLOCK_ENTITY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_type"));
public static final ResourceKey<Registry<BlockEntityElementConfigFactory>> BLOCK_ENTITY_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_element_type"));
public static final ResourceKey<Registry<BlockEntityElementConfigFactory<?>>> BLOCK_ENTITY_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_element_type"));
public static final ResourceKey<Registry<CraftRemainderFactory>> CRAFT_REMAINDER_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("craft_remainder_factory"));
public static final ResourceKey<Registry<FurnitureElementConfigFactory>> FURNITURE_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_element_type"));
public static final ResourceKey<Registry<FurnitureHitBoxConfigFactory>> FURNITURE_HITBOX_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_hitbox_type"));
public static final ResourceKey<Registry<FurnitureElementConfigFactory<?>>> FURNITURE_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_element_type"));
public static final ResourceKey<Registry<FurnitureHitBoxConfigFactory<?>>> FURNITURE_HITBOX_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_hitbox_type"));
}

View File

@@ -22,7 +22,7 @@ public record SoundData(Key id, SoundValue volume, SoundValue pitch) {
SoundValue pitchValue = Optional.ofNullable(SoundValue.of(map.get("pitch"))).orElse(volume);
return new SoundData(id, volumeValue, pitchValue);
} else {
throw new IllegalArgumentException("Illegal object id for sound data: " + obj.getClass());
throw new IllegalArgumentException("Illegal object type for sound data: " + obj.getClass());
}
}

View File

@@ -6,8 +6,8 @@ import java.util.Objects;
* A generic class representing a pair of values.
* This class provides methods to create and access pairs of values.
*
* @param <L> the id of the left value
* @param <R> the id of the right value
* @param <L> the type of the left value
* @param <R> the type of the right value
*/
public record Pair<L, R>(L left, R right) {
@@ -16,8 +16,8 @@ public record Pair<L, R>(L left, R right) {
*
* @param left the left value
* @param right the right value
* @param <L> the id of the left value
* @param <R> the id of the right value
* @param <L> the type of the left value
* @param <R> the type of the right value
* @return a new {@link Pair} with the specified values
*/
public static <L, R> Pair<L, R> of(final L left, final R right) {

View File

@@ -439,7 +439,7 @@ public class ReflectionUtils {
public static List<Method> getMethods(@NotNull Class<?> clazz, @NotNull Class<?> returnType, @NotNull Class<?>... parameterTypes) {
List<Method> list = new ArrayList<>();
for (Method method : clazz.getMethods()) {
if (!returnType.isAssignableFrom(method.getReturnType()) // check id
if (!returnType.isAssignableFrom(method.getReturnType()) // check type
|| method.getParameterCount() != parameterTypes.length // check length
) continue;
Class<?>[] types = method.getParameterTypes();

View File

@@ -137,13 +137,13 @@ public final class ResourceConfigUtils {
try {
return Integer.parseInt(s.replace("_", ""));
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.id.int", e, s, option);
throw new LocalizedResourceConfigException("warning.config.type.int", e, s, option);
}
}
case Boolean b -> {
return b ? 1 : 0;
}
default -> throw new LocalizedResourceConfigException("warning.config.id.int", o.toString(), option);
default -> throw new LocalizedResourceConfigException("warning.config.type.int", o.toString(), option);
}
}
@@ -162,11 +162,11 @@ public final class ResourceConfigUtils {
try {
return Double.parseDouble(s);
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.id.double", e, s, option);
throw new LocalizedResourceConfigException("warning.config.type.double", e, s, option);
}
}
default -> {
throw new LocalizedResourceConfigException("warning.config.id.double", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.double", o.toString(), option);
}
}
}
@@ -183,14 +183,14 @@ public final class ResourceConfigUtils {
try {
return Float.parseFloat(s);
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.id.float", e, s, option);
throw new LocalizedResourceConfigException("warning.config.type.float", e, s, option);
}
}
case Number number -> {
return number.floatValue();
}
default -> {
throw new LocalizedResourceConfigException("warning.config.id.float", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.float", o.toString(), option);
}
}
}
@@ -206,15 +206,15 @@ public final class ResourceConfigUtils {
case Number n -> {
if (n.byteValue() == 0) return false;
if (n.byteValue() == 1) return true;
throw new LocalizedResourceConfigException("warning.config.id.boolean", String.valueOf(n), option);
throw new LocalizedResourceConfigException("warning.config.type.boolean", String.valueOf(n), option);
}
case String s -> {
if (s.equalsIgnoreCase("true")) return true;
if (s.equalsIgnoreCase("false")) return false;
throw new LocalizedResourceConfigException("warning.config.id.boolean", s, option);
throw new LocalizedResourceConfigException("warning.config.type.boolean", s, option);
}
default -> {
throw new LocalizedResourceConfigException("warning.config.id.boolean", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.boolean", o.toString(), option);
}
}
}
@@ -234,11 +234,11 @@ public final class ResourceConfigUtils {
try {
return Long.parseLong(s.replace("_", ""));
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.id.long", e, s, option);
throw new LocalizedResourceConfigException("warning.config.type.long", e, s, option);
}
}
default -> {
throw new LocalizedResourceConfigException("warning.config.id.long", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.long", o.toString(), option);
}
}
}
@@ -248,7 +248,7 @@ public final class ResourceConfigUtils {
if (obj instanceof Map<?, ?> map) {
return (Map<String, Object>) map;
}
throw new LocalizedResourceConfigException("warning.config.id.map", String.valueOf(obj), option);
throw new LocalizedResourceConfigException("warning.config.type.map", String.valueOf(obj), option);
}
@SuppressWarnings("unchecked")
@@ -259,24 +259,30 @@ public final class ResourceConfigUtils {
if (obj instanceof Map<?, ?> map) {
return (Map<String, Object>) map;
}
throw new LocalizedResourceConfigException("warning.config.id.map", String.valueOf(obj), option);
throw new LocalizedResourceConfigException("warning.config.type.map", String.valueOf(obj), option);
}
public static Vector3f getAsVector3f(Object o, String option) {
if (o == null) return new Vector3f();
if (o instanceof List<?> list && list.size() == 3) {
return new Vector3f(Float.parseFloat(list.get(0).toString()), Float.parseFloat(list.get(1).toString()), Float.parseFloat(list.get(2).toString()));
} else if (o instanceof Number number) {
return new Vector3f(number.floatValue());
} else {
String stringFormat = o.toString();
String[] split = stringFormat.split(",");
if (split.length == 3) {
return new Vector3f(Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2]));
} else if (split.length == 1) {
return new Vector3f(Float.parseFloat(split[0]));
} else {
throw new LocalizedResourceConfigException("warning.config.id.vector3f", stringFormat, option);
switch (o) {
case null -> {
return new Vector3f();
}
case List<?> list when list.size() == 3 -> {
return new Vector3f(Float.parseFloat(list.get(0).toString()), Float.parseFloat(list.get(1).toString()), Float.parseFloat(list.get(2).toString()));
}
case Number number -> {
return new Vector3f(number.floatValue());
}
default -> {
String stringFormat = o.toString();
String[] split = stringFormat.split(",");
if (split.length == 3) {
return new Vector3f(Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2]));
} else if (split.length == 1) {
return new Vector3f(Float.parseFloat(split[0]));
} else {
throw new LocalizedResourceConfigException("warning.config.type.vector3f", stringFormat, option);
}
}
}
}
@@ -295,7 +301,7 @@ public final class ResourceConfigUtils {
} else if (split.length == 1) {
return QuaternionUtils.toQuaternionf(0, (float) -Math.toRadians(Float.parseFloat(split[0])), 0);
} else {
throw new LocalizedResourceConfigException("warning.config.id.quaternionf", stringFormat, option);
throw new LocalizedResourceConfigException("warning.config.type.quaternionf", stringFormat, option);
}
}
}
@@ -313,7 +319,7 @@ public final class ResourceConfigUtils {
double d = Double.parseDouble(split[0]);
return new Vec3d(d, d, d);
} else {
throw new LocalizedResourceConfigException("warning.config.id.vec3d", stringFormat, option);
throw new LocalizedResourceConfigException("warning.config.type.vec3d", stringFormat, option);
}
}
}
@@ -347,7 +353,7 @@ public final class ResourceConfigUtils {
public static AABB getAsAABB(Object o, String option) {
switch (o) {
case null -> throw new LocalizedResourceConfigException("warning.config.id.aabb", "null", option);
case null -> throw new LocalizedResourceConfigException("warning.config.type.aabb", "null", option);
case AABB aabb -> {
return aabb;
}
@@ -367,7 +373,7 @@ public final class ResourceConfigUtils {
try {
args[i] = Double.parseDouble(list.get(i).toString());
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.id.aabb", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.aabb", o.toString(), option);
}
}
}
@@ -378,7 +384,7 @@ public final class ResourceConfigUtils {
try {
args[i] = Double.parseDouble(split[i]);
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("warning.config.id.aabb", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.aabb", o.toString(), option);
}
}
}
@@ -391,7 +397,7 @@ public final class ResourceConfigUtils {
} else if (args.length == 6) {
return new AABB(args[0], args[1], args[2], args[3], args[4], args[5]);
} else {
throw new LocalizedResourceConfigException("warning.config.id.aabb", o.toString(), option);
throw new LocalizedResourceConfigException("warning.config.type.aabb", o.toString(), option);
}
}
}

View File

@@ -156,7 +156,7 @@ public final class SNBTReader extends DefaultStringReader {
// 1.21.6的SNBT原版是支持 {key:[B;1,2b,0xFF]} 这种奇葩写法的, 越界部分会被自动舍弃, 如0xff的byte值为-1.
// 如果需要和原版对齐, 那么只需要判断是否是数字就行了.
// if (!(element instanceof Number number))
// throw new IllegalArgumentException("Error element id at pos " + getCursor());
// throw new IllegalArgumentException("Error element type at pos " + getCursor());
if (!(element instanceof Number number))
throw new IllegalArgumentException("Error parsing number at pos " + getCursor());

View File

@@ -6,9 +6,9 @@ import java.util.Objects;
* A generic class representing a tuple with three values.
* This class provides methods for creating and accessing tuples with three values.
*
* @param <L> the id of the left value
* @param <M> the id of the middle value
* @param <R> the id of the right value
* @param <L> the type of the left value
* @param <M> the type of the middle value
* @param <R> the type of the right value
*/
public record Tuple<L, M, R>(L left, M mid, R right) {
@@ -18,9 +18,9 @@ public record Tuple<L, M, R>(L left, M mid, R right) {
* @param left the left value
* @param mid the middle value
* @param right the right value
* @param <L> the id of the left value
* @param <M> the id of the middle value
* @param <R> the id of the right value
* @param <L> the type of the left value
* @param <M> the type of the middle value
* @param <R> the type of the right value
* @return a new {@link Tuple} with the specified values
*/
public static <L, M, R> Tuple<L, M, R> of(final L left, final M mid, final R right) {

View File

@@ -8,18 +8,18 @@ public class TypeUtils {
private TypeUtils() {}
/**
* Checks if the provided object is of the specified id.
* Checks if the provided object is of the specified type.
* If not, throws an IllegalArgumentException with a detailed message.
*
* @param object The object to check.
* @param expectedType The expected class id.
* @param <T> The id parameter for expectedType.
* @return The object cast to the expected id if it matches.
* @throws IllegalArgumentException if the object's id does not match the expected id.
* @param expectedType The expected class type.
* @param <T> The type parameter for expectedType.
* @return The object cast to the expected type if it matches.
* @throws IllegalArgumentException if the object's type does not match the expected type.
*/
public static <T> T checkType(Object object, Class<T> expectedType) {
if (!expectedType.isInstance(object)) {
throw new IllegalArgumentException("Expected id: " + expectedType.getName() +
throw new IllegalArgumentException("Expected type: " + expectedType.getName() +
", but got: " + (object == null ? "null" : object.getClass().getName()));
}
return expectedType.cast(object);
@@ -48,7 +48,7 @@ public class TypeUtils {
}
yield bytes;
}
default -> throw new IllegalStateException("Unsupported id: " + type.toLowerCase(Locale.ENGLISH));
default -> throw new IllegalStateException("Unsupported type: " + type.toLowerCase(Locale.ENGLISH));
};
}