Merge pull request #83 from kolbytn/creative-mode

Creative mode
This commit is contained in:
Max Robinson 2024-05-14 23:00:35 -05:00 committed by GitHub
commit 265dd6a076
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 9 deletions

View file

@ -0,0 +1,17 @@
diff --git a/node_modules/mineflayer-pathfinder/lib/movements.js b/node_modules/mineflayer-pathfinder/lib/movements.js
index a7e3505..77e428f 100644
--- a/node_modules/mineflayer-pathfinder/lib/movements.js
+++ b/node_modules/mineflayer-pathfinder/lib/movements.js
@@ -143,7 +143,11 @@ class Movements {
for (const id of this.scafoldingBlocks) {
for (const j in items) {
const item = items[j]
- if (item.type === id) count += item.count
+ if (item.type === id) {
+ count += item.count
+ if (this.bot.game.gameMode === 'creative')
+ count = 1000
+ }
}
}
return count

View file

@ -17,10 +17,11 @@ export const queryList = [
let pos = bot.entity.position; let pos = bot.entity.position;
// display position to 2 decimal places // display position to 2 decimal places
res += `\n- Position: x: ${pos.x.toFixed(2)}, y: ${pos.y.toFixed(2)}, z: ${pos.z.toFixed(2)}`; res += `\n- Position: x: ${pos.x.toFixed(2)}, y: ${pos.y.toFixed(2)}, z: ${pos.z.toFixed(2)}`;
res += `\n- Gamemode: ${bot.game.gameMode}`;
res += `\n- Health: ${Math.round(bot.health)} / 20`; res += `\n- Health: ${Math.round(bot.health)} / 20`;
res += `\n- Hunger: ${Math.round(bot.food)} / 20`; res += `\n- Hunger: ${Math.round(bot.food)} / 20`;
res += `\n- Biome: ${world.getBiomeName(bot)}`; res += `\n- Biome: ${world.getBiomeName(bot)}`;
let weather = "clear"; let weather = "Clear";
if (bot.rainState > 0) if (bot.rainState > 0)
weather = "Rain"; weather = "Rain";
if (bot.thunderState > 0) if (bot.thunderState > 0)
@ -57,9 +58,12 @@ export const queryList = [
if (inventory[item] && inventory[item] > 0) if (inventory[item] && inventory[item] > 0)
res += `\n- ${item}: ${inventory[item]}`; res += `\n- ${item}: ${inventory[item]}`;
} }
if (res == 'INVENTORY') { if (res === 'INVENTORY') {
res += ': none'; res += ': none';
} }
else if (agent.bot.game.gameMode === 'creative') {
res += '\n(You have infinite items in creative mode)';
}
return pad(res); return pad(res);
} }
}, },

View file

@ -463,11 +463,13 @@ export async function breakBlockAt(bot, x, y, z) {
bot.pathfinder.setMovements(movements); bot.pathfinder.setMovements(movements);
await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4)); await bot.pathfinder.goto(new pf.goals.GoalNear(pos.x, pos.y, pos.z, 4));
} }
await bot.tool.equipForBlock(block); if (bot.gameMode !== 'creative') {
const itemId = bot.heldItem ? bot.heldItem.type : null await bot.tool.equipForBlock(block);
if (!block.canHarvest(itemId)) { const itemId = bot.heldItem ? bot.heldItem.type : null
log(bot, `Don't have right tools to break ${block.name}.`); if (!block.canHarvest(itemId)) {
return false; log(bot, `Don't have right tools to break ${block.name}.`);
return false;
}
} }
await bot.dig(block, true); await bot.dig(block, true);
log(bot, `Broke ${block.name} at x:${x.toFixed(1)}, y:${y.toFixed(1)}, z:${z.toFixed(1)}.`); log(bot, `Broke ${block.name} at x:${x.toFixed(1)}, y:${y.toFixed(1)}, z:${z.toFixed(1)}.`);

View file

@ -26,13 +26,15 @@ const modes = [
const bot = agent.bot; const bot = agent.bot;
const block = bot.blockAt(bot.entity.position); const block = bot.blockAt(bot.entity.position);
const blockAbove = bot.blockAt(bot.entity.position.offset(0, 1, 0)); const blockAbove = bot.blockAt(bot.entity.position.offset(0, 1, 0));
if (blockAbove && (blockAbove.name === 'water' || blockAbove.name === 'flowing_water')) { if (!block) block = {name: 'air'}; // hacky fix when blocks are not loaded
if (!blockAbove) blockAbove = {name: 'air'};
if (blockAbove.name === 'water' || blockAbove.name === 'flowing_water') {
// does not call execute so does not interrupt other actions // does not call execute so does not interrupt other actions
if (!bot.pathfinder.goal) { if (!bot.pathfinder.goal) {
bot.setControlState('jump', true); bot.setControlState('jump', true);
} }
} }
else if (blockAbove && this.fall_blocks.some(name => blockAbove.name.includes(name))) { else if (this.fall_blocks.some(name => blockAbove.name.includes(name))) {
execute(this, agent, async () => { execute(this, agent, async () => {
await skills.moveAway(bot, 2); await skills.moveAway(bot, 2);
}); });