Last active
November 13, 2024 16:02
-
-
Save mcm/2e5318174b19460b9ca070e41d1c4d27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
}) | |
) | |
}) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"values": [ | |
"minecraft:lava" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"values": [ | |
"minecraft:water" | |
] | |
} |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 (: