#type erasure issues.

1 messages ยท Page 1 of 1 (latest)

hidden horizonBOT
#

<@&987246399047479336> please have a look, thanks.

narrow axle
#
package com.example.commands;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;
import thunder.hack.ThunderHack;
import thunder.hack.cmd.Command;

import java.util.concurrent.atomic.AtomicBoolean;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

public abstract class ExampleCommand extends Command {
    public ExampleCommand() {
        super("help");
    }

    @Override
    public void executeBuild(@NotNull LiteralArgumentBuilder<ServerCommandSource> builder) {
        builder.executes(context -> {
            sendMessage("Commands: \n");

            AtomicBoolean flip = new AtomicBoolean(false);

            ThunderHack.commandManager.getCommands().forEach(command -> {
                        context.getSource().getPlayer().sendMessage(Text.of(
                                (flip.get() ? Formatting.LIGHT_PURPLE : Formatting.DARK_PURPLE)
                                        + ThunderHack.commandManager.getPrefix()
                                        + (flip.get() ? Formatting.AQUA : Formatting.DARK_AQUA)
                                        + command.getName()
                                        + (command.getAliases().isEmpty() ? "" : " (" + command.getAliases() + ")")
                                        + Formatting.DARK_GRAY + " -> "
                                        + (flip.get() ? Formatting.WHITE : Formatting.GRAY)
                                        + command.getDescription()
                        ));
                        flip.set(!flip.get());
                    }
            );

            return SINGLE_SUCCESS;
        });
    }
}
hidden horizonBOT
narrow axle
#

Heres the command superclass

hidden horizonBOT
grave bison
#

generics are not covariant

#

a Type<Super> is not the same as a Type<Sub>

#

Type<Animal> is not the same as Type<Cat>

#

so you are not overriding the method, since the super expects CommandSource, but the sub is defining ServerCommandSource

narrow axle
#

Oh wait, that makes sense. Let me try that

#

'executeBuild(LiteralArgumentBuilder<CommandSource>)' in 'com.example.commands.ExampleCommand' clashes with 'executeBuild(LiteralArgumentBuilder<class_2172>)' in 'thunder.hack.cmd.Command'; both methods have same erasure, yet neither overrides the other

grave bison
#

what is class_2172?

#

is the supertype decompiled?

narrow axle
#

seems to be an obfuscated minecraft class

narrow axle
#

I have it included

#

its the thunderhack

grave bison
#

so use the expected types. apparently class_2172 is the expected type

narrow axle
#

There is so many issues

#

also says Cannot resolve method 'getPlayer()'

#

But this code is the exact same inside the main mod

#

the issue is just that im using it from a different mod

grave bison
#

how did you add the dependency?

#

if its from a different mod, how are you accessing the types from that mod?

narrow axle
#

though jitpack with gradle

grave bison
#

share the link

narrow axle
#

the repo link?

grave bison
#

the artifact

narrow axle
#

or the jitpack

grave bison
#

the jitpack dependency

narrow axle
#

'com.github.Pan4ur:ThunderHack-Recode:c37468bbed'

grave bison
#

so i can look it up

#

and what package are those types in?

narrow axle
#

The command?

grave bison
#

the one you're trying to access

narrow axle
#

its thunder.hack.cmd.Command

narrow axle
#

import net.minecraft.command.CommandSource;

grave bison
#

so i found the recode repo, i went the cmd package

#

cant find CommandSource

#

CommandSource is the type thats expected

narrow axle
#

Yeah

grave bison
narrow axle
#

CommandSource isnt built into the mod

#

its from minecraft

#

net.minecraft.command.CommandSource;

grave bison
#

yeah so that seems to be the issue

#

im no MC dev, slowly been getting exposed to the environment

#

arent there mappings you could apply?

narrow axle
#

its imported perfectly fine

grave bison
#

this is a compiler issue, yeah?

#

not at runtime, right?

narrow axle
#

i believe so

#

uh let me try at runtime

grave bison
#

no need. if you encountered the issue before running, its a compiler error

narrow axle
#

Yeah it wont even build, its a compiler error

grave bison
#

im just trying to understand why a decompiled name would show up in a compiler error when you're referencing a non-decompiled library

narrow axle
#

I have no clue, its weird.

grave bison
#

this is probably better suited for the MC community. theres something going on that isnt being shown here

#

and until we see it, not much we can do, other than make assumpsions based on the error

narrow axle
#

๐Ÿ‘

grave bison
#

the library doesnt have any decompiled-like naming

#

so some system is existing in between somewhere

#

MC devs may know about it more

#

but yeah, in terms of generics, gotta make sure its the exact type, or use another feature (bounded wildcards) to allow covariance

#

but tbh, that is the least of your worries ๐Ÿ˜‚

narrow axle
#

Thanks for the help!