Skip to content

Commit

Permalink
check if blocks length is more than 0
Browse files Browse the repository at this point in the history
  • Loading branch information
HirziDevs committed Jun 20, 2024
1 parent 5d4e64f commit 756eb75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
A Custom Cobblestone and Basalt Generator By @HirziDevs
You can view all the documentation at https://ccbg.znproject.my.id
*/
const config = {}
const config = {};

/*
Generator
Expand Down Expand Up @@ -118,4 +118,4 @@ config.customGenerator = [
}
]

export default config
export default config;
48 changes: 25 additions & 23 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,32 @@ function Generator(generatorBlock) {

if (isCustomGenerator && customGeneratorID !== -1) blocks = config.customGenerator[customGeneratorID].blocks;

let chances = 0;
let selectedBlock = blocks[0].identifier;

for (const block of blocks) {
chances += block.chance;
if (Math.random() * 100 < chances) {
selectedBlock = block.identifier;
break;
if (blocks.length > 0) {
let chances = 0;
let selectedBlock = blocks[0].identifier;

for (const block of blocks) {
chances += block.chance;
if (Math.random() * 100 < chances) {
selectedBlock = block.identifier;
break;
}
}
}

config.delay = config.delay < 0 ? 0.1 : config.delay;
system.runTimeout(() => {
dimension.runCommand(`setblock ${location.x} ${location.y} ${location.z} ${selectedBlock}`)
}, config.delay * 20);
}
}
config.delay = config.delay < 0 ? 0.1 : config.delay;
system.runTimeout(() => {
dimension.runCommand(`setblock ${location.x} ${location.y} ${location.z} ${selectedBlock}`);
}, config.delay * 20);
};
};
};

if(config.player || config.player === null || config.player === undefined) world.afterEvents.playerBreakBlock.subscribe(event => Generator(event.block));
if (config.player || config.player === null || config.player === undefined) world.afterEvents.playerBreakBlock.subscribe(event => Generator(event.block));

if(config.explosion || config.player === null || config.player === undefined) world.afterEvents.blockExplode.subscribe(event => Generator(event.block));
if (config.explosion || config.player === null || config.player === undefined) world.afterEvents.blockExplode.subscribe(event => Generator(event.block));

if(config.piston || config.player === null || config.player === undefined) world.afterEvents.pistonActivate.subscribe(event => {
const { dimension, location } = event.block
if (config.piston || config.player === null || config.player === undefined) world.afterEvents.pistonActivate.subscribe(event => {
const { dimension, location } = event.block;

const locations = [
{ x: location.x + 1, y: location.y, z: location.z },
Expand All @@ -170,10 +172,10 @@ if(config.piston || config.player === null || config.player === undefined) world
{ x: location.x, y: location.y, z: location.z - 1 },
{ x: location.x, y: location.y + 1, z: location.z },
{ x: location.x, y: location.y - 1, z: location.z }
]
];

for (const blockLocation of locations) {
const block = dimension.getBlock(blockLocation)
if (block.isAir) Generator(block)
}
const block = dimension.getBlock(blockLocation);
if (block.isAir) Generator(block);
};
});

0 comments on commit 756eb75

Please sign in to comment.