Fix examples

pull/1386/head
tobspr 2 years ago
parent 561318b7db
commit ea2f32b3ff

@ -87,7 +87,7 @@ class FluidItem extends shapez.BaseItem {
* @param {number} diameter * @param {number} diameter
* @param {DrawParameters} parameters * @param {DrawParameters} parameters
*/ */
drawItemCenteredClipped(x, y, parameters, diameter = globalConfig.defaultItemDiameter) { drawItemCenteredClipped(x, y, parameters, diameter = shapez.globalConfig.defaultItemDiameter) {
const realDiameter = diameter * 0.6; const realDiameter = diameter * 0.6;
if (!this.cachedSprite) { if (!this.cachedSprite) {
this.cachedSprite = shapez.Loader.getSprite(`sprites/fluids/${this.fluidType}.png`); this.cachedSprite = shapez.Loader.getSprite(`sprites/fluids/${this.fluidType}.png`);
@ -120,19 +120,19 @@ class Mod extends shapez.Mod {
this.modInterface.registerSprite("sprites/fluids/water.png", RESOURCES["water.png"]); this.modInterface.registerSprite("sprites/fluids/water.png", RESOURCES["water.png"]);
// Make the item spawn on the map // Make the item spawn on the map
this.modInterface.runAfterMethod( this.modInterface.runAfterMethod(shapez.MapChunk, "generatePatches", function ({
shapez.MapChunk, rng,
"generatePatches", chunkCenter,
function ({ rng, chunkCenter, distanceToOriginInChunks }) { distanceToOriginInChunks,
// Generate a simple patch }) {
// ALWAYS use rng and NEVER use Math.random() otherwise the map will look different // Generate a simple patch
// every time you resume the game // ALWAYS use rng and NEVER use Math.random() otherwise the map will look different
if (rng.next() > 0.8) { // every time you resume the game
const fluidType = rng.choice(Array.from(Object.keys(enumFluidType))); if (rng.next() > 0.8) {
this.internalGeneratePatch(rng, 4, FLUID_ITEM_SINGLETONS[fluidType]); const fluidType = rng.choice(Array.from(Object.keys(enumFluidType)));
} this.internalGeneratePatch(rng, 4, FLUID_ITEM_SINGLETONS[fluidType]);
} }
); });
this.modInterface.registerItem(FluidItem, itemData => FLUID_ITEM_SINGLETONS[itemData]); this.modInterface.registerItem(FluidItem, itemData => FLUID_ITEM_SINGLETONS[itemData]);
} }

Loading…
Cancel
Save