mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 11:59:11 +00:00
fix(furniture): 修复家具互动逻辑
This commit is contained in:
@@ -45,7 +45,7 @@ public class ShulkerHitBox extends AbstractHitBox {
|
||||
ShulkerData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, this.cachedShulkerValues); // 不可见
|
||||
|
||||
if (this.interactionEntity) {
|
||||
InteractionEntityData.Height.addEntityDataIfNotDefaultValue((float) ((1 + getPeekHeight(peek)) * scale) + 0.001f, cachedInteractionValues);
|
||||
InteractionEntityData.Height.addEntityDataIfNotDefaultValue(getPeekHeight(peek, scale) + 0.001f, cachedInteractionValues);
|
||||
InteractionEntityData.Width.addEntityDataIfNotDefaultValue((float) scale + 0.001f, cachedInteractionValues);
|
||||
InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(interactive, cachedInteractionValues);
|
||||
}
|
||||
@@ -57,12 +57,17 @@ public class ShulkerHitBox extends AbstractHitBox {
|
||||
true,
|
||||
position(),
|
||||
(float) scale(),
|
||||
1 + getPeekHeight(peek())
|
||||
getPeekHeight(peek(), scale())
|
||||
));
|
||||
}
|
||||
|
||||
private static float getPeekHeight(byte peek) {
|
||||
return (float) (0.5F - Math.sin((0.5F + peek * 0.01F) * 3.1415927F) * 0.5F);
|
||||
private static float getPeekHeight(byte peek, double scale) {
|
||||
double sineValue = Math.sin(
|
||||
(0.5 + peek * 0.01) * Math.PI
|
||||
);
|
||||
return (float) (
|
||||
(1.0 + (0.5 - sineValue * 0.5)) * scale
|
||||
);
|
||||
}
|
||||
|
||||
public boolean interactionEntity() {
|
||||
|
||||
@@ -12,7 +12,6 @@ import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.modelengine.ModelEngineUtils;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.LoadedFurniture;
|
||||
import net.momirealms.craftengine.bukkit.nms.CollisionEntity;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
@@ -691,21 +690,26 @@ public class PacketConsumers {
|
||||
Object actionType = Reflections.method$ServerboundInteractPacket$Action$getType.invoke(action);
|
||||
if (actionType == null) return;
|
||||
LoadedFurniture furniture = BukkitFurnitureManager.instance().getLoadedFurnitureByEntityId(entityId);
|
||||
if (furniture == null) return;
|
||||
if (furniture == null) {
|
||||
furniture = BukkitFurnitureManager.instance().getLoadedFurnitureByCollisionEntityId(entityId);
|
||||
player.sendMessage("Interact with " + entityId + " " + actionType + " " + furniture);
|
||||
if (furniture == null) return;
|
||||
}
|
||||
Location location = furniture.baseEntity().getLocation();
|
||||
BukkitServerPlayer serverPlayer = (BukkitServerPlayer) user;
|
||||
if (serverPlayer.isSpectatorMode() || serverPlayer.isAdventureMode()) return;
|
||||
LoadedFurniture finalFurniture = furniture;
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
if (actionType == Reflections.instance$ServerboundInteractPacket$ActionType$ATTACK) {
|
||||
if (furniture.isValid()) {
|
||||
if (finalFurniture.isValid()) {
|
||||
if (!BukkitCraftEngine.instance().antiGrief().canBreak(player, location)) {
|
||||
return;
|
||||
}
|
||||
FurnitureBreakEvent breakEvent = new FurnitureBreakEvent(serverPlayer.platformPlayer(), furniture);
|
||||
FurnitureBreakEvent breakEvent = new FurnitureBreakEvent(serverPlayer.platformPlayer(), finalFurniture);
|
||||
if (EventUtils.fireAndCheckCancel(breakEvent)) {
|
||||
return;
|
||||
}
|
||||
CraftEngineFurniture.remove(furniture, serverPlayer, !serverPlayer.isCreativeMode(), true);
|
||||
CraftEngineFurniture.remove(finalFurniture, serverPlayer, !serverPlayer.isCreativeMode(), true);
|
||||
}
|
||||
} else if (actionType == Reflections.instance$ServerboundInteractPacket$ActionType$INTERACT_AT) {
|
||||
InteractionHand hand;
|
||||
@@ -721,15 +725,15 @@ public class PacketConsumers {
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to get interaction hand from interact packet", e);
|
||||
}
|
||||
FurnitureInteractEvent interactEvent = new FurnitureInteractEvent(serverPlayer.platformPlayer(), furniture, hand, interactionPoint);
|
||||
FurnitureInteractEvent interactEvent = new FurnitureInteractEvent(serverPlayer.platformPlayer(), finalFurniture, hand, interactionPoint);
|
||||
if (EventUtils.fireAndCheckCancel(interactEvent)) {
|
||||
return;
|
||||
}
|
||||
if (player.isSneaking())
|
||||
return;
|
||||
furniture.findFirstAvailableSeat(entityId).ifPresent(seatPos -> {
|
||||
if (furniture.tryOccupySeat(seatPos)) {
|
||||
furniture.spawnSeatEntityForPlayer(Objects.requireNonNull(player.getPlayer()), seatPos);
|
||||
finalFurniture.findFirstAvailableSeat(entityId).ifPresent(seatPos -> {
|
||||
if (finalFurniture.tryOccupySeat(seatPos)) {
|
||||
finalFurniture.spawnSeatEntityForPlayer(Objects.requireNonNull(player.getPlayer()), seatPos);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user