mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
@@ -80,7 +80,7 @@ public final class CraftEngineFurniture {
|
|||||||
*
|
*
|
||||||
* @param location location
|
* @param location location
|
||||||
* @param furnitureId furniture to place
|
* @param furnitureId furniture to place
|
||||||
* @param anchorType anchor id
|
* @param anchorType anchor type
|
||||||
* @return the loaded furniture
|
* @return the loaded furniture
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -98,7 +98,7 @@ public final class CraftEngineFurniture {
|
|||||||
*
|
*
|
||||||
* @param location location
|
* @param location location
|
||||||
* @param furniture furniture to place
|
* @param furniture furniture to place
|
||||||
* @param anchorType anchor id
|
* @param anchorType anchor type
|
||||||
* @return the loaded furniture
|
* @return the loaded furniture
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -114,7 +114,7 @@ public final class CraftEngineFurniture {
|
|||||||
*
|
*
|
||||||
* @param location location
|
* @param location location
|
||||||
* @param furnitureId furniture to place
|
* @param furnitureId furniture to place
|
||||||
* @param anchorType anchor id
|
* @param anchorType anchor type
|
||||||
* @param playSound whether to play place sounds
|
* @param playSound whether to play place sounds
|
||||||
* @return the loaded furniture
|
* @return the loaded furniture
|
||||||
*/
|
*/
|
||||||
@@ -133,7 +133,7 @@ public final class CraftEngineFurniture {
|
|||||||
*
|
*
|
||||||
* @param location location
|
* @param location location
|
||||||
* @param furniture furniture to place
|
* @param furniture furniture to place
|
||||||
* @param anchorType anchor id
|
* @param anchorType anchor type
|
||||||
* @param playSound whether to play place sounds
|
* @param playSound whether to play place sounds
|
||||||
* @return the loaded furniture
|
* @return the loaded furniture
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public final class AsyncResourcePackCacheEvent extends Event {
|
|||||||
* Adds an external resource pack to the cache.
|
* Adds an external resource pack to the cache.
|
||||||
* <p>
|
* <p>
|
||||||
* This method accepts either a .zip file or a directory path representing a resource pack.
|
* This method accepts either a .zip file or a directory path representing a resource pack.
|
||||||
* The resource pack will be added to the appropriate cache collection based on its id.
|
* The resource pack will be added to the appropriate cache collection based on its type.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param path the file system path to the resource pack. Must be either a .zip file or a directory.
|
* @param path the file system path to the resource pack. Must be either a .zip file or a directory.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class NearLiquidBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
|||||||
public static class Factory implements BlockBehaviorFactory {
|
public static class Factory implements BlockBehaviorFactory {
|
||||||
@Override
|
@Override
|
||||||
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
|
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
|
||||||
List<String> liquidTypes = MiscUtils.getAsStringList(arguments.getOrDefault("liquid-id", List.of("water")));
|
List<String> liquidTypes = MiscUtils.getAsStringList(arguments.getOrDefault("liquid-type", List.of("water")));
|
||||||
boolean stackable = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("stackable", false), "stackable");
|
boolean stackable = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("stackable", false), "stackable");
|
||||||
int delay = ResourceConfigUtils.getAsInt(arguments.getOrDefault("delay", 0), "delay");
|
int delay = ResourceConfigUtils.getAsInt(arguments.getOrDefault("delay", 0), "delay");
|
||||||
List<String> positionsToCheck = MiscUtils.getAsStringList(arguments.getOrDefault("positions", List.of()));
|
List<String> positionsToCheck = MiscUtils.getAsStringList(arguments.getOrDefault("positions", List.of()));
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class OnLiquidBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
|||||||
public static class Factory implements BlockBehaviorFactory {
|
public static class Factory implements BlockBehaviorFactory {
|
||||||
@Override
|
@Override
|
||||||
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
|
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
|
||||||
List<String> liquidTypes = MiscUtils.getAsStringList(arguments.getOrDefault("liquid-id", List.of("water")));
|
List<String> liquidTypes = MiscUtils.getAsStringList(arguments.getOrDefault("liquid-type", List.of("water")));
|
||||||
boolean stackable = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("stackable", false), "stackable");
|
boolean stackable = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("stackable", false), "stackable");
|
||||||
int delay = ResourceConfigUtils.getAsInt(arguments.getOrDefault("delay", 0), "delay");
|
int delay = ResourceConfigUtils.getAsInt(arguments.getOrDefault("delay", 0), "delay");
|
||||||
return new OnLiquidBlockBehavior(block, delay, stackable, liquidTypes.contains("water"), liquidTypes.contains("lava"));
|
return new OnLiquidBlockBehavior(block, delay, stackable, liquidTypes.contains("water"), liquidTypes.contains("lava"));
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public class ItemDisplayEntityData<T> extends DisplayEntityData<T> {
|
|||||||
// Item display only
|
// Item display only
|
||||||
public static final ItemDisplayEntityData<Object> DisplayedItem = new ItemDisplayEntityData<>(ItemDisplayEntityData.class, EntityDataValue.Serializers$ITEM_STACK, CoreReflections.instance$ItemStack$EMPTY);
|
public static final ItemDisplayEntityData<Object> DisplayedItem = new ItemDisplayEntityData<>(ItemDisplayEntityData.class, EntityDataValue.Serializers$ITEM_STACK, CoreReflections.instance$ItemStack$EMPTY);
|
||||||
/**
|
/**
|
||||||
* Display id:
|
* Display type:
|
||||||
* 0 = NONE
|
* 0 = NONE
|
||||||
* 1 = THIRD_PERSON_LEFT_HAND
|
* 1 = THIRD_PERSON_LEFT_HAND
|
||||||
* 2 = THIRD_PERSON_RIGHT_HAND
|
* 2 = THIRD_PERSON_RIGHT_HAND
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
||||||
|
|
||||||
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxTypes;
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxTypes;
|
||||||
|
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||||
|
|
||||||
public class BukkitFurnitureHitboxTypes extends FurnitureHitBoxTypes {
|
public class BukkitFurnitureHitboxTypes extends FurnitureHitBoxTypes {
|
||||||
|
|
||||||
@@ -9,7 +10,9 @@ public class BukkitFurnitureHitboxTypes extends FurnitureHitBoxTypes {
|
|||||||
static {
|
static {
|
||||||
register(INTERACTION, InteractionFurnitureHitboxConfig.FACTORY);
|
register(INTERACTION, InteractionFurnitureHitboxConfig.FACTORY);
|
||||||
register(SHULKER, ShulkerFurnitureHitboxConfig.FACTORY);
|
register(SHULKER, ShulkerFurnitureHitboxConfig.FACTORY);
|
||||||
// register(HAPPY_GHAST, HappyGhastFurnitureHitboxConfig.FACTORY);
|
// register(CUSTOM, CustomFurnitureHitboxConfig.FACTORY);
|
||||||
// register(CUSTOM, CustomFurnitureHitboxConfig.FACTORY);
|
if (VersionHelper.isOrAbove1_21_6()) {
|
||||||
|
register(HAPPY_GHAST, HappyGhastFurnitureHitboxConfig.FACTORY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeHolders;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
|
||||||
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.Collider;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart;
|
||||||
|
import net.momirealms.craftengine.core.entity.player.Player;
|
||||||
|
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||||
|
import net.momirealms.craftengine.core.util.QuaternionUtils;
|
||||||
|
import net.momirealms.craftengine.core.world.Vec3d;
|
||||||
|
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||||
|
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class HappyGhastFurnitureHitbox extends AbstractFurnitureHitBox {
|
||||||
|
private final HappyGhastFurnitureHitboxConfig config;
|
||||||
|
private final Collider collider;
|
||||||
|
private final Object spawnPacket;
|
||||||
|
private final Object despawnPacket;
|
||||||
|
private final FurnitureHitboxPart part;
|
||||||
|
|
||||||
|
public HappyGhastFurnitureHitbox(Furniture furniture, HappyGhastFurnitureHitboxConfig config) {
|
||||||
|
super(furniture, config);
|
||||||
|
this.config = config;
|
||||||
|
WorldPosition position = furniture.position();
|
||||||
|
Quaternionf conjugated = QuaternionUtils.toQuaternionf(0f, (float) Math.toRadians(180 - position.yRot()), 0f).conjugate();
|
||||||
|
Vector3f offset = conjugated.transform(new Vector3f(config.position()));
|
||||||
|
Vec3d pos = Furniture.getRelativePosition(position, config.position());
|
||||||
|
AABB aabb = AABB.fromInteraction(pos, 3 * config.scale(), 3 * config.scale());
|
||||||
|
int happyGhastId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||||
|
List<Object> packets = new ArrayList<>(3);
|
||||||
|
packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
||||||
|
happyGhastId, UUID.randomUUID(), position.x + offset.x, position.y + offset.y, position.z + offset.z, 0, position.yRot,
|
||||||
|
MEntityTypes.HAPPY_GHAST, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||||
|
));
|
||||||
|
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(happyGhastId, config.cachedValues()));
|
||||||
|
if (config.scale() != 1) {
|
||||||
|
try {
|
||||||
|
Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {});
|
||||||
|
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale());
|
||||||
|
packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(happyGhastId, Collections.singletonList(attributeInstance)));
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
CraftEngine.instance().logger().warn("Failed to apply scale attribute", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.collider = createCollider(furniture.world(), pos, aabb, config.hardCollision(), config.blocksBuilding(), config.canBeHitByProjectile());
|
||||||
|
this.part = new FurnitureHitboxPart(happyGhastId, aabb, pos);
|
||||||
|
this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
|
||||||
|
this.despawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(new IntArrayList() {{ add(happyGhastId); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Collider> colliders() {
|
||||||
|
return List.of(this.collider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FurnitureHitboxPart> parts() {
|
||||||
|
return List.of(this.part);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(Player player) {
|
||||||
|
player.sendPacket(this.spawnPacket, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide(Player player) {
|
||||||
|
player.sendPacket(this.despawnPacket, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HappyGhastFurnitureHitboxConfig config() {
|
||||||
|
return this.config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.bukkit.entity.data.HappyGhastData;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.AbstractFurnitureHitBoxConfig;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxConfig;
|
||||||
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxConfigFactory;
|
||||||
|
import net.momirealms.craftengine.core.entity.seat.SeatConfig;
|
||||||
|
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||||
|
import net.momirealms.craftengine.core.world.Vec3d;
|
||||||
|
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||||
|
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class HappyGhastFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<HappyGhastFurnitureHitbox> {
|
||||||
|
public static final Factory FACTORY = new Factory();
|
||||||
|
private final double scale;
|
||||||
|
private final boolean hardCollision;
|
||||||
|
private final List<Object> cachedValues = new ArrayList<>(3);
|
||||||
|
|
||||||
|
public HappyGhastFurnitureHitboxConfig(SeatConfig[] seats,
|
||||||
|
Vector3f position,
|
||||||
|
boolean canUseItemOn,
|
||||||
|
boolean blocksBuilding,
|
||||||
|
boolean canBeHitByProjectile,
|
||||||
|
double scale,
|
||||||
|
boolean hardCollision) {
|
||||||
|
super(seats, position, canUseItemOn, blocksBuilding, canBeHitByProjectile);
|
||||||
|
this.scale = scale;
|
||||||
|
this.hardCollision = hardCollision;
|
||||||
|
HappyGhastData.StaysStill.addEntityDataIfNotDefaultValue(hardCollision, this.cachedValues);
|
||||||
|
HappyGhastData.MobFlags.addEntityDataIfNotDefaultValue((byte) 0x01, this.cachedValues); // NO AI
|
||||||
|
HappyGhastData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, this.cachedValues); // Invisible
|
||||||
|
}
|
||||||
|
|
||||||
|
public double scale() {
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hardCollision() {
|
||||||
|
return hardCollision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> cachedValues() {
|
||||||
|
return cachedValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HappyGhastFurnitureHitbox create(Furniture furniture) {
|
||||||
|
return new HappyGhastFurnitureHitbox(furniture, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) {
|
||||||
|
if (this.blocksBuilding) {
|
||||||
|
Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position);
|
||||||
|
aabbConsumer.accept(AABB.fromInteraction(relativePosition, 3 * this.scale, 3 * this.scale));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements FurnitureHitBoxConfigFactory<HappyGhastFurnitureHitbox> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FurnitureHitBoxConfig<HappyGhastFurnitureHitbox> create(Map<String, Object> arguments) {
|
||||||
|
Vector3f position = ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0), "position");
|
||||||
|
boolean canUseItemOn = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("can-use-item-on", true), "can-use-item-on");
|
||||||
|
boolean blocksBuilding = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("blocks-building", true), "blocks-building");
|
||||||
|
boolean canBeHitByProjectile = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("can-be-hit-by-projectile", true), "can-be-hit-by-projectile");
|
||||||
|
double scale = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("scale", 1), "scale");
|
||||||
|
boolean hardCollision = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("hard-collision", true), "hard-collision");
|
||||||
|
return new HappyGhastFurnitureHitboxConfig(
|
||||||
|
SeatConfig.fromObj(arguments.get("seats")),
|
||||||
|
position, canUseItemOn, blocksBuilding, canBeHitByProjectile,
|
||||||
|
scale, hardCollision
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData;
|
|
||||||
import net.momirealms.craftengine.bukkit.entity.data.InteractionEntityData;
|
|
||||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
|
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
|
||||||
@@ -14,7 +12,6 @@ import net.momirealms.craftengine.core.world.Vec3d;
|
|||||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||||
import net.momirealms.craftengine.core.world.collision.AABB;
|
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -30,22 +27,15 @@ public class InteractionFurnitureHitbox extends AbstractFurnitureHitBox {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
WorldPosition position = furniture.position();
|
WorldPosition position = furniture.position();
|
||||||
Vec3d pos = Furniture.getRelativePosition(position, config.position());
|
Vec3d pos = Furniture.getRelativePosition(position, config.position());
|
||||||
AABB aabb = AABB.fromInteraction(pos, config.size.x, config.size.y);
|
AABB aabb = AABB.fromInteraction(pos, config.size().x, config.size().y);
|
||||||
this.collider = createCollider(furniture.world(), pos, aabb, false, config.blocksBuilding(), config.canBeHitByProjectile());
|
this.collider = createCollider(furniture.world(), pos, aabb, false, config.blocksBuilding(), config.canBeHitByProjectile());
|
||||||
int interactionId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
int interactionId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||||
List<Object> values = new ArrayList<>(4);
|
|
||||||
InteractionEntityData.Height.addEntityDataIfNotDefaultValue(config.size.y, values);
|
|
||||||
InteractionEntityData.Width.addEntityDataIfNotDefaultValue(config.size.x, values);
|
|
||||||
InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(config.responsive, values);
|
|
||||||
if (config.invisible) {
|
|
||||||
BaseEntityData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, values);
|
|
||||||
}
|
|
||||||
this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(List.of(
|
this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(List.of(
|
||||||
FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
||||||
interactionId, UUID.randomUUID(), position.x, position.y, position.z, 0, position.yRot,
|
interactionId, UUID.randomUUID(), position.x, position.y, position.z, 0, position.yRot,
|
||||||
MEntityTypes.INTERACTION, 0, CoreReflections.instance$Vec3$Zero, 0
|
MEntityTypes.INTERACTION, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||||
),
|
),
|
||||||
FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(interactionId, values)
|
FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(interactionId, config.cachedValues())
|
||||||
));
|
));
|
||||||
this.part = new FurnitureHitboxPart(interactionId, aabb, pos);
|
this.part = new FurnitureHitboxPart(interactionId, aabb, pos);
|
||||||
this.despawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(new IntArrayList() {{ add(interactionId); }});
|
this.despawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(new IntArrayList() {{ add(interactionId); }});
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData;
|
||||||
|
import net.momirealms.craftengine.bukkit.entity.data.InteractionEntityData;
|
||||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||||
import net.momirealms.craftengine.core.entity.furniture.hitbox.AbstractFurnitureHitBoxConfig;
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.AbstractFurnitureHitBoxConfig;
|
||||||
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxConfigFactory;
|
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxConfigFactory;
|
||||||
@@ -10,16 +12,19 @@ import net.momirealms.craftengine.core.world.WorldPosition;
|
|||||||
import net.momirealms.craftengine.core.world.collision.AABB;
|
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class InteractionFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<InteractionFurnitureHitbox> {
|
public class InteractionFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<InteractionFurnitureHitbox> {
|
||||||
public static final Factory FACTORY = new Factory();
|
public static final Factory FACTORY = new Factory();
|
||||||
public static final InteractionFurnitureHitboxConfig DEFAULT = new InteractionFurnitureHitboxConfig(new SeatConfig[0], new Vector3f(), false, false, false, false, new Vector3f(1,1,1), true);
|
public static final InteractionFurnitureHitboxConfig DEFAULT = new InteractionFurnitureHitboxConfig();
|
||||||
|
|
||||||
public final Vector3f size;
|
private final Vector3f size;
|
||||||
public final boolean responsive;
|
private final boolean responsive;
|
||||||
public final boolean invisible;
|
private final boolean invisible;
|
||||||
|
private final List<Object> cachedValues = new ArrayList<>(4);
|
||||||
|
|
||||||
public InteractionFurnitureHitboxConfig(SeatConfig[] seats,
|
public InteractionFurnitureHitboxConfig(SeatConfig[] seats,
|
||||||
Vector3f position,
|
Vector3f position,
|
||||||
@@ -33,6 +38,19 @@ public class InteractionFurnitureHitboxConfig extends AbstractFurnitureHitBoxCon
|
|||||||
this.size = size;
|
this.size = size;
|
||||||
this.responsive = responsive;
|
this.responsive = responsive;
|
||||||
this.invisible = invisible;
|
this.invisible = invisible;
|
||||||
|
InteractionEntityData.Height.addEntityDataIfNotDefaultValue(size.y, cachedValues);
|
||||||
|
InteractionEntityData.Width.addEntityDataIfNotDefaultValue(size.x, cachedValues);
|
||||||
|
InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(responsive, cachedValues);
|
||||||
|
if (invisible) {
|
||||||
|
BaseEntityData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, cachedValues);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private InteractionFurnitureHitboxConfig() {
|
||||||
|
super(new SeatConfig[0], new Vector3f(), false, false, false);
|
||||||
|
this.size = new Vector3f(1);
|
||||||
|
this.responsive = true;
|
||||||
|
this.invisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f size() {
|
public Vector3f size() {
|
||||||
@@ -47,6 +65,10 @@ public class InteractionFurnitureHitboxConfig extends AbstractFurnitureHitBoxCon
|
|||||||
return invisible;
|
return invisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Object> cachedValues() {
|
||||||
|
return cachedValues;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) {
|
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) {
|
||||||
if (this.blocksBuilding) {
|
if (this.blocksBuilding) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class ShulkerFurnitureHitbox extends AbstractFurnitureHitBox {
|
|||||||
entityIds[1], UUID.randomUUID(), x + offset.x, processedY, z - offset.z, 0, yaw,
|
entityIds[1], UUID.randomUUID(), x + offset.x, processedY, z - offset.z, 0, yaw,
|
||||||
MEntityTypes.SHULKER, 0, CoreReflections.instance$Vec3$Zero, 0
|
MEntityTypes.SHULKER, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||||
));
|
));
|
||||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.copyOf(config.cachedShulkerValues)));
|
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.copyOf(config.cachedShulkerValues())));
|
||||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetPassengersPacket(entityIds[0], entityIds[1]));
|
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetPassengersPacket(entityIds[0], entityIds[1]));
|
||||||
|
|
||||||
// fix some special occasions
|
// fix some special occasions
|
||||||
@@ -73,16 +73,16 @@ public class ShulkerFurnitureHitbox extends AbstractFurnitureHitBox {
|
|||||||
CraftEngine.instance().logger().warn("Failed to construct ClientboundMoveEntityPacket$Pos", e);
|
CraftEngine.instance().logger().warn("Failed to construct ClientboundMoveEntityPacket$Pos", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (VersionHelper.isOrAbove1_20_5() && config.scale != 1) {
|
if (VersionHelper.isOrAbove1_20_5() && config.scale() != 1) {
|
||||||
try {
|
try {
|
||||||
Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {});
|
Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {});
|
||||||
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale);
|
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale());
|
||||||
packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityIds[1], Collections.singletonList(attributeInstance)));
|
packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityIds[1], Collections.singletonList(attributeInstance)));
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
CraftEngine.instance().logger().warn("Failed to apply scale attribute", e);
|
CraftEngine.instance().logger().warn("Failed to apply scale attribute", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.spawner.accept(entityIds, position.world(), x, y, z, yaw, offset, packets::add, colliders::add, parts::add);
|
config.spawner().accept(entityIds, position.world(), x, y, z, yaw, offset, packets::add, colliders::add, parts::add);
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
this.colliders = colliders;
|
this.colliders = colliders;
|
||||||
this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
|
this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
|
||||||
@@ -115,8 +115,8 @@ public class ShulkerFurnitureHitbox extends AbstractFurnitureHitBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int[] acquireEntityIds(Supplier<Integer> entityIdSupplier) {
|
public int[] acquireEntityIds(Supplier<Integer> entityIdSupplier) {
|
||||||
if (config.interactionEntity) {
|
if (config.interactionEntity()) {
|
||||||
if (config.direction.stepY() != 0) {
|
if (config.direction().stepY() != 0) {
|
||||||
// 展示实体 // 潜影贝 // 交互实体
|
// 展示实体 // 潜影贝 // 交互实体
|
||||||
return new int[] {entityIdSupplier.get(), entityIdSupplier.get(), entityIdSupplier.get()};
|
return new int[] {entityIdSupplier.get(), entityIdSupplier.get(), entityIdSupplier.get()};
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<ShulkerFurnitureHitbox> {
|
public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<ShulkerFurnitureHitbox> {
|
||||||
public static final Factory FACTORY = new Factory();
|
public static final Factory FACTORY = new Factory();
|
||||||
public final float scale;
|
private final float scale;
|
||||||
public final byte peek;
|
private final byte peek;
|
||||||
public final boolean interactive;
|
private final boolean interactive;
|
||||||
public final boolean interactionEntity;
|
private final boolean interactionEntity;
|
||||||
public final Direction direction;
|
private final Direction direction;
|
||||||
public final DirectionalShulkerSpawner spawner;
|
private final DirectionalShulkerSpawner spawner;
|
||||||
public final List<Object> cachedShulkerValues = new ArrayList<>();
|
private final List<Object> cachedShulkerValues = new ArrayList<>(6);
|
||||||
public final AABBCreator aabbCreator;
|
private final AABBCreator aabbCreator;
|
||||||
|
|
||||||
public ShulkerFurnitureHitboxConfig(SeatConfig[] seats,
|
public ShulkerFurnitureHitboxConfig(SeatConfig[] seats,
|
||||||
Vector3f position,
|
Vector3f position,
|
||||||
@@ -178,6 +178,14 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<
|
|||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DirectionalShulkerSpawner spawner() {
|
||||||
|
return spawner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> cachedShulkerValues() {
|
||||||
|
return cachedShulkerValues;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShulkerFurnitureHitbox create(Furniture furniture) {
|
public ShulkerFurnitureHitbox create(Furniture furniture) {
|
||||||
return new ShulkerFurnitureHitbox(furniture, this);
|
return new ShulkerFurnitureHitbox(furniture, this);
|
||||||
@@ -297,8 +305,8 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShulkerFurnitureHitboxConfig create(Map<String, Object> arguments) {
|
public ShulkerFurnitureHitboxConfig create(Map<String, Object> arguments) {
|
||||||
Vector3f position = ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", "0"), "position");
|
Vector3f position = ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0), "position");
|
||||||
float scale = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("scale", "1"), "scale");
|
float scale = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("scale", 1), "scale");
|
||||||
byte peek = (byte) ResourceConfigUtils.getAsInt(arguments.getOrDefault("peek", 0), "peek");
|
byte peek = (byte) ResourceConfigUtils.getAsInt(arguments.getOrDefault("peek", 0), "peek");
|
||||||
Direction directionEnum = ResourceConfigUtils.getAsEnum(arguments.get("direction"), Direction.class, Direction.UP);
|
Direction directionEnum = ResourceConfigUtils.getAsEnum(arguments.get("direction"), Direction.class, Direction.UP);
|
||||||
boolean interactive = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("interactive", true), "interactive");
|
boolean interactive = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("interactive", true), "interactive");
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class BukkitPlatform implements Platform {
|
|||||||
Map<String, Object> map = (Map<String, Object>) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
|
Map<String, Object> map = (Map<String, Object>) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
|
||||||
return map.get("root");
|
return map.get("root");
|
||||||
} catch (CommandSyntaxException e) {
|
} catch (CommandSyntaxException e) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.id.snbt.invalid_syntax", e, nbt);
|
throw new LocalizedResourceConfigException("warning.config.type.snbt.invalid_syntax", e, nbt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class BukkitPlatform implements Platform {
|
|||||||
CompoundTag map = (CompoundTag) MRegistryOps.NBT.convertTo(MRegistryOps.SPARROW_NBT, tag);
|
CompoundTag map = (CompoundTag) MRegistryOps.NBT.convertTo(MRegistryOps.SPARROW_NBT, tag);
|
||||||
return map.get("root");
|
return map.get("root");
|
||||||
} catch (CommandSyntaxException e) {
|
} catch (CommandSyntaxException e) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.id.snbt.invalid_syntax", e, nbt);
|
throw new LocalizedResourceConfigException("warning.config.type.snbt.invalid_syntax", e, nbt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
|
|||||||
} else if (nbt instanceof short[]) {
|
} else if (nbt instanceof short[]) {
|
||||||
value = Arrays.toString((short[]) nbt);
|
value = Arrays.toString((short[]) nbt);
|
||||||
} else {
|
} else {
|
||||||
value = "Unknown array id";
|
value = "Unknown array type";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = nbt.toString();
|
value = nbt.toString();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSend
|
|||||||
super(commandManager, plugin);
|
super(commandManager, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||||
return builder
|
return builder
|
||||||
@@ -34,7 +35,7 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSend
|
|||||||
return CompletableFuture.completedFuture(plugin().furnitureManager().cachedSuggestions());
|
return CompletableFuture.completedFuture(plugin().furnitureManager().cachedSuggestions());
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.optional("anchor-id", EnumParser.enumParser(AnchorType.class))
|
.optional("anchor-type", EnumParser.enumParser(AnchorType.class))
|
||||||
.flag(FlagKeys.SILENT_FLAG)
|
.flag(FlagKeys.SILENT_FLAG)
|
||||||
.handler(context -> {
|
.handler(context -> {
|
||||||
// fixme 指令
|
// fixme 指令
|
||||||
@@ -47,7 +48,7 @@ public class DebugSpawnFurnitureCommand extends BukkitCommandFeature<CommandSend
|
|||||||
// }
|
// }
|
||||||
// Location location = context.get("location");
|
// Location location = context.get("location");
|
||||||
// FurnitureConfig customFurniture = optionalCustomFurniture.get();
|
// FurnitureConfig customFurniture = optionalCustomFurniture.get();
|
||||||
// AnchorType anchorType = (AnchorType) context.optional("anchor-id").orElse(customFurniture.getAnyAnchorType());
|
// AnchorType anchorType = (AnchorType) context.optional("anchor-type").orElse(customFurniture.getAnyAnchorType());
|
||||||
// boolean playSound = context.flags().hasFlag("silent");
|
// boolean playSound = context.flags().hasFlag("silent");
|
||||||
// CraftEngineFurniture.place(location, customFurniture, anchorType, playSound);
|
// CraftEngineFurniture.place(location, customFurniture, anchorType, playSound);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class ProjectilePacketHandler implements EntityPacketHandler {
|
|||||||
|
|
||||||
public void convertAddCustomProjectilePacket(FriendlyByteBuf buf, ByteBufPacketEvent event) {
|
public void convertAddCustomProjectilePacket(FriendlyByteBuf buf, ByteBufPacketEvent event) {
|
||||||
UUID uuid = buf.readUUID();
|
UUID uuid = buf.readUUID();
|
||||||
buf.readVarInt(); // id
|
buf.readVarInt(); // type
|
||||||
double x = buf.readDouble();
|
double x = buf.readDouble();
|
||||||
double y = buf.readDouble();
|
double y = buf.readDouble();
|
||||||
double z = buf.readDouble();
|
double z = buf.readDouble();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class PayloadHelper {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
NetworkCodec<FriendlyByteBuf, ModPacket> codec = (NetworkCodec<FriendlyByteBuf, ModPacket>) BuiltInRegistries.MOD_PACKET.getValue(data.type());
|
NetworkCodec<FriendlyByteBuf, ModPacket> codec = (NetworkCodec<FriendlyByteBuf, ModPacket>) BuiltInRegistries.MOD_PACKET.getValue(data.type());
|
||||||
if (codec == null) {
|
if (codec == null) {
|
||||||
CraftEngine.instance().logger().warn("Unknown data id class: " + data.getClass().getName());
|
CraftEngine.instance().logger().warn("Unknown data type class: " + data.getClass().getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||||
@@ -65,7 +65,7 @@ public class PayloadHelper {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
NetworkCodec<FriendlyByteBuf, ModPacket> codec = (NetworkCodec<FriendlyByteBuf, ModPacket>) BuiltInRegistries.MOD_PACKET.getValue(type);
|
NetworkCodec<FriendlyByteBuf, ModPacket> codec = (NetworkCodec<FriendlyByteBuf, ModPacket>) BuiltInRegistries.MOD_PACKET.getValue(type);
|
||||||
if (codec == null) {
|
if (codec == null) {
|
||||||
Debugger.COMMON.debug(() -> "Unknown data id received: " + type);
|
Debugger.COMMON.debug(() -> "Unknown data type received: " + type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public abstract class BlockBehavior {
|
|||||||
return (boolean) superMethod.call();
|
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
|
// 1.20.5+ BlockState state, PathComputationType pathComputationType
|
||||||
public boolean isPathFindable(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
public boolean isPathFindable(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception {
|
||||||
return (boolean) superMethod.call();
|
return (boolean) superMethod.call();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.concurrent.Callable;
|
|||||||
|
|
||||||
public interface IsPathFindableBlockBehavior {
|
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
|
// 1.20.5+ BlockState state, PathComputationType pathComputationType
|
||||||
boolean isPathFindable(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception;
|
boolean isPathFindable(Object thisBlock, Object[] args, Callable<Object> superMethod) throws Exception;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,15 @@ public abstract class BlockEntityElementConfigs {
|
|||||||
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
|
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
|
||||||
public static final Key ITEM = Key.of("craftengine:item");
|
public static final Key ITEM = Key.of("craftengine:item");
|
||||||
|
|
||||||
public static void register(Key key, BlockEntityElementConfigFactory type) {
|
public static void register(Key key, BlockEntityElementConfigFactory<?> type) {
|
||||||
((WritableRegistry<BlockEntityElementConfigFactory>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE)
|
((WritableRegistry<BlockEntityElementConfigFactory<?>>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE)
|
||||||
.register(ResourceKey.create(Registries.BLOCK_ENTITY_ELEMENT_TYPE.location(), key), type);
|
.register(ResourceKey.create(Registries.BLOCK_ENTITY_ELEMENT_TYPE.location(), key), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends BlockEntityElement> BlockEntityElementConfig<E> fromMap(Map<String, Object> arguments) {
|
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);
|
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) {
|
if (factory == null) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.block.state.entity_renderer.invalid_type", type.toString());
|
throw new LocalizedResourceConfigException("warning.config.block.state.entity_renderer.invalid_type", type.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public interface FurnitureConfig {
|
|||||||
if (optionalVariant.isPresent()) {
|
if (optionalVariant.isPresent()) {
|
||||||
variantName = optionalVariant.get();
|
variantName = optionalVariant.get();
|
||||||
} else {
|
} else {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
Optional<AnchorType> optionalAnchorType = accessor.anchorType();
|
Optional<AnchorType> optionalAnchorType = accessor.anchorType();
|
||||||
if (optionalAnchorType.isPresent()) {
|
if (optionalAnchorType.isPresent()) {
|
||||||
variantName = optionalAnchorType.get().name().toLowerCase(Locale.ROOT);
|
variantName = optionalAnchorType.get().name().toLowerCase(Locale.ROOT);
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public class FurnitureDataAccessor {
|
|||||||
this.data.putString(VARIANT, variant);
|
this.data.putString(VARIANT, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@ApiStatus.Obsolete
|
@ApiStatus.Obsolete
|
||||||
public Optional<AnchorType> anchorType() {
|
public Optional<AnchorType> anchorType() {
|
||||||
if (this.data.containsKey(ANCHOR_TYPE)) return Optional.of(AnchorType.byId(this.data.getInt(ANCHOR_TYPE)));
|
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
|
@ApiStatus.Obsolete
|
||||||
public FurnitureDataAccessor anchorType(AnchorType type) {
|
public FurnitureDataAccessor anchorType(@SuppressWarnings("deprecation") AnchorType type) {
|
||||||
this.data.putInt(ANCHOR_TYPE, type.getId());
|
this.data.putInt(ANCHOR_TYPE, type.getId());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,15 @@ public class FurnitureElementConfigs {
|
|||||||
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
|
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
|
||||||
public static final Key ITEM = Key.of("craftengine:item");
|
public static final Key ITEM = Key.of("craftengine:item");
|
||||||
|
|
||||||
public static void register(Key key, FurnitureElementConfigFactory type) {
|
public static void register(Key key, FurnitureElementConfigFactory<?> type) {
|
||||||
((WritableRegistry<FurnitureElementConfigFactory>) BuiltInRegistries.FURNITURE_ELEMENT_TYPE)
|
((WritableRegistry<FurnitureElementConfigFactory<?>>) BuiltInRegistries.FURNITURE_ELEMENT_TYPE)
|
||||||
.register(ResourceKey.create(Registries.FURNITURE_ELEMENT_TYPE.location(), key), type);
|
.register(ResourceKey.create(Registries.FURNITURE_ELEMENT_TYPE.location(), key), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends FurnitureElement> FurnitureElementConfig<E> fromMap(Map<String, Object> arguments) {
|
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);
|
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) {
|
if (factory == null) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.furniture.element.invalid_type", type.toString());
|
throw new LocalizedResourceConfigException("warning.config.furniture.element.invalid_type", type.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ public class FurnitureHitBoxTypes {
|
|||||||
public static final Key VIRTUAL = Key.of("minecraft:virtual");
|
public static final Key VIRTUAL = Key.of("minecraft:virtual");
|
||||||
public static final Key CUSTOM = Key.of("minecraft:custom");
|
public static final Key CUSTOM = Key.of("minecraft:custom");
|
||||||
|
|
||||||
public static void register(Key key, FurnitureHitBoxConfigFactory factory) {
|
public static void register(Key key, FurnitureHitBoxConfigFactory<?> factory) {
|
||||||
((WritableRegistry<FurnitureHitBoxConfigFactory>) BuiltInRegistries.FURNITURE_HITBOX_TYPE)
|
((WritableRegistry<FurnitureHitBoxConfigFactory<?>>) BuiltInRegistries.FURNITURE_HITBOX_TYPE)
|
||||||
.register(ResourceKey.create(Registries.FURNITURE_HITBOX_TYPE.location(), key), factory);
|
.register(ResourceKey.create(Registries.FURNITURE_HITBOX_TYPE.location(), key), factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <H extends FurnitureHitBox> FurnitureHitBoxConfig<H> fromMap(Map<String, Object> arguments) {
|
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);
|
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) {
|
if (factory == null) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.invalid_type", type.toString());
|
throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.invalid_type", type.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.util.Optional;
|
|||||||
* This interface provides methods for managing item properties such as custom model data,
|
* This interface provides methods for managing item properties such as custom model data,
|
||||||
* damage, display name, lore, enchantments, and tags.
|
* 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> {
|
public interface Item<I> {
|
||||||
|
|
||||||
|
|||||||
@@ -446,8 +446,8 @@ public class ItemSettings {
|
|||||||
Key customTridentItemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("item"), "warning.config.item.settings.projectile.missing_item"));
|
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));
|
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));
|
Billboard billboard = Billboard.valueOf(args.getOrDefault("billboard", "FIXED").toString().toUpperCase(Locale.ENGLISH));
|
||||||
Vector3f translation = ResourceConfigUtils.getAsVector3f(args.getOrDefault("translation", "0"), "translation");
|
Vector3f translation = ResourceConfigUtils.getAsVector3f(args.getOrDefault("translation", 0), "translation");
|
||||||
Vector3f scale = ResourceConfigUtils.getAsVector3f(args.getOrDefault("scale", "1"), "scale");
|
Vector3f scale = ResourceConfigUtils.getAsVector3f(args.getOrDefault("scale", 1), "scale");
|
||||||
Quaternionf rotation = ResourceConfigUtils.getAsQuaternionf(ResourceConfigUtils.get(args, "rotation"), "rotation");
|
Quaternionf rotation = ResourceConfigUtils.getAsQuaternionf(ResourceConfigUtils.get(args, "rotation"), "rotation");
|
||||||
double range = ResourceConfigUtils.getAsDouble(args.getOrDefault("range", 1), "range");
|
double range = ResourceConfigUtils.getAsDouble(args.getOrDefault("range", 1), "range");
|
||||||
return settings -> settings.projectileMeta(new ProjectileMeta(customTridentItemId, displayType, billboard, scale, translation, rotation, range));
|
return settings -> settings.projectileMeta(new ProjectileMeta(customTridentItemId, displayType, billboard, scale, translation, rotation, range));
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
|||||||
@Override
|
@Override
|
||||||
public CustomSmithingTransformRecipe<A> readMap(Key id, Map<String, Object> arguments) {
|
public CustomSmithingTransformRecipe<A> readMap(Key id, Map<String, Object> arguments) {
|
||||||
List<String> base = MiscUtils.getAsStringList(arguments.get("base"));
|
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"));
|
List<String> addition = MiscUtils.getAsStringList(arguments.get("addition"));
|
||||||
boolean mergeComponents = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("merge-components", true), "merge-components");
|
boolean mergeComponents = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("merge-components", true), "merge-components");
|
||||||
boolean mergeEnchantments = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("merge-enchantments", false), "merge-enchantments");
|
boolean mergeEnchantments = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("merge-enchantments", false), "merge-enchantments");
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public class CustomSmithingTrimRecipe<T> extends AbstractRecipe<T>
|
|||||||
@Override
|
@Override
|
||||||
public CustomSmithingTrimRecipe<A> readMap(Key id, Map<String, Object> arguments) {
|
public CustomSmithingTrimRecipe<A> readMap(Key id, Map<String, Object> arguments) {
|
||||||
List<String> base = MiscUtils.getAsStringList(arguments.get("base"));
|
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"));
|
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;
|
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,
|
return new CustomSmithingTrimRecipe<>(id,
|
||||||
|
|||||||
@@ -87,12 +87,12 @@ public class ApplyBonusCountFunction<T> extends AbstractLootConditionalFunction<
|
|||||||
public static Formula fromMap(Map<String, Object> map) {
|
public static Formula fromMap(Map<String, Object> map) {
|
||||||
String type = (String) map.get("type");
|
String type = (String) map.get("type");
|
||||||
if (type == null) {
|
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);
|
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
|
||||||
FormulaFactory factory = BuiltInRegistries.FORMULA_FACTORY.getValue(key);
|
FormulaFactory factory = BuiltInRegistries.FORMULA_FACTORY.getValue(key);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new IllegalArgumentException("Unknown formula id: " + type);
|
throw new IllegalArgumentException("Unknown formula type: " + type);
|
||||||
}
|
}
|
||||||
return factory.create(map);
|
return factory.create(map);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class ItemModels {
|
|||||||
Key key = Key.withDefaultNamespace(type, "minecraft");
|
Key key = Key.withDefaultNamespace(type, "minecraft");
|
||||||
ItemModelReader reader = BuiltInRegistries.ITEM_MODEL_READER.getValue(key);
|
ItemModelReader reader = BuiltInRegistries.ITEM_MODEL_READER.getValue(key);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
throw new IllegalArgumentException("Invalid item model id: " + key);
|
throw new IllegalArgumentException("Invalid item model type: " + key);
|
||||||
}
|
}
|
||||||
return reader.read(json);
|
return reader.read(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class ConditionProperties {
|
|||||||
Key key = Key.withDefaultNamespace(type, "minecraft");
|
Key key = Key.withDefaultNamespace(type, "minecraft");
|
||||||
ConditionPropertyReader reader = BuiltInRegistries.CONDITION_PROPERTY_READER.getValue(key);
|
ConditionPropertyReader reader = BuiltInRegistries.CONDITION_PROPERTY_READER.getValue(key);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
throw new IllegalArgumentException("Invalid condition property id: " + key);
|
throw new IllegalArgumentException("Invalid condition property type: " + key);
|
||||||
}
|
}
|
||||||
return reader.read(json);
|
return reader.read(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class RangeDispatchProperties {
|
|||||||
Key key = Key.withDefaultNamespace(type, "minecraft");
|
Key key = Key.withDefaultNamespace(type, "minecraft");
|
||||||
RangeDispatchPropertyReader reader = BuiltInRegistries.RANGE_DISPATCH_PROPERTY_READER.getValue(key);
|
RangeDispatchPropertyReader reader = BuiltInRegistries.RANGE_DISPATCH_PROPERTY_READER.getValue(key);
|
||||||
if (reader == null) {
|
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);
|
return reader.read(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class SelectProperties {
|
|||||||
Key key = Key.withDefaultNamespace(type, "minecraft");
|
Key key = Key.withDefaultNamespace(type, "minecraft");
|
||||||
SelectPropertyReader reader = BuiltInRegistries.SELECT_PROPERTY_READER.getValue(key);
|
SelectPropertyReader reader = BuiltInRegistries.SELECT_PROPERTY_READER.getValue(key);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
throw new IllegalArgumentException("Invalid select property id: " + key);
|
throw new IllegalArgumentException("Invalid select property type: " + key);
|
||||||
}
|
}
|
||||||
return reader.read(json);
|
return reader.read(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class SignSpecialModel implements SpecialModel {
|
|||||||
@Override
|
@Override
|
||||||
public SpecialModel create(Map<String, Object> arguments) {
|
public SpecialModel create(Map<String, Object> arguments) {
|
||||||
Key type = Key.of(arguments.get("type").toString());
|
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");
|
String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.sign.missing_texture");
|
||||||
return new SignSpecialModel(type, woodType, texture);
|
return new SignSpecialModel(type, woodType, texture);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class SpecialModels {
|
|||||||
Key key = Key.withDefaultNamespace(type, "minecraft");
|
Key key = Key.withDefaultNamespace(type, "minecraft");
|
||||||
SpecialModelReader reader = BuiltInRegistries.SPECIAL_MODEL_READER.getValue(key);
|
SpecialModelReader reader = BuiltInRegistries.SPECIAL_MODEL_READER.getValue(key);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
throw new IllegalArgumentException("Invalid special model id: " + key);
|
throw new IllegalArgumentException("Invalid special model type: " + key);
|
||||||
}
|
}
|
||||||
return reader.read(json);
|
return reader.read(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class Tints {
|
|||||||
Key key = Key.withDefaultNamespace(type, "minecraft");
|
Key key = Key.withDefaultNamespace(type, "minecraft");
|
||||||
TintReader reader = BuiltInRegistries.TINT_READER.getValue(key);
|
TintReader reader = BuiltInRegistries.TINT_READER.getValue(key);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
throw new IllegalArgumentException("Invalid tint id: " + type);
|
throw new IllegalArgumentException("Invalid tint type: " + type);
|
||||||
}
|
}
|
||||||
return reader.read(json);
|
return reader.read(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public enum ObfA {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown resource id: " + xclf);
|
throw new IllegalArgumentException("Unknown resource type: " + xclf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final byte[] VALUES = new byte[] {
|
public static final byte[] VALUES = new byte[] {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Simple implementation of {@link Sender} using a {@link SenderFactory}
|
* 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 {
|
public final class AbstractSender<T> implements Sender {
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|||||||
@@ -448,10 +448,10 @@ public class Config {
|
|||||||
|
|
||||||
// furniture
|
// furniture
|
||||||
furniture$hide_base_entity = config.getBoolean("furniture.hide-base-entity", true);
|
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
|
||||||
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)) {
|
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);
|
TranslationManager.instance().log("warning.config.equipment.invalid_sacrificed_armor", equipment$sacrificed_vanilla_armor$type);
|
||||||
equipment$sacrificed_vanilla_armor$type = "chainmail";
|
equipment$sacrificed_vanilla_armor$type = "chainmail";
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ public class StringKeyConstructor extends SafeConstructor {
|
|||||||
if (value instanceof Number number) {
|
if (value instanceof Number number) {
|
||||||
return number.byteValue();
|
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) {
|
if (value instanceof Number number) {
|
||||||
return number.shortValue();
|
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) {
|
if (value instanceof Number number) {
|
||||||
return number.longValue();
|
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) {
|
if (value instanceof Number number) {
|
||||||
return number.floatValue();
|
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) {
|
if (value instanceof Number number) {
|
||||||
return number.doubleValue();
|
return number.doubleValue();
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Unexpected id: " + value.getClass().getName());
|
throw new RuntimeException("Unexpected type: " + value.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class ExpressionTemplateArgument implements TemplateArgument {
|
|||||||
public TemplateArgument create(Map<String, Object> arguments) {
|
public TemplateArgument create(Map<String, Object> arguments) {
|
||||||
return new ExpressionTemplateArgument(
|
return new ExpressionTemplateArgument(
|
||||||
arguments.getOrDefault("expression", "").toString(),
|
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))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class TemplateArguments {
|
|||||||
Key key = Key.withDefaultNamespace(type0, Key.DEFAULT_NAMESPACE);
|
Key key = Key.withDefaultNamespace(type0, Key.DEFAULT_NAMESPACE);
|
||||||
TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key);
|
TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
throw new IllegalArgumentException("Unknown argument id: " + type);
|
throw new IllegalArgumentException("Unknown argument type: " + type);
|
||||||
}
|
}
|
||||||
return factory.create(map);
|
return factory.create(map);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class DamageFunction<CTX extends Context> extends AbstractConditionalFunc
|
|||||||
@Override
|
@Override
|
||||||
public Function<CTX> create(Map<String, Object> arguments) {
|
public Function<CTX> create(Map<String, Object> arguments) {
|
||||||
PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.getOrDefault("target", "self"), conditionFactory());
|
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));
|
NumberProvider amount = NumberProviders.fromObject(arguments.getOrDefault("amount", 1f));
|
||||||
return new DamageFunction<>(selector, damageType, amount, getPredicates(arguments));
|
return new DamageFunction<>(selector, damageType, amount, getPredicates(arguments));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class OpenWindowFunction<CTX extends Context> extends AbstractConditional
|
|||||||
@Override
|
@Override
|
||||||
public Function<CTX> create(Map<String, Object> arguments) {
|
public Function<CTX> create(Map<String, Object> arguments) {
|
||||||
String title = Optional.ofNullable(arguments.get("title")).map(String::valueOf).orElse(null);
|
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 {
|
try {
|
||||||
GuiType type = GuiType.valueOf(rawType.toUpperCase(Locale.ENGLISH));
|
GuiType type = GuiType.valueOf(rawType.toUpperCase(Locale.ENGLISH));
|
||||||
return new OpenWindowFunction<>(getPredicates(arguments), PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), type, title);
|
return new OpenWindowFunction<>(getPredicates(arguments), PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), type, title);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class ReplaceFurnitureFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
public class ReplaceFurnitureFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||||
private final Key newFurnitureId;
|
private final Key newFurnitureId;
|
||||||
private final NumberProvider x;
|
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 z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:furniture.z>"));
|
||||||
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", "<arg:furniture.pitch>"));
|
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", "<arg:furniture.pitch>"));
|
||||||
NumberProvider yaw = NumberProviders.fromObject(arguments.getOrDefault("yaw", "<arg:furniture.yaw>"));
|
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 dropLoot = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("drop-loot", true), "drop-loot");
|
||||||
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
|
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));
|
return new ReplaceFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, anchorType, dropLoot, playSound, getPredicates(arguments));
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class SpawnFurnitureFunction<CTX extends Context> extends AbstractConditi
|
|||||||
NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>"));
|
NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>"));
|
||||||
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", "<arg:position.pitch>"));
|
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", "<arg:position.pitch>"));
|
||||||
NumberProvider yaw = NumberProviders.fromObject(arguments.getOrDefault("yaw", "<arg:position.yaw>"));
|
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");
|
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
|
||||||
return new SpawnFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, variant, playSound, getPredicates(arguments));
|
return new SpawnFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, variant, playSound, getPredicates(arguments));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class ToastFunction<CTX extends Context> extends AbstractConditionalFunct
|
|||||||
@Override
|
@Override
|
||||||
public Function<CTX> create(Map<String, Object> arguments) {
|
public Function<CTX> create(Map<String, Object> arguments) {
|
||||||
AdvancementType advancementType;
|
AdvancementType advancementType;
|
||||||
String advancementName = arguments.getOrDefault("advancement-id", "goal").toString();
|
String advancementName = arguments.getOrDefault("advancement-type", "goal").toString();
|
||||||
try {
|
try {
|
||||||
advancementType = AdvancementType.valueOf(advancementName.toUpperCase(Locale.ROOT));
|
advancementType = AdvancementType.valueOf(advancementName.toUpperCase(Locale.ROOT));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class LangData {
|
|||||||
temp.put(result, entry.getValue());
|
temp.put(result, entry.getValue());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
() -> CraftEngine.instance().logger().warn("Unknown lang id: " + key)
|
() -> CraftEngine.instance().logger().warn("Unknown lang type: " + key)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
temp.put(key, entry.getValue());
|
temp.put(key, entry.getValue());
|
||||||
|
|||||||
@@ -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<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<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<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<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<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<FurnitureHitBoxConfigFactory<?>> FURNITURE_HITBOX_TYPE = createConstantBoundRegistry(Registries.FURNITURE_HITBOX_TYPE, 16);
|
||||||
|
|
||||||
private static <T> Registry<T> createConstantBoundRegistry(ResourceKey<? extends Registry<T>> key, int expectedSize) {
|
private static <T> Registry<T> createConstantBoundRegistry(ResourceKey<? extends Registry<T>> key, int expectedSize) {
|
||||||
return new ConstantBoundRegistry<>(key, expectedSize);
|
return new ConstantBoundRegistry<>(key, expectedSize);
|
||||||
|
|||||||
@@ -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<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<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<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<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<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<FurnitureHitBoxConfigFactory<?>>> FURNITURE_HITBOX_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_hitbox_type"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public record SoundData(Key id, SoundValue volume, SoundValue pitch) {
|
|||||||
SoundValue pitchValue = Optional.ofNullable(SoundValue.of(map.get("pitch"))).orElse(volume);
|
SoundValue pitchValue = Optional.ofNullable(SoundValue.of(map.get("pitch"))).orElse(volume);
|
||||||
return new SoundData(id, volumeValue, pitchValue);
|
return new SoundData(id, volumeValue, pitchValue);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Illegal object id for sound data: " + obj.getClass());
|
throw new IllegalArgumentException("Illegal object type for sound data: " + obj.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import java.util.Objects;
|
|||||||
* A generic class representing a pair of values.
|
* A generic class representing a pair of values.
|
||||||
* This class provides methods to create and access pairs of values.
|
* This class provides methods to create and access pairs of values.
|
||||||
*
|
*
|
||||||
* @param <L> the id of the left value
|
* @param <L> the type of the left value
|
||||||
* @param <R> the id of the right value
|
* @param <R> the type of the right value
|
||||||
*/
|
*/
|
||||||
public record Pair<L, R>(L left, R right) {
|
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 left the left value
|
||||||
* @param right the right value
|
* @param right the right value
|
||||||
* @param <L> the id of the left value
|
* @param <L> the type of the left value
|
||||||
* @param <R> the id of the right value
|
* @param <R> the type of the right value
|
||||||
* @return a new {@link Pair} with the specified values
|
* @return a new {@link Pair} with the specified values
|
||||||
*/
|
*/
|
||||||
public static <L, R> Pair<L, R> of(final L left, final R right) {
|
public static <L, R> Pair<L, R> of(final L left, final R right) {
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ public class ReflectionUtils {
|
|||||||
public static List<Method> getMethods(@NotNull Class<?> clazz, @NotNull Class<?> returnType, @NotNull Class<?>... parameterTypes) {
|
public static List<Method> getMethods(@NotNull Class<?> clazz, @NotNull Class<?> returnType, @NotNull Class<?>... parameterTypes) {
|
||||||
List<Method> list = new ArrayList<>();
|
List<Method> list = new ArrayList<>();
|
||||||
for (Method method : clazz.getMethods()) {
|
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
|
|| method.getParameterCount() != parameterTypes.length // check length
|
||||||
) continue;
|
) continue;
|
||||||
Class<?>[] types = method.getParameterTypes();
|
Class<?>[] types = method.getParameterTypes();
|
||||||
|
|||||||
@@ -137,13 +137,13 @@ public final class ResourceConfigUtils {
|
|||||||
try {
|
try {
|
||||||
return Integer.parseInt(s.replace("_", ""));
|
return Integer.parseInt(s.replace("_", ""));
|
||||||
} catch (NumberFormatException e) {
|
} 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 -> {
|
case Boolean b -> {
|
||||||
return b ? 1 : 0;
|
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 {
|
try {
|
||||||
return Double.parseDouble(s);
|
return Double.parseDouble(s);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.id.double", e, s, option);
|
throw new LocalizedResourceConfigException("warning.config.type.double", e, s, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default -> {
|
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 {
|
try {
|
||||||
return Float.parseFloat(s);
|
return Float.parseFloat(s);
|
||||||
} catch (NumberFormatException e) {
|
} 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 -> {
|
case Number number -> {
|
||||||
return number.floatValue();
|
return number.floatValue();
|
||||||
}
|
}
|
||||||
default -> {
|
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 -> {
|
case Number n -> {
|
||||||
if (n.byteValue() == 0) return false;
|
if (n.byteValue() == 0) return false;
|
||||||
if (n.byteValue() == 1) return true;
|
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 -> {
|
case String s -> {
|
||||||
if (s.equalsIgnoreCase("true")) return true;
|
if (s.equalsIgnoreCase("true")) return true;
|
||||||
if (s.equalsIgnoreCase("false")) return false;
|
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 -> {
|
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 {
|
try {
|
||||||
return Long.parseLong(s.replace("_", ""));
|
return Long.parseLong(s.replace("_", ""));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.id.long", e, s, option);
|
throw new LocalizedResourceConfigException("warning.config.type.long", e, s, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default -> {
|
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) {
|
if (obj instanceof Map<?, ?> map) {
|
||||||
return (Map<String, Object>) 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")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -259,24 +259,30 @@ public final class ResourceConfigUtils {
|
|||||||
if (obj instanceof Map<?, ?> map) {
|
if (obj instanceof Map<?, ?> map) {
|
||||||
return (Map<String, Object>) 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) {
|
public static Vector3f getAsVector3f(Object o, String option) {
|
||||||
if (o == null) return new Vector3f();
|
switch (o) {
|
||||||
if (o instanceof List<?> list && list.size() == 3) {
|
case null -> {
|
||||||
return new Vector3f(Float.parseFloat(list.get(0).toString()), Float.parseFloat(list.get(1).toString()), Float.parseFloat(list.get(2).toString()));
|
return new Vector3f();
|
||||||
} else if (o instanceof Number number) {
|
}
|
||||||
return new Vector3f(number.floatValue());
|
case List<?> list when list.size() == 3 -> {
|
||||||
} else {
|
return new Vector3f(Float.parseFloat(list.get(0).toString()), Float.parseFloat(list.get(1).toString()), Float.parseFloat(list.get(2).toString()));
|
||||||
String stringFormat = o.toString();
|
}
|
||||||
String[] split = stringFormat.split(",");
|
case Number number -> {
|
||||||
if (split.length == 3) {
|
return new Vector3f(number.floatValue());
|
||||||
return new Vector3f(Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2]));
|
}
|
||||||
} else if (split.length == 1) {
|
default -> {
|
||||||
return new Vector3f(Float.parseFloat(split[0]));
|
String stringFormat = o.toString();
|
||||||
} else {
|
String[] split = stringFormat.split(",");
|
||||||
throw new LocalizedResourceConfigException("warning.config.id.vector3f", stringFormat, option);
|
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) {
|
} else if (split.length == 1) {
|
||||||
return QuaternionUtils.toQuaternionf(0, (float) -Math.toRadians(Float.parseFloat(split[0])), 0);
|
return QuaternionUtils.toQuaternionf(0, (float) -Math.toRadians(Float.parseFloat(split[0])), 0);
|
||||||
} else {
|
} 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]);
|
double d = Double.parseDouble(split[0]);
|
||||||
return new Vec3d(d, d, d);
|
return new Vec3d(d, d, d);
|
||||||
} else {
|
} 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) {
|
public static AABB getAsAABB(Object o, String option) {
|
||||||
switch (o) {
|
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 -> {
|
case AABB aabb -> {
|
||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
@@ -367,7 +373,7 @@ public final class ResourceConfigUtils {
|
|||||||
try {
|
try {
|
||||||
args[i] = Double.parseDouble(list.get(i).toString());
|
args[i] = Double.parseDouble(list.get(i).toString());
|
||||||
} catch (NumberFormatException e) {
|
} 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 {
|
try {
|
||||||
args[i] = Double.parseDouble(split[i]);
|
args[i] = Double.parseDouble(split[i]);
|
||||||
} catch (NumberFormatException e) {
|
} 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) {
|
} else if (args.length == 6) {
|
||||||
return new AABB(args[0], args[1], args[2], args[3], args[4], args[5]);
|
return new AABB(args[0], args[1], args[2], args[3], args[4], args[5]);
|
||||||
} else {
|
} else {
|
||||||
throw new LocalizedResourceConfigException("warning.config.id.aabb", o.toString(), option);
|
throw new LocalizedResourceConfigException("warning.config.type.aabb", o.toString(), option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public final class SNBTReader extends DefaultStringReader {
|
|||||||
// 1.21.6的SNBT原版是支持 {key:[B;1,2b,0xFF]} 这种奇葩写法的, 越界部分会被自动舍弃, 如0xff的byte值为-1.
|
// 1.21.6的SNBT原版是支持 {key:[B;1,2b,0xFF]} 这种奇葩写法的, 越界部分会被自动舍弃, 如0xff的byte值为-1.
|
||||||
// 如果需要和原版对齐, 那么只需要判断是否是数字就行了.
|
// 如果需要和原版对齐, 那么只需要判断是否是数字就行了.
|
||||||
// if (!(element instanceof Number number))
|
// 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))
|
if (!(element instanceof Number number))
|
||||||
throw new IllegalArgumentException("Error parsing number at pos " + getCursor());
|
throw new IllegalArgumentException("Error parsing number at pos " + getCursor());
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import java.util.Objects;
|
|||||||
* A generic class representing a tuple with three values.
|
* A generic class representing a tuple with three values.
|
||||||
* This class provides methods for creating and accessing tuples with three values.
|
* This class provides methods for creating and accessing tuples with three values.
|
||||||
*
|
*
|
||||||
* @param <L> the id of the left value
|
* @param <L> the type of the left value
|
||||||
* @param <M> the id of the middle value
|
* @param <M> the type of the middle value
|
||||||
* @param <R> the id of the right value
|
* @param <R> the type of the right value
|
||||||
*/
|
*/
|
||||||
public record Tuple<L, M, R>(L left, M mid, R right) {
|
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 left the left value
|
||||||
* @param mid the middle value
|
* @param mid the middle value
|
||||||
* @param right the right value
|
* @param right the right value
|
||||||
* @param <L> the id of the left value
|
* @param <L> the type of the left value
|
||||||
* @param <M> the id of the middle value
|
* @param <M> the type of the middle value
|
||||||
* @param <R> the id of the right value
|
* @param <R> the type of the right value
|
||||||
* @return a new {@link Tuple} with the specified values
|
* @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) {
|
public static <L, M, R> Tuple<L, M, R> of(final L left, final M mid, final R right) {
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ public class TypeUtils {
|
|||||||
private 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.
|
* If not, throws an IllegalArgumentException with a detailed message.
|
||||||
*
|
*
|
||||||
* @param object The object to check.
|
* @param object The object to check.
|
||||||
* @param expectedType The expected class id.
|
* @param expectedType The expected class type.
|
||||||
* @param <T> The id parameter for expectedType.
|
* @param <T> The type parameter for expectedType.
|
||||||
* @return The object cast to the expected id if it matches.
|
* @return The object cast to the expected type if it matches.
|
||||||
* @throws IllegalArgumentException if the object's id does not match the expected id.
|
* @throws IllegalArgumentException if the object's type does not match the expected type.
|
||||||
*/
|
*/
|
||||||
public static <T> T checkType(Object object, Class<T> expectedType) {
|
public static <T> T checkType(Object object, Class<T> expectedType) {
|
||||||
if (!expectedType.isInstance(object)) {
|
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()));
|
", but got: " + (object == null ? "null" : object.getClass().getName()));
|
||||||
}
|
}
|
||||||
return expectedType.cast(object);
|
return expectedType.cast(object);
|
||||||
@@ -48,7 +48,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
yield bytes;
|
yield bytes;
|
||||||
}
|
}
|
||||||
default -> throw new IllegalStateException("Unsupported id: " + type.toLowerCase(Locale.ENGLISH));
|
default -> throw new IllegalStateException("Unsupported type: " + type.toLowerCase(Locale.ENGLISH));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user