diff --git a/src/js/game/game_system_with_filter.js b/src/js/game/game_system_with_filter.js index 82ab4c22..a34e61e2 100644 --- a/src/js/game/game_system_with_filter.js +++ b/src/js/game/game_system_with_filter.js @@ -8,6 +8,8 @@ import { GameSystem } from "./game_system"; import { arrayDelete, arrayDeleteValue } from "../core/utils"; import { DrawParameters } from "../core/draw_parameters"; import { globalConfig } from "../core/config"; +import { enumDirection, enumDirectionToVector } from "../core/vector"; + export class GameSystemWithFilter extends GameSystem { /** * Constructs a new game system with the given component filter. It will process @@ -211,4 +213,21 @@ export class GameSystemWithFilter extends GameSystem { arrayDelete(this.allEntities, index); } } + + /** + * + * @param {Entity} entity + * @param {enumDirection=} direction + * @returns {Entity|null} + */ + getAdjacentEntity(entity, direction = null) { + const ejectComp = entity.components.ItemEjector; + const staticComp = entity.components.StaticMapEntity; + + const ejectingSlot = ejectComp.slots[0]; + const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos); + const ejectingDirection = staticComp.localDirectionToWorld(direction || ejectingSlot.direction); + const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]); + return this.root.map.getTileContent(targetTile, enumLayer.regular); + } } diff --git a/src/js/game/systems/miner.js b/src/js/game/systems/miner.js index f317d0d1..94500989 100644 --- a/src/js/game/systems/miner.js +++ b/src/js/game/systems/miner.js @@ -66,16 +66,10 @@ export class MinerSystem extends GameSystemWithFilter { tryPerformMinerEject(entity, item) { const minerComp = entity.components.Miner; const ejectComp = entity.components.ItemEjector; - const staticComp = entity.components.StaticMapEntity; // Check if we are a chained miner if (minerComp.chainable) { - const ejectingSlot = ejectComp.slots[0]; - const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos); - const ejectingDirection = staticComp.localDirectionToWorld(ejectingSlot.direction); - - const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]); - const targetContents = this.root.map.getTileContent(targetTile, enumLayer.regular); + const targetContents = this.getAdjacentEntity(entity); // Check if we are connected to another miner and thus do not eject directly if (targetContents) {