skapa-season-3/kubejs/startup_scripts/jetpacks.js
Steve McMaster da0b26d1a2
All checks were successful
continuous-integration/drone/push Build is passing
Prepare for season 3 reset. Update required!
2024-07-17 05:32:07 +00:00

83 lines
3.6 KiB
JavaScript

var tanks = [
{ 'id': 'create_sa:small_filling_tank', 'type': 'water', 'capacity': 8000 },
{ 'id': 'create_sa:medium_filling_tank', 'type': 'water', 'capacity': 16000 },
{ 'id': 'create_sa:large_filling_tank', 'type': 'water', 'capacity': 32000 },
{ 'id': 'create_sa:small_fueling_tank', 'type': 'fuel', 'capacity': 8000 },
{ 'id': 'create_sa:medium_fueling_tank', 'type': 'fuel', 'capacity': 16000 },
{ 'id': 'create_sa:large_fueling_tank', 'type': 'fuel', 'capacity': 32000 },
]
var jetpacks = [
{ 'id': 'create_sa:andesite_jetpack_chestplate', 'type': 'fuel' },
{ 'id': 'create_sa:brass_jetpack_chestplate', 'type': 'both' },
{ 'id': 'create_sa:copper_jetpack_chestplate', 'type': 'water' },
]
ItemEvents.modification(event => {
tanks.forEach((tank) => {
event.modify(tank['id'], (item) => {
item.attachCapability(
CapabilityBuilder.FLUID.customItemStack()
.withCapacity(tank['capacity'])
.onFill((container, fluid, simulate) => {
if (tank['type'] == 'water' && !fluid.hasTag(`create_sa:jetpack_water`)) {
return 0
} else if (tank['type'] == 'fuel' && !fluid.hasTag(`create_sa:jetpack_fuel`)) {
return 0
}
let nbt = container.getOrCreateTag()
let stock = nbt.getDouble('tagStock') * 10.0
let amount = fluid.getAmount()
if (fluid.hasTag(`create_sa:jetpack_fuel`) && tank['type'] == 'fuel') {
// TODO: Strong and weak fuels
/* if (fluid.hasTag(`create_sa:weak_jetpack_fuel`)) {
amount /= 2
} else if (fluid.hasTag(`create_sa:strong_jetpack_fuel`)) {
amount *= 2
} */
}
let filled = Math.min(amount, tank['capacity'] - stock)
if (!simulate) {
nbt.putDouble('tagStock', (stock + filled) / 10.0)
container.setNbt(nbt)
}
return filled
})
)
})
})
jetpacks.forEach((jetpack) => {
event.modify(jetpack['id'], (item) => {
item.attachCapability(
CapabilityBuilder.FLUID.customItemStack()
.withCapacity(16000)
.onFill((container, fluid, simulate) => {
let nbtKey = null
if ((jetpack['type'] == 'water' || jetpack['type'] == 'both') && fluid.hasTag(`create_sa:jetpack_water`)) {
nbtKey = 'tagWater'
} else if ((jetpack['type'] == 'fuel' || jetpack['type'] == 'both') && fluid.hasTag(`create_sa:jetpack_fuel`)) {
nbtKey = 'tagFuel'
} else {
return 0
}
let nbt = container.getOrCreateTag()
let stock = nbt.getDouble(nbtKey) * 10.0
let amount = fluid.getAmount()
let filled = Math.min(amount, 16000 - stock)
if (!simulate) {
nbt.putDouble(nbtKey, (stock + filled) / 10.0)
container.setNbt(nbt)
}
return filled
})
)
})
})
})