-
-
Save mcm/2e5318174b19460b9ca070e41d1c4d27 to your computer and use it in GitHub Desktop.
/* | |
For use with KubeJS. Allows for filling jetpacks and tanks via Spouts in Create. | |
Also depends on PowerfulJS. | |
Save this as a startup_script in your KubeJS directory. | |
Capacity is mapped in a way that is equivalent to manual filling, e.g. each bucket | |
fills by 100.0 "units", so a small tank requires 8 buckets to fill, and a large | |
tank requires 32 buckets to fill. | |
You'll also need to create two new fluid tags, `create_sa:jetpack_water` and | |
`create_sa:jetpack_fuel`. Basic versions of the files needed are included, you can | |
add these to `kubejs/data/create_sa/tags/fluids` inside your Minecraft game | |
directory. | |
*/ | |
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 | |
}) | |
) | |
}) | |
}) | |
}) |
{ | |
"values": [ | |
"minecraft:lava" | |
] | |
} |
{ | |
"values": [ | |
"minecraft:water" | |
] | |
} |
hello your projet could save me Lol every time I have to fill it up manually and all but i tried to install the script did all like you told and then i get an error
the error happen on the medium cause i tried to edit it to remove the tiny tank cause the error was on it but it seem the error happen on every tank cause the function isn't found can u give me a hand ? I'll give you my discord if you are able to help me could you add me on here ? it's wrier. ty in advance
@Herozia-Wrier do you have PowerfulJS installed?
I forgot to install it, then I did install it the games does not longer crash but the tank or jetpack aren't refilled by the spout, the log state that your script did start :
i did create the fuel and water tag for the other script to use put it in the right folder and also put the refilling script in the startup script but nothing seem to work (: ty for the help you are providing it's really nice of u (:
Hey sorry, looks like that instruction wasn't particularly clear. The folder doesn't need "directory" in the name. Try renaming "fluids directory" to just "fluids" and restart, see if that works.
men ty so much it work perfectly fine, that's so much better
Oh gosh, i was tired to search a solution for that thing and you give it with entire kindness of this world, thank's man
Great work