Browse Source

modding #2012: Added the beforeSpawnResource that allows spawned resources' positions to be set by mods

tags/v0.14.0^2
Shaun 3 months ago
parent
commit
6bf5da5569
1 changed files with 15 additions and 2 deletions
  1. +15
    -2
      src/server/world/resourceSpawner.js

+ 15
- 2
src/server/world/resourceSpawner.js View File

@@ -1,4 +1,5 @@
let herbs = require('../config/herbs');
const eventEmitter = require('../misc/events');

const defaultGatherChance = {
herb: 100,
@@ -122,8 +123,20 @@ module.exports = {
},

spawn: function (node) {
let blueprint = node.blueprint;
let position = this.getRandomSpawnPosition(node, blueprint);
const blueprint = node.blueprint;

const eBeforeSpawnResource = {
node,
position: undefined,
allowRandomPosition: true
};
eventEmitter.emit('beforeSpawnResource', eBeforeSpawnResource);

if (eBeforeSpawnResource.allowRandomPosition && !eBeforeSpawnResource.position)
eBeforeSpawnResource.position = this.getRandomSpawnPosition(node, blueprint);

const { position } = eBeforeSpawnResource;

if (!position)
return false;



Loading…
Cancel
Save