Skip to content

Instantly share code, notes, and snippets.

@vidaj
Created April 26, 2020 10:40
Show Gist options
  • Save vidaj/e77ac49866841b5df74a7ffcfca666f7 to your computer and use it in GitHub Desktop.
Save vidaj/e77ac49866841b5df74a7ffcfca666f7 to your computer and use it in GitHub Desktop.
KubeJS script that will allow you to add custom tasks to FTB Quests to detect that the player has acquired a specific Forestry bee species.
// USAGE:
// In FTB Quests, add a custom task type. Add a tag that starts with "beespecies_" and ends with the name of the species.
// There are some limitations to the tag string contents, so everything must be lowercase, colons and dots can't be used.
//
// Examples:
// beespecies_speciesforest
// beespecies_speciescommon
// beespecies_specieslordly
(function() {
var beeSpecies = {};
var playerBeeState = {};
function checkItemForBeeSpecies(item, player) {
var nbt = item.nbt;
if (nbt == null || nbt.empty) {
return;
}
var genome = nbt.get("Genome");
if (genome != null && !genome.isNull()) {
var chromosomes = genome.get("Chromosomes");
var speciesAllele = chromosomes.asList().get(0);
var uid1 = speciesAllele.get("UID1").toString().toLowerCase();
var allSpecies = Object.keys(beeSpecies);
for (var i = 0; i < allSpecies.length; i++) {
var species = allSpecies[i];
if (uid1.indexOf(species) !== -1) {
if (!playerBeeState.hasOwnProperty(player.id)) {
playerBeeState[player.id] = {};
}
var state = playerBeeState[player.id];
state[species] = true;
return;
}
}
}
}
events.listen("player.inventory.changed", function(event) {
if (event.player.fake) {
return;
}
var item = event.item;
if (item != null) {
checkItemForBeeSpecies(item, event.player);
}
});
function getBeeSpeciesFromTags(tags) {
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
tag = tag.toString();
if (tag.startsWith("beespecies_")) {
var species = tag.substring(11);
return species;
}
}
return null;
}
events.listen("ftbquests.custom_task", function(event) {
var task = event.getTask();
var tags = task.getTags().toArray();
var species = getBeeSpeciesFromTags(tags);
if (species == null) {
return;
}
beeSpecies[species] = true;
event.setCheckTimer(100); // every 5 second
event.setCheck(function(taskData, player) {
if (taskData.complete) {
return;
}
var state = playerBeeState[player.id];
if (!state) {
return;
}
if (state.hasOwnProperty(species.toLowerCase())) {
taskData.addProgress(1);
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment