Scrap !!
This commit is contained in:
@@ -549,7 +549,8 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
|
||||
spawn_item(x: number, y: number, z: number, stack: ItemStack, pickup_delay = 0): ItemEntity {
|
||||
// a cubi:item, or the entity the item lies around as, see EntityManager.spawn_item
|
||||
spawn_item(x: number, y: number, z: number, stack: ItemStack, pickup_delay = 0): Entity {
|
||||
const entity = this.entities.spawn_item(x, y, z, stack, pickup_delay);
|
||||
this.world.dirty = true;
|
||||
return entity;
|
||||
@@ -588,6 +589,8 @@ export class GameServer {
|
||||
entity.vx = -Math.sin(player.yaw) * cos_pitch * speed + Math.cos(spread_angle) * spread;
|
||||
entity.vy = Math.sin(player.pitch) * speed + (0.1 + (Math.random() - Math.random()) * 0.1) * TICKS_PER_SECOND;
|
||||
entity.vz = -Math.cos(player.yaw) * cos_pitch * speed + Math.sin(spread_angle) * spread;
|
||||
// one drawn with a model lands facing the way they threw it
|
||||
entity.yaw = player.yaw;
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -1224,6 +1227,10 @@ export class GameServer {
|
||||
this.#attack_entity(player, message.id);
|
||||
}
|
||||
break;
|
||||
case "interact_entity":
|
||||
// a client that hadn't heard it's using an item yet, still clicking
|
||||
if (typeof message.id === "string" && !player.using) this.#interact_entity(player, message.id);
|
||||
break;
|
||||
case "swing":
|
||||
player.attack_strength_ticker = 0;
|
||||
break;
|
||||
@@ -1380,6 +1387,19 @@ export class GameServer {
|
||||
}
|
||||
|
||||
// right click at nothing: eating, or the item's on_use
|
||||
// a right click on an entity, like minecraft's ServerboundInteractPacket: mods' entity_interact, then the held item
|
||||
// is used like on nothing, unless one of them stopped it. out of reach, or gone already, it's only that use
|
||||
#interact_entity(player: ServerPlayer, id: string) {
|
||||
const entity = this.entities.get_entity(id);
|
||||
if (entity && !entity.removed && player.alive && this.#entity_in_reach(player, entity)) {
|
||||
const player_api = this.mods.player(player);
|
||||
const event = { player: player_api, entity: entity_ref(entity), item: player_api.held_item, cancel: false };
|
||||
this.mods.before.entity_interact.emit(event);
|
||||
if (event.cancel) return;
|
||||
}
|
||||
this.#use_item(player);
|
||||
}
|
||||
|
||||
#use_item(player: ServerPlayer): boolean {
|
||||
return this.#eat(player) || this.#use_item_components(player, undefined);
|
||||
}
|
||||
@@ -2639,7 +2659,7 @@ export class GameServer {
|
||||
}
|
||||
|
||||
// from the eyes to the closest point of its box
|
||||
#entity_in_reach(player: ServerPlayer, entity: LivingEntity) {
|
||||
#entity_in_reach(player: ServerPlayer, entity: Entity) {
|
||||
const eye_y = player.y + player.eye_height;
|
||||
const half = entity.width / 2;
|
||||
const dx = Math.max(entity.x - half - player.x, 0, player.x - entity.x - half);
|
||||
|
||||
Reference in New Issue
Block a user