From 91978fff3cf8ac09a35b835061e70fc71262532a Mon Sep 17 00:00:00 2001 From: Nebby <78170922+Nebby1999@users.noreply.github.com> Date: Fri, 18 Apr 2025 01:53:24 -0400 Subject: [PATCH] Fixed the "look at water" task not working. (#882) --- .../quests/chapters/questsstoneage.snbt | 10 ++- kubejs/assets/tfg/lang/en_us.json | 4 +- .../server_scripts/ftb_quests/CustomQuests.js | 41 ++++++++++++ kubejs/server_scripts/tfg/events.js | 66 +++++++++++-------- 4 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 kubejs/server_scripts/ftb_quests/CustomQuests.js diff --git a/config/ftbquests/quests/chapters/questsstoneage.snbt b/config/ftbquests/quests/chapters/questsstoneage.snbt index d0f810272..d78ad7781 100644 --- a/config/ftbquests/quests/chapters/questsstoneage.snbt +++ b/config/ftbquests/quests/chapters/questsstoneage.snbt @@ -89,12 +89,10 @@ subtitle: "{quests.stone_age.find_potable_water.subtitle}" tasks: [{ icon: "minecraft:water_bucket" - id: "73E3594A5481E63F" - observe_type: 0 - timer: 0L - title: "{quests.tasktype.lookat} {quests.stone_age.find_potable_water.task}" - to_observe: "minecraft:water" - type: "observation" + id: "3601D2311BB1383F" + stage: "tfg.stages.quests.drank_fresh_water_with_hand" + title: "{quests.stone_age.find_potable_water.task}" + type: "gamestage" }] title: "{quests.stone_age.find_potable_water.title}" x: 4.5d diff --git a/kubejs/assets/tfg/lang/en_us.json b/kubejs/assets/tfg/lang/en_us.json index 36de34d84..c118df0f4 100644 --- a/kubejs/assets/tfg/lang/en_us.json +++ b/kubejs/assets/tfg/lang/en_us.json @@ -1076,8 +1076,8 @@ "quests.stone_age.garlic_bread.task": "1024 slices of Garlic Bread", "quests.stone_age.find_potable_water.title": "Thirsty?", "quests.stone_age.find_potable_water.subtitle": "Remember to drink water!", - "quests.stone_age.find_potable_water.desc": "Thirst is represented by the blue bar above your hunger. You can and will die of dehydration if you dont keep your thirst meter filled! The easiest way to have a drink is by drinking from natural ponds in the wild, by right-clicking on them with an empty hand.\n\nYou don't have to worry about purifying water here, though Salt Water will just make you more thirsty.", - "quests.stone_age.find_potable_water.task": "A source of fresh Water", + "quests.stone_age.find_potable_water.desc": "Thirst is represented by the blue bar above your hunger. You can and will die of dehydration if you dont keep your thirst meter filled! The easiest way to have a drink is by drinking from natural ponds in the wild, by right-clicking on them with an empty hand.\nTo complete this quest, you need to drink a Potable source of water, can be regular or river water. You may need to drink multiple times so the quest completes properly\n\nYou don't have to worry about purifying water here, though Salt Water will just make you more thirsty.", + "quests.stone_age.find_potable_water.task": "Drink from a Water Source with your Hand. (Not Salty or Hot)", "quests.stone_age.hydration.title": "Mechanic: Hydration", "quests.stone_age.hydration.subtitle": "Yet another bar to keep full...", "quests.stone_age.hydration.desc": "Water is an important resource, not just for staying hydrated! Setting up a base near a fresh lake or river is recommended, so you have easy access to the stuff. Other items can quench your thirst, such as certain types of food or drinks.\n\nWater won't always be available when you go exploring, however, so here are some ways to carry drinks around with you. Drinking consumes 100mB from the container.", diff --git a/kubejs/server_scripts/ftb_quests/CustomQuests.js b/kubejs/server_scripts/ftb_quests/CustomQuests.js new file mode 100644 index 000000000..df613051f --- /dev/null +++ b/kubejs/server_scripts/ftb_quests/CustomQuests.js @@ -0,0 +1,41 @@ +// Handles the quest for drinking water. The drinking water quest checks if the player has this stage. +ItemEvents.firstRightClicked(evt => +{ + const FORGE_CAPS = "ForgeCaps"; + const TFC_PLAYERDATA = "tfc:player_data"; + const FOOD = "food"; + const THIRST = "thirst"; + const PREVIOUS_THIRST = "previous_thirst"; + const STAGE = "tfg.stages.quests.drank_fresh_water_with_hand"; + const {player, level} = evt; + + if(evt.target.block == null) + return; + + //We reach for the "food" compound tag, that contains the tfc thirst. + let forgecaps = player.nbt.getCompound(FORGE_CAPS); + let tfc_playerdata = forgecaps.getCompound(TFC_PLAYERDATA); + let food = tfc_playerdata.getCompound(FOOD); + let thirstValue = food.getFloat(THIRST); + + //Do we already keep track of the previous thirst value? if not, put it and then return. + let customData = getTFGPersistentDataRoot(player); + let containsPreviousThirst = customData.contains(PREVIOUS_THIRST); + if(!containsPreviousThirst) + { + customData.putFloat(PREVIOUS_THIRST, thirstValue); + return; + } + + let previousThirstValue = customData.getFloat(PREVIOUS_THIRST); + + //As long as our new thirst is greater than our previous, it means we hydrated ourselves. OFC we need to make sure the block clicked was potable. + let blockID = evt.target.block.id; + let isFreshWater = blockID == "minecraft:water" || blockID == "tfc:fluid/river_water"; + if(isFreshWater && thirstValue > previousThirstValue && !player.stages.has(STAGE)) + { + player.stages.add(STAGE); + } + //Put it back in. + customData.putFloat(PREVIOUS_THIRST, thirstValue); +}) \ No newline at end of file diff --git a/kubejs/server_scripts/tfg/events.js b/kubejs/server_scripts/tfg/events.js index 91f924648..98eccb9d0 100644 --- a/kubejs/server_scripts/tfg/events.js +++ b/kubejs/server_scripts/tfg/events.js @@ -83,35 +83,49 @@ salvo_event.forEach(salvo_event => { }); }); - ItemEvents.rightClicked(event => { - const {item,server,player,player:{x,y,z,username}} = event - if (item.id != `tfg:absorption_salvo`) return - item.count-- - player.addItemCooldown(item, 200) - player.runCommandSilent(`effect give ${username} minecraft:absorption 480 4 true`) - server.runCommandSilent(`playsound minecraft:item.glow_ink_sac.use player ${username} ${x} ${y} ${z} 10 2 1`) - }); +ItemEvents.rightClicked(event => { + const {item,server,player,player:{x,y,z,username}} = event + if (item.id != `tfg:absorption_salvo`) return + item.count-- + player.addItemCooldown(item, 200) + player.runCommandSilent(`effect give ${username} minecraft:absorption 480 4 true`) + server.runCommandSilent(`playsound minecraft:item.glow_ink_sac.use player ${username} ${x} ${y} ${z} 10 2 1`) +}); - ItemEvents.rightClicked(event => { - const {item,server,player,player:{x,y,z,username}} = event - if (item.id != `tfg:instant_health_salvo`) return - item.count-- - player.addItemCooldown(item, 100) - player.runCommandSilent(`effect give ${username} minecraft:instant_health 1 1 true`) - server.runCommandSilent(`playsound minecraft:item.glow_ink_sac.use player ${username} ${x} ${y} ${z} 10 2 1`) - }); +ItemEvents.rightClicked(event => { + const {item,server,player,player:{x,y,z,username}} = event + if (item.id != `tfg:instant_health_salvo`) return + item.count-- + player.addItemCooldown(item, 100) + player.runCommandSilent(`effect give ${username} minecraft:instant_health 1 1 true`) + server.runCommandSilent(`playsound minecraft:item.glow_ink_sac.use player ${username} ${x} ${y} ${z} 10 2 1`) +}); // Vase Sounds - global.MINECRAFT_DYE_NAMES.forEach(color => { - BlockEvents.rightClicked(event => { - const {block,server,player,player:{x,y,z,username}} = event - if (block.id != `tfg:decorative_vase/${color}`) {return}{ - server.runCommandSilent(`playsound tfc:block.quern.drag block ${username} ${block.x} ${block.y} ${block.z} 0.3 2.0 0.1`) - }}) - }); - +global.MINECRAFT_DYE_NAMES.forEach(color => { BlockEvents.rightClicked(event => { const {block,server,player,player:{x,y,z,username}} = event - if (block.id != 'tfg:decorative_vase') {return}{ + if (block.id != `tfg:decorative_vase/${color}`) {return}{ server.runCommandSilent(`playsound tfc:block.quern.drag block ${username} ${block.x} ${block.y} ${block.z} 0.3 2.0 0.1`) - }}); \ No newline at end of file + }}) +}); + +BlockEvents.rightClicked(event => { + const {block,server,player,player:{x,y,z,username}} = event + if (block.id != 'tfg:decorative_vase') {return}{ + server.runCommandSilent(`playsound tfc:block.quern.drag block ${username} ${block.x} ${block.y} ${block.z} 0.3 2.0 0.1`) +}}); + +/** + * + * @param {Internal.Player} player + * @returns {Internal.CompoundTag} + */ +function getTFGPersistentDataRoot(player) +{ + if(!player.persistentData.contains("tfg:custom_data")) + { + player.persistentData.put("tfg:custom_data", {}); + } + return player.persistentData.getCompound("tfg:custom_data") +} \ No newline at end of file