Search in sources :

Example 6 with Advancement

use of net.minecraft.advancements.Advancement in project BuildCraft by BuildCraft.

the class AdvancementUtil method unlockAdvancement.

public static void unlockAdvancement(EntityPlayer player, ResourceLocation advancementName) {
    if (player instanceof EntityPlayerMP) {
        EntityPlayerMP playerMP = (EntityPlayerMP) player;
        AdvancementManager advancementManager = playerMP.getServerWorld().getAdvancementManager();
        if (advancementManager == null) {
            // Because this *can* happen
            return;
        }
        Advancement advancement = advancementManager.getAdvancement(advancementName);
        if (advancement != null) {
            // never assume the advancement exists, we create them but they are removable by datapacks
            playerMP.getAdvancements().grantCriterion(advancement, "code_trigger");
        } else if (UNKNOWN_ADVANCEMENTS.add(advancementName)) {
            BCLog.logger.warn("[lib.advancement] Attempted to trigger undefined advancement: " + advancementName);
        }
    }
}
Also used : AdvancementManager(net.minecraft.advancements.AdvancementManager) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Advancement(net.minecraft.advancements.Advancement)

Example 7 with Advancement

use of net.minecraft.advancements.Advancement in project Cavern2 by kegare.

the class PlayerHelper method grantCriterion.

public static boolean grantCriterion(EntityPlayer entityPlayer, String key, String criterion) {
    if (entityPlayer == null || !(entityPlayer instanceof EntityPlayerMP)) {
        return false;
    }
    EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
    Advancement advancement = player.mcServer.getAdvancementManager().getAdvancement(CaveUtils.getKey(key));
    return advancement != null && player.getAdvancements().grantCriterion(advancement, criterion);
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Advancement(net.minecraft.advancements.Advancement)

Example 8 with Advancement

use of net.minecraft.advancements.Advancement in project takumicraft by TNTModders.

the class TakumiUtils method getAdvancementUnlocked.

@SideOnly(Side.CLIENT)
public static boolean getAdvancementUnlocked(ResourceLocation location) {
    ClientAdvancementManager manager = Minecraft.getMinecraft().player.connection.getAdvancementManager();
    try {
        Field field = TakumiASMNameMap.getField(ClientAdvancementManager.class, "advancementToProgress");
        field.setAccessible(true);
        Map<Advancement, AdvancementProgress> advancementToProgress = (Map<Advancement, AdvancementProgress>) field.get(manager);
        if (advancementToProgress.containsKey(manager.getAdvancementList().getAdvancement(location))) {
            return advancementToProgress.get(manager.getAdvancementList().getAdvancement(location)).isDone();
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : Field(java.lang.reflect.Field) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) ClientAdvancementManager(net.minecraft.client.multiplayer.ClientAdvancementManager) TakumiASMNameMap(com.tntmodders.asm.TakumiASMNameMap) Advancement(net.minecraft.advancements.Advancement) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 9 with Advancement

use of net.minecraft.advancements.Advancement in project SpongeCommon by SpongePowered.

the class MixinAdvancement method onInit.

@SuppressWarnings("ConstantConditions")
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(ResourceLocation id, @Nullable Advancement parentIn, @Nullable DisplayInfo displayIn, AdvancementRewards rewardsIn, Map<String, Criterion> criteriaIn, String[][] requirementsIn, CallbackInfo ci) {
    if (displayIn != null) {
        ((IMixinDisplayInfo) displayIn).setAdvancement(this);
    }
    String path = id.getResourcePath();
    this.name = path.replace('/', '_');
    this.spongeId = id.getResourceDomain() + ':' + this.name;
    if (displayIn != null) {
        this.name = SpongeTexts.toPlain(displayIn.getTitle());
    }
    if (!AdvancementRegistryModule.INSIDE_REGISTER_EVENT) {
        AdvancementRegistryModule.getInstance().registerAdditionalCatalog(this);
    } else {
        // Wait to set the parent until the advancement is registered
        this.tempParent = parentIn;
        this.parent = SpongeAdvancementBuilder.DUMMY_ROOT_ADVANCEMENT;
    }
    // This is only possible when REGISTER_ADVANCEMENTS_ON_CONSTRUCT is true
    if (parentIn == null) {
        // Remove the root suffix from json file tree ids
        if (path.endsWith("/root")) {
            path = path.substring(0, path.lastIndexOf('/'));
        }
        path = path.replace('/', '_');
        String name = path;
        if (displayIn != null) {
            name = this.name;
        }
        path = id.getResourceDomain() + ':' + path;
        this.tree = new SpongeAdvancementTree(this, path, name);
        AdvancementTreeRegistryModule.getInstance().registerAdditionalCatalog(this.tree);
    } else {
        this.tree = ((org.spongepowered.api.advancement.Advancement) parentIn).getTree().orElse(null);
    }
    this.text = SpongeTexts.toText(this.displayText);
    final ImmutableList.Builder<Text> toastText = ImmutableList.builder();
    if (this.display != null) {
        final FrameType frameType = this.display.getFrame();
        toastText.add(Text.builder(new SpongeTranslation("advancements.toast." + frameType.getName())).format(((AdvancementType) (Object) frameType).getTextFormat()).build());
        toastText.add(getDisplayInfo().get().getTitle());
    } else {
        toastText.add(Text.of("Unlocked advancement"));
        toastText.add(Text.of(getId()));
    }
    this.toastText = toastText.build();
    final Set<String> scoreCriteria = new HashSet<>();
    final Map<String, ICriterion> criterionMap = new HashMap<>();
    for (Map.Entry<String, Criterion> entry : new HashMap<>(criteriaIn).entrySet()) {
        final IMixinCriterion mixinCriterion = (IMixinCriterion) entry.getValue();
        final ICriterion criterion;
        if (mixinCriterion.getScoreGoal() != null) {
            criterion = new SpongeScoreCriterion(entry.getKey(), mixinCriterion.getScoreGoal(), entry.getValue().getCriterionInstance());
            scoreCriteria.add(entry.getKey());
            ((SpongeScoreCriterion) criterion).internalCriteria.forEach(criterion1 -> criteriaIn.put(criterion1.getName(), (Criterion) criterion1));
        } else {
            criterion = (ICriterion) mixinCriterion;
            ((IMixinCriterion) criterion).setName(entry.getKey());
        }
        criterionMap.put(entry.getKey(), criterion);
    }
    final List<String[]> entries = new ArrayList<>();
    final List<AdvancementCriterion> andCriteria = new ArrayList<>();
    for (String[] array : requirementsIn) {
        final Set<AdvancementCriterion> orCriteria = new HashSet<>();
        for (String name : array) {
            final ICriterion criterion = criterionMap.get(name);
            if (criterion instanceof SpongeScoreCriterion) {
                ((SpongeScoreCriterion) criterion).internalCriteria.forEach(criterion1 -> entries.add(new String[] { criterion1.getName() }));
            } else {
                entries.add(new String[] { criterion.getName() });
            }
            orCriteria.add(criterion);
        }
        andCriteria.add(OrCriterion.of(orCriteria));
    }
    this.criterion = AndCriterion.of(andCriteria);
    if (!scoreCriteria.isEmpty()) {
        scoreCriteria.forEach(criteriaIn::remove);
        this.criteria = ImmutableMap.copyOf(criteriaIn);
        this.requirements = entries.toArray(new String[entries.size()][]);
    }
}
Also used : SpongeTranslation(org.spongepowered.common.text.translation.SpongeTranslation) SpongeAdvancementTree(org.spongepowered.common.advancement.SpongeAdvancementTree) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.SpongeScoreCriterion) IMixinDisplayInfo(org.spongepowered.common.interfaces.advancement.IMixinDisplayInfo) Criterion(net.minecraft.advancements.Criterion) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) ICriterion(org.spongepowered.common.advancement.ICriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.SpongeScoreCriterion) IMixinCriterion(org.spongepowered.common.interfaces.advancement.IMixinCriterion) FrameType(net.minecraft.advancements.FrameType) ICriterion(org.spongepowered.common.advancement.ICriterion) HashSet(java.util.HashSet) Text(org.spongepowered.api.text.Text) IMixinCriterion(org.spongepowered.common.interfaces.advancement.IMixinCriterion) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Advancement(net.minecraft.advancements.Advancement) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with Advancement

use of net.minecraft.advancements.Advancement in project SpongeCommon by SpongePowered.

the class MixinPlayerAdvancements method onUnregisterListenersGetProgress.

@Nullable
@Redirect(method = "unregisterListeners", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/AdvancementProgress;getCriterionProgress(Ljava/lang/String;)Lnet/minecraft/advancements/CriterionProgress;"))
private CriterionProgress onUnregisterListenersGetProgress(AdvancementProgress advancementProgress, String criterion) {
    final org.spongepowered.api.advancement.Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).getAdvancement();
    final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((Advancement) advancement).getCriteria().get(criterion);
    final IMixinCriterion mixinCriterion = (IMixinCriterion) advancementCriterion;
    // Only remove the trigger once the goal is reached
    if (mixinCriterion.getScoreCriterion() != null && !((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).get(mixinCriterion.getScoreCriterion()).get().achieved()) {
        return null;
    }
    return advancementProgress.getCriterionProgress(criterion);
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) IMixinAdvancementProgress(org.spongepowered.common.interfaces.advancement.IMixinAdvancementProgress) IMixinCriterion(org.spongepowered.common.interfaces.advancement.IMixinCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) Advancement(net.minecraft.advancements.Advancement) Redirect(org.spongepowered.asm.mixin.injection.Redirect) Nullable(javax.annotation.Nullable)

Aggregations

Advancement (net.minecraft.advancements.Advancement)12 AdvancementProgress (net.minecraft.advancements.AdvancementProgress)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 ResourceLocation (net.minecraft.util.ResourceLocation)3 Map (java.util.Map)2 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)2 IMixinCriterion (org.spongepowered.common.interfaces.advancement.IMixinCriterion)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TypeToken (com.google.common.reflect.TypeToken)1 BlockModFluid (com.teamwizardry.librarianlib.features.base.fluid.BlockModFluid)1 ModFluid (com.teamwizardry.librarianlib.features.base.fluid.ModFluid)1 EntityUpdateEvent (com.teamwizardry.librarianlib.features.forgeevents.EntityUpdateEvent)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 FluidTracker (com.teamwizardry.wizardry.api.block.FluidTracker)1 IExplodable (com.teamwizardry.wizardry.api.item.IExplodable)1 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)1 LibParticles (com.teamwizardry.wizardry.client.fx.LibParticles)1 DamageSourceMana (com.teamwizardry.wizardry.common.core.DamageSourceMana)1 FluidRecipeLoader (com.teamwizardry.wizardry.crafting.mana.FluidRecipeLoader)1