Draconic Evolution

Draconic Evolution

77M Downloads

[Feature Request] Access transforming

SirEndii opened this issue ยท 7 comments

commented

Hey,
I want to create an add-on for DE, for that I would need access to the fields and methods core(TileEnergyPylon), lastTickEnergy(TileEnergyCore) and getCachedCore(TileReactorComponent) (Probably more in the future).
I just want to ask, am I allowed to create an PR for this to change the access of these methods/fields or create getters for them?

commented

If you really want to access those fields, you can always use reflection.

commented

I wanted to prevent that, that's the reason I created this request.
If DE does not change the access of the fields/methods, I will use reflection.

commented

Understandable. I'm guessing this is for DE2 (for MC 1.12.2)?

commented

Nah, 1.16

commented

Your best bet would be to use mixin accessors.
For example:

@Mixin (ServerWorld.class)
public interface ServerLevelAccessor {

    @Accessor
    Int2ObjectMap<Entity> getEntitiesById();
}

Exposes the entitiesByID field on ServerWorld.
Then to use that you do

ServerWorld world = ...;
Int2ObjectMap<Entity> entitiesById = ((ServerLevelAccessor)world).getEntitiesById();
commented

Ok that should work. Just be aware reflection is rather slow so if you will be calling that method a lot a mixin would be much more efficient.