9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-24 01:19:24 +00:00

好东西

This commit is contained in:
XiaoMoMi
2025-04-21 04:27:28 +08:00
parent 37c507b45f
commit 1954aebac3
7 changed files with 56 additions and 20 deletions

View File

@@ -99,7 +99,7 @@ public class ShulkerHitBox extends AbstractHitBox {
), true);
packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(cachedInteractionValues)), true);
// second interaction
float distance = shulkerHeight - scale;
double distance = shulkerHeight - scale;
packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
entityIds[3], UUID.randomUUID(), x + offset.x + shulkerDirection.stepX() * distance, y + offset.y - 0.005f, z - offset.z + shulkerDirection.stepZ() * distance, 0, yaw,
Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0

View File

@@ -23,6 +23,7 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.entity.player.InteractionHand;
import net.momirealms.craftengine.core.font.FontManager;
import net.momirealms.craftengine.core.font.IllegalCharacterProcessResult;
import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.item.context.UseOnContext;
@@ -1633,23 +1634,26 @@ public class PacketConsumers {
if (hitBox == null) return;
Item<ItemStack> itemInHand = serverPlayer.getItemInHand(InteractionHand.MAIN_HAND);
if (itemInHand == null) return;
itemInHand.getCustomItem().ifPresent(customItem -> {
Location eyeLocation = player.getEyeLocation();
Vector direction = eyeLocation.getDirection();
Location endLocation = eyeLocation.clone();
endLocation.add(direction.multiply(serverPlayer.getCachedInteractionRange()));
Optional<EntityHitResult> result = hitBox.clip(LocationUtils.toVec3d(eyeLocation), LocationUtils.toVec3d(endLocation));
if (result.isPresent()) {
EntityHitResult hitResult = result.get();
Vec3d vec3d = hitResult.position();
for (ItemBehavior behavior : customItem.behaviors()) {
if (behavior instanceof FurnitureItemBehavior) {
behavior.useOnBlock(new UseOnContext(serverPlayer, InteractionHand.MAIN_HAND, new BlockHitResult(vec3d, hitResult.direction(), BlockPos.fromVec3d(vec3d), false)));
return;
}
Optional<CustomItem<ItemStack>> optionalCustomitem = itemInHand.getCustomItem();
Location eyeLocation = player.getEyeLocation();
Vector direction = eyeLocation.getDirection();
Location endLocation = eyeLocation.clone();
endLocation.add(direction.multiply(serverPlayer.getCachedInteractionRange()));
Optional<EntityHitResult> result = hitBox.clip(LocationUtils.toVec3d(eyeLocation), LocationUtils.toVec3d(endLocation));
if (result.isEmpty()) {
return;
}
EntityHitResult hitResult = result.get();
if (optionalCustomitem.isPresent() && !optionalCustomitem.get().behaviors().isEmpty()) {
for (ItemBehavior behavior : optionalCustomitem.get().behaviors()) {
if (behavior instanceof FurnitureItemBehavior) {
behavior.useOnBlock(new UseOnContext(serverPlayer, InteractionHand.MAIN_HAND, new BlockHitResult(hitResult.hitLocation(), hitResult.direction(), BlockPos.fromVec3d(hitResult.hitLocation()), false)));
return;
}
}
});
}
// now simulate vanilla item behavior
FastNMS.INSTANCE.simulateInteraction(serverPlayer.serverPlayer(), DirectionUtils.toNMSDirection(hitResult.direction()), hitResult.hitLocation().x, hitResult.hitLocation().y, hitResult.hitLocation().z, LocationUtils.toBlockPos(hitResult.blockPos()));
} else {
furniture.findFirstAvailableSeat(entityId).ifPresent(seatPos -> {
if (furniture.tryOccupySeat(seatPos)) {