Search in sources :

Example 1 with AdvancementManager

use of net.minecraft.advancements.AdvancementManager 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 2 with AdvancementManager

use of net.minecraft.advancements.AdvancementManager in project ImmersiveEngineering by BluSunrize.

the class Utils method unlockIEAdvancement.

public static void unlockIEAdvancement(EntityPlayer player, String name) {
    if (player instanceof EntityPlayerMP) {
        PlayerAdvancements advancements = ((EntityPlayerMP) player).getAdvancements();
        AdvancementManager manager = ((WorldServer) player.getEntityWorld()).getAdvancementManager();
        Advancement advancement = manager.getAdvancement(new ResourceLocation(ImmersiveEngineering.MODID, name));
        if (advancement != null)
            advancements.grantCriterion(advancement, "code_trigger");
    }
}
Also used : AdvancementManager(net.minecraft.advancements.AdvancementManager) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) Advancement(net.minecraft.advancements.Advancement)

Aggregations

Advancement (net.minecraft.advancements.Advancement)2 AdvancementManager (net.minecraft.advancements.AdvancementManager)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 PlayerAdvancements (net.minecraft.advancements.PlayerAdvancements)1 WorldServer (net.minecraft.world.WorldServer)1