diff --git a/src/js/game/belt_path.js b/src/js/game/belt_path.js index e628a85c..9b58ac7e 100644 --- a/src/js/game/belt_path.js +++ b/src/js/game/belt_path.js @@ -186,9 +186,12 @@ export class BeltPath extends BasicSerializableObject { /** * Finds the entity which accepts our items + * @param {boolean=} debug_Silent Whether debug output should be silent * @return {{ entity: Entity, slot: number, direction?: enumDirection }} */ - computeAcceptingEntityAndSlot() { + computeAcceptingEntityAndSlot(debug_Silent = false) { + DEBUG && !debug_Silent && logger.log("Recomputing acceptor target"); + const lastEntity = this.entityPath[this.entityPath.length - 1]; const lastStatic = lastEntity.components.StaticMapEntity; const lastBeltComp = lastEntity.components.Belt; @@ -207,12 +210,23 @@ export class BeltPath extends BasicSerializableObject { ); if (targetEntity) { + DEBUG && !debug_Silent && logger.log(" Found target entity", targetEntity.uid); const targetStaticComp = targetEntity.components.StaticMapEntity; const targetBeltComp = targetEntity.components.Belt; // Check for belts (special case) if (targetBeltComp) { const beltAcceptingDirection = targetStaticComp.localDirectionToWorld(enumDirection.top); + DEBUG && + !debug_Silent && + logger.log( + " Entity is accepting items from", + ejectSlotWsDirection, + "vs", + beltAcceptingDirection, + "Rotation:", + targetStaticComp.rotation + ); if (ejectSlotWsDirection === beltAcceptingDirection) { return { entity: targetEntity, @@ -377,6 +391,41 @@ export class BeltPath extends BasicSerializableObject { if (!actualBounds.equalsEpsilon(this.worldBounds, 0.01)) { return fail("Bounds are stale"); } + + // Check acceptor + const acceptor = this.computeAcceptingEntityAndSlot(true); + if (!!acceptor !== !!this.acceptorTarget) { + return fail("Acceptor target mismatch, acceptor", !!acceptor, "vs stored", !!this.acceptorTarget); + } + + if (acceptor) { + if (this.acceptorTarget.entity !== acceptor.entity) { + return fail( + "Mismatching entity on acceptor target:", + acceptor.entity.uid, + "vs", + this.acceptorTarget.entity.uid + ); + } + + if (this.acceptorTarget.slot !== acceptor.slot) { + return fail( + "Mismatching entity on acceptor target:", + acceptor.slot, + "vs stored", + this.acceptorTarget.slot + ); + } + + if (this.acceptorTarget.direction !== acceptor.direction) { + return fail( + "Mismatching direction on acceptor target:", + acceptor.direction, + "vs stored", + this.acceptorTarget.direction + ); + } + } } /* dev:end */ diff --git a/src/js/game/systems/belt.js b/src/js/game/systems/belt.js index 3951077a..10543e6c 100644 --- a/src/js/game/systems/belt.js +++ b/src/js/game/systems/belt.js @@ -165,6 +165,8 @@ export class BeltSystem extends GameSystemWithFilter { const newDirection = arrayBeltVariantToRotation[rotationVariant]; if (targetStaticComp.rotation !== rotation || newDirection !== targetBeltComp.direction) { + const originalPath = targetBeltComp.assignedPath; + // Ok, first remove it from its current path this.deleteEntityFromPath(targetBeltComp.assignedPath, targetEntity); @@ -179,6 +181,9 @@ export class BeltSystem extends GameSystemWithFilter { rotationVariant ); + // Update the original path since it might have picked up the entit1y + originalPath.onPathChanged(); + // Now add it again this.addEntityToPaths(targetEntity);