#Is it possible to read ad astra settings for a dimension?

20 messages · Page 1 of 1 (latest)

spice egret
#

I need the information in kubejs if a dimension has oxygen to change the behavior of some custom blocks (like spread my custom dead_grass). Is there a possibility?

ember gyroBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

late cairn
#

with Java.loadClass('earth.terrarium.adastra.api.PlanetAPI').API, quite possibly

#

just need to load the right class and you can fetch the desired planet from the dimension

#

and then read properties as necessary

#

you can use this method from earth.terrarium.adastra.api.systems.OxygenApi

spice egret
#

I can load Java classes in KubeJS? How is that possible?

late cairn
#

assign Java.loadClass(string classpath) to a variable

#

from there, you can call the variable and use it to access the class' methods/functions, and constructors

spice egret
#

Thank you so much, i'll try that

late cairn
#

also note that for a lot of API classes, you have to get the API instance by using an appropriate method or variable, which can sometimes be from another class than the one you want to access stuff from

#

in the case of adastra, i assume .API on the respective API class is what works, but it's possible it doesn't

#

you can also stick .API onto the end of the class variable's value, as seen with my first message, so that you don't need to do classVar.API.method() every time, just classVar.method()

spice egret
#

Hey first of all, thank you a lot! The Part with the API works just fine. Now i have a problem with the setOxygen method. The log is telling me, my call is ambiguous. There are 2 Versions of this method in ad astra. But one wants a BlockPos and the other a Collection of BlockPos. I went the first way, but it seems like it is not clear which version of the method is meant to be used.

#

My Test-Code:

BlockEvents.rightClicked('minecraft:chest', event => {
    const ad_astra = Java.loadClass('earth.terrarium.adastra.api.systems.OxygenApi').API
    console.log(ad_astra.hasOxygen(event.level))
    console.log(ad_astra.hasOxygen(event.level, new BlockPos(event.block.x,event.block.y,event.block.z)))
    ad_astra.setOxygen(event.level, new BlockPos(event.block.x,event.block.y+1,event.block.z),true)
    ad_astra.setOxygen(event.level, new BlockPos(event.block.x,event.block.y+2,event.block.z),true)
    console.log(ad_astra.hasOxygen(event.level, new BlockPos(event.block.x,event.block.y+2,event.block.z)))
})

The methods in Ad-Astra:

/**
     * Sets the position's oxygen presence to the given value.
     *
     * @param level  The level to check.
     * @param pos    The position to add oxygen to.
     * @param oxygen The oxygen to set.
     */
    void setOxygen(Level level, BlockPos pos, boolean oxygen);

    /**
     * Sets the oxygen presence of the given positions to the given value.
     *
     * @param level     The level to check.
     * @param positions The position to add oxygen to.
     * @param oxygen    The oxygen to set.
     */
    void setOxygen(Level level, Collection<BlockPos> positions, boolean oxygen);

The Error:

[14:06:32] [ERROR] ! oxygen_test.js#5: Error in 'BlockEvents.rightClicked': The choice of Java method earth.terrarium.adastra.common.systems.OxygenApiImpl.setOxygen matching JavaScript argument types (net.minecraft.server.level.ServerLevel,net.minecraft.core.BlockPos,boolean) is ambiguous; candidate methods are: 
    void setOxygen(net.minecraft.world.level.Level,net.minecraft.core.BlockPos,boolean)
    void setOxygen(net.minecraft.world.level.Level,java.util.Collection,boolean)
late cairn
#

right, this

#
ad_astra['setOxygen(net.minecraft.world.level.Level,net.minecraft.core.BlockPos,boolean)'](event.level, new BlockPos(event.block.x,event.block.y+1,event.block.z),true)```
#

basically doing this should work

spice egret
#

works just fine, thank you 🙂