diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java index a10a9faa3..e742a7ecf 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java @@ -26,8 +26,8 @@ public class CustomHitBox extends AbstractHitBox { private final EntityType entityType; private final List cachedValues = new ArrayList<>(); - public CustomHitBox(Seat[] seats, Vector3f position, EntityType type, float scale) { - super(seats, position, false); + public CustomHitBox(Seat[] seats, Vector3f position, EntityType type, float scale, boolean blocksBuilding, boolean canBeHitByProjectile) { + super(seats, position, false, blocksBuilding, canBeHitByProjectile); this.scale = scale; this.entityType = type; BaseEntityData.NoGravity.addEntityDataIfNotDefaultValue(true, this.cachedValues); @@ -82,7 +82,9 @@ public class CustomHitBox extends AbstractHitBox { if (entityType == null) { throw new IllegalArgumentException("EntityType not found: " + arguments.get("entity-type")); } - return new CustomHitBox(HitBoxFactory.getSeats(arguments), position, entityType, scale); + boolean canBeHitByProjectile = (boolean) arguments.getOrDefault("can-be-hit-by-projectile", false); + boolean blocksBuilding = (boolean) arguments.getOrDefault("blocks-building", true); + return new CustomHitBox(HitBoxFactory.getSeats(arguments), position, entityType, scale, blocksBuilding, canBeHitByProjectile); } } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastHitBox.java index d6f133c33..32d3460ce 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastHitBox.java @@ -17,8 +17,8 @@ public class HappyGhastHitBox extends AbstractHitBox { public static final Factory FACTORY = new Factory(); private final double scale; - public HappyGhastHitBox(Seat[] seats, Vector3f position, double scale, boolean canUseOn) { - super(seats, position, canUseOn); + public HappyGhastHitBox(Seat[] seats, Vector3f position, double scale, boolean canUseOn, boolean blocksBuilding, boolean canBeHitByProjectile) { + super(seats, position, canUseOn, blocksBuilding, canBeHitByProjectile); this.scale = scale; } @@ -47,10 +47,12 @@ public class HappyGhastHitBox extends AbstractHitBox { public HitBox create(Map arguments) { double scale = MiscUtils.getAsDouble(arguments.getOrDefault("scale", "1")); boolean canUseOn = (boolean) arguments.getOrDefault("can-use-item-on", false); + boolean canBeHitByProjectile = (boolean) arguments.getOrDefault("can-be-hit-by-projectile", false); + boolean blocksBuilding = (boolean) arguments.getOrDefault("blocks-building", false); return new HappyGhastHitBox( HitBoxFactory.getSeats(arguments), MiscUtils.getVector3f(arguments.getOrDefault("position", "0")), - scale, canUseOn + scale, canUseOn, blocksBuilding, canBeHitByProjectile ); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionHitBox.java index c723b47ad..3d5b9c649 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionHitBox.java @@ -1,6 +1,7 @@ package net.momirealms.craftengine.bukkit.entity.furniture.hitbox; import net.momirealms.craftengine.bukkit.entity.data.InteractionEntityData; +import net.momirealms.craftengine.bukkit.entity.furniture.BukkitCollider; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.util.Reflections; import net.momirealms.craftengine.core.entity.furniture.*; @@ -22,14 +23,14 @@ import java.util.function.Supplier; public class InteractionHitBox extends AbstractHitBox { public static final Factory FACTORY = new Factory(); - public static final InteractionHitBox DEFAULT = new InteractionHitBox(new Seat[0], new Vector3f(), new Vector3f(1,1,1), true, false); + public static final InteractionHitBox DEFAULT = new InteractionHitBox(new Seat[0], new Vector3f(), new Vector3f(1,1,1), true, false, false, false); private final Vector3f size; private final boolean responsive; private final List cachedValues = new ArrayList<>(); - public InteractionHitBox(Seat[] seats, Vector3f position, Vector3f size, boolean responsive, boolean canUseOn) { - super(seats, position, canUseOn); + public InteractionHitBox(Seat[] seats, Vector3f position, Vector3f size, boolean responsive, boolean canUseOn, boolean blocksBuilding, boolean canBeHitByProjectile) { + super(seats, position, canUseOn, blocksBuilding, canBeHitByProjectile); this.size = size; this.responsive = responsive; InteractionEntityData.Height.addEntityDataIfNotDefaultValue(size.y, cachedValues); @@ -58,9 +59,17 @@ public class InteractionHitBox extends AbstractHitBox { Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 ), true); packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityId[0], List.copyOf(this.cachedValues)), true); - if (canPlaceAgainst()) { + if (canUseItemOn()) { aabb.accept(entityId[0], AABB.fromInteraction(new Vec3d(x + offset.x, y + offset.y, z - offset.z), this.size.x, this.size.y)); } + if (blocksBuilding()) { + AABB ceAABB = AABB.fromInteraction(new Vec3d(x + offset.x, y + offset.y, z - offset.z), this.size.x, this.size.y); + Object nmsAABB = FastNMS.INSTANCE.constructor$AABB(ceAABB.minX, ceAABB.minY, ceAABB.minZ, ceAABB.maxX, ceAABB.maxY, ceAABB.maxZ); + collider.accept(new BukkitCollider( + FastNMS.INSTANCE.createCollisionShulker(world.serverWorld(), nmsAABB, x, y, z, this.canBeHitByProjectile(), false, this.blocksBuilding()), + ColliderType.SHULKER + )); + } } @Override @@ -85,11 +94,13 @@ public class InteractionHitBox extends AbstractHitBox { } boolean canUseOn = (boolean) arguments.getOrDefault("can-use-item-on", false); boolean interactive = (boolean) arguments.getOrDefault("interactive", true); + boolean canBeHitByProjectile = (boolean) arguments.getOrDefault("can-be-hit-by-projectile", false); + boolean blocksBuilding = (boolean) arguments.getOrDefault("blocks-building", false); return new InteractionHitBox( HitBoxFactory.getSeats(arguments), position, new Vector3f(width, height, width), - interactive, canUseOn + interactive, canUseOn, blocksBuilding, canBeHitByProjectile ); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java index e6737e719..c78a5a68e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java @@ -30,8 +30,8 @@ public class ShulkerHitBox extends AbstractHitBox { private final List cachedShulkerValues = new ArrayList<>(); private final DirectionalShulkerSpawner spawner; - public ShulkerHitBox(Seat[] seats, Vector3f position, Direction direction, float scale, byte peek, boolean interactionEntity, boolean interactive, boolean canUseOn) { - super(seats, position, canUseOn); + public ShulkerHitBox(Seat[] seats, Vector3f position, Direction direction, float scale, byte peek, boolean interactionEntity, boolean interactive, boolean canUseOn, boolean blocksBuilding, boolean canBeHitByProjectile) { + super(seats, position, canUseOn, blocksBuilding, canBeHitByProjectile); this.direction = direction; this.scale = scale; this.peek = peek; @@ -152,7 +152,7 @@ public class ShulkerHitBox extends AbstractHitBox { Object nmsAABB = FastNMS.INSTANCE.constructor$AABB(minX, minY, minZ, maxX, maxY, maxZ); aabb.accept(entityId, new AABB(minX, minY, minZ, maxX, maxY, maxZ)); return new BukkitCollider( - FastNMS.INSTANCE.createCollisionShulker(level, nmsAABB, x, y, z, true), + FastNMS.INSTANCE.createCollisionShulker(level, nmsAABB, x, y, z, this.canBeHitByProjectile(), true, this.blocksBuilding()), ColliderType.SHULKER ); } @@ -258,10 +258,12 @@ public class ShulkerHitBox extends AbstractHitBox { boolean interactive = (boolean) arguments.getOrDefault("interactive", true); boolean interactionEntity = (boolean) arguments.getOrDefault("interaction-entity", true); boolean canUseItemOn = (boolean) arguments.getOrDefault("can-use-item-on", true); + boolean canBeHitByProjectile = (boolean) arguments.getOrDefault("can-be-hit-by-projectile", true); + boolean blocksBuilding = (boolean) arguments.getOrDefault("blocks-building", true); return new ShulkerHitBox( HitBoxFactory.getSeats(arguments), position, directionEnum, - scale, peek, interactionEntity, interactive, canUseItemOn + scale, peek, interactionEntity, interactive, canUseItemOn, blocksBuilding, canBeHitByProjectile ); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index afd5ca2c3..eceee5109 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -35,14 +35,16 @@ import net.momirealms.craftengine.core.plugin.network.ConnectionState; import net.momirealms.craftengine.core.plugin.network.NetWorkUser; import net.momirealms.craftengine.core.plugin.network.NetworkManager; import net.momirealms.craftengine.core.util.*; -import net.momirealms.craftengine.core.world.*; +import net.momirealms.craftengine.core.world.BlockHitResult; +import net.momirealms.craftengine.core.world.BlockPos; +import net.momirealms.craftengine.core.world.EntityHitResult; +import net.momirealms.craftengine.core.world.WorldEvents; import net.momirealms.craftengine.core.world.chunk.Palette; import net.momirealms.craftengine.core.world.chunk.PalettedContainer; import net.momirealms.craftengine.core.world.chunk.packet.MCSection; import net.momirealms.craftengine.core.world.collision.AABB; import net.momirealms.sparrow.nbt.Tag; import org.bukkit.*; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; @@ -1628,6 +1630,7 @@ public class PacketConsumers { if (EventUtils.fireAndCheckCancel(interactEvent)) { return; } + if (player.isSneaking()) { // try placing another furniture above it AABB hitBox = furniture.aabbByEntityId(entityId); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractHitBox.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractHitBox.java index 17867d8c6..11be803c9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractHitBox.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractHitBox.java @@ -6,11 +6,15 @@ public abstract class AbstractHitBox implements HitBox { protected final Seat[] seats; protected final Vector3f position; protected final boolean canUseItemOn; + protected final boolean blocksBuilding; + protected final boolean canBeHitByProjectile; - public AbstractHitBox(Seat[] seats, Vector3f position, boolean canUseItemOn) { + public AbstractHitBox(Seat[] seats, Vector3f position, boolean canUseItemOn, boolean blocksBuilding, boolean canBeHitByProjectile) { this.seats = seats; this.position = position; this.canUseItemOn = canUseItemOn; + this.blocksBuilding = blocksBuilding; + this.canBeHitByProjectile = canBeHitByProjectile; } @Override @@ -24,7 +28,17 @@ public abstract class AbstractHitBox implements HitBox { } @Override - public boolean canPlaceAgainst() { - return this.canUseItemOn; + public boolean blocksBuilding() { + return blocksBuilding; + } + + @Override + public boolean canBeHitByProjectile() { + return canBeHitByProjectile; + } + + @Override + public boolean canUseItemOn() { + return canUseItemOn; } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java index 07b40bf3d..61d9076bc 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java @@ -23,5 +23,9 @@ public interface HitBox { Vector3f position(); - boolean canPlaceAgainst(); + boolean blocksBuilding(); + + boolean canBeHitByProjectile(); + + boolean canUseItemOn(); } diff --git a/gradle.properties b/gradle.properties index 70408b833..754b5c367 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,7 +51,7 @@ byte_buddy_version=1.17.5 ahocorasick_version=0.6.3 snake_yaml_version=2.4 anti_grief_version=0.15 -nms_helper_version=0.60.5 +nms_helper_version=0.60.8 reactive_streams_version=1.0.4 amazon_awssdk_version=2.31.23 amazon_awssdk_eventstream_version=1.0.1