mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 04:46:37 +00:00
新增碰撞体积阻碍建造
This commit is contained in:
@@ -26,8 +26,8 @@ public class CustomHitBox extends AbstractHitBox {
|
||||
private final EntityType entityType;
|
||||
private final List<Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, Object> 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Object> 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ public class ShulkerHitBox extends AbstractHitBox {
|
||||
private final List<Object> 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user