SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.37k stars 185 forks source link

Trying to add another 'case' value to a 'switch' statement #651

Closed Attack8 closed 7 months ago

Attack8 commented 7 months ago

The method that I want to inject into reads:

     public Quest build() {
        if (this.id != null && !this.id.isBlank()) {
            if (this.name != null && !this.name.isBlank()) {
                if (this.descriptionData == null) {
                    throw new IllegalStateException("Attempted to create a Quest with invalid DESCRIPTION. DESCRIPTION must not be null or empty.");
                } else if (this.icon == null) {
                    throw new IllegalStateException("Attempted to create a Quest with invalid ICON. ICON must not be null.");
                } else if (this.targetId == null) {
                    throw new IllegalStateException("Attempted to create a Quest with invalid TARGET. TARGET must not be null.");
                } else if (this.targetProgress < 1.0F) {
                    throw new IllegalStateException("Attempted to create a Quest with invalid TARGET PROGRESS. Must be greater than 0.");
                } else if (this.reward == null) {
                    throw new IllegalStateException("Attempted to create a Quest with invalid REWARD. REWARD must not be null.");
                } else {
                    switch (this.type) {
                        case "anvil":
                            return new AnvilQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "block_interact":
                            return new BlockInteractionQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "bounty_complete":
                            return new BountyCompleteQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "checkmark":
                            return new CheckmarkQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "collection":
                            return new CollectionQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "craft_crystal":
                            return new CraftCrystalQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "crafting":
                            return new CraftingQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "enter_vault":
                            return new EnterVaultQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "forge_gear":
                            return new ForgeGearQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "level_up":
                            return new LevelUpQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "mining":
                            return new MiningQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "modify_gear":
                            return new ModifyGearQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        case "survive":
                            return new SurviveQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);
                        default:
                            return null;
                    }
                }
            } else {
                throw new IllegalStateException("Attempted to create a Quest with invalid NAME. NAME must not be null or empty.");
            }
        } else {
            throw new IllegalStateException("Attempted to create a Quest with invalid ID. ID must not be null or empty.");
        }
    }

But I want to add

    case "jar_pickup":
            return new AnimajJarPickupQuest(this.id, this.name, this.descriptionData, this.icon, this.targetId, this.targetProgress, this.unlockedBy, this.reward);

How could I go about dong this? I've tried @Inject with an @At of HEAD and CallbackInfoReturnable, but haven't had any luck

Thanks in advance!