Search in sources :

Example 1 with PlayerAdvancements

use of net.minecraft.advancements.PlayerAdvancements in project Railcraft by Railcraft.

the class BaseTrigger method trigger.

void trigger(EntityPlayerMP player, Predicate<? super T> predicate) {
    PlayerAdvancements advancements = player.getAdvancements();
    Collection<Listener<T>> done = manager.get(advancements).parallelStream().filter(listener -> predicate.test(listener.getCriterionInstance())).collect(Collectors.toList());
    for (Listener<T> listener : done) {
        listener.grantCriterion(advancements);
    }
}
Also used : PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Tuple(net.minecraft.util.Tuple) ICriterionTrigger(net.minecraft.advancements.ICriterionTrigger) Collectors(java.util.stream.Collectors) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements)

Example 2 with PlayerAdvancements

use of net.minecraft.advancements.PlayerAdvancements in project Railcraft by Railcraft.

the class MultiBlockFormedTrigger method onMultiBlockForm.

@SubscribeEvent
public void onMultiBlockForm(MultiBlockEvent.Form event) {
    TileRailcraft tile = event.getMaster();
    GameProfile owner = tile.getOwner();
    MinecraftServer server = requireNonNull(Game.getServer());
    EntityPlayerMP player = server.getPlayerList().getPlayerByUUID(owner.getId());
    if (player == null) {
        // Offline
        return;
    }
    PlayerAdvancements advancements = player.getAdvancements();
    Collection<Listener<Instance>> done = manager.get(advancements).stream().filter(listener -> listener.getCriterionInstance().matches(tile)).collect(Collectors.toList());
    for (Listener<Instance> listener : done) {
        listener.grantCriterion(advancements);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) GameProfile(com.mojang.authlib.GameProfile) Conditions(mods.railcraft.common.util.misc.Conditions) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RailcraftConstantsAPI(mods.railcraft.api.core.RailcraftConstantsAPI) MinecraftServer(net.minecraft.server.MinecraftServer) MultiBlockEvent(mods.railcraft.common.events.MultiBlockEvent) Objects.requireNonNull(java.util.Objects.requireNonNull) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Collection(java.util.Collection) Game(mods.railcraft.common.util.misc.Game) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) MinecraftForge(net.minecraftforge.common.MinecraftForge) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) JsonTools(mods.railcraft.common.util.json.JsonTools) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) JsonUtils(net.minecraft.util.JsonUtils) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) NBTPredicate(net.minecraft.advancements.critereon.NBTPredicate) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) GameProfile(com.mojang.authlib.GameProfile) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with PlayerAdvancements

use of net.minecraft.advancements.PlayerAdvancements 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)

Example 4 with PlayerAdvancements

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

the class SpongeTrigger method trigger.

@Override
public void trigger(Player player) {
    final PlayerAdvancements playerAdvancements = ((EntityPlayerMP) player).getAdvancements();
    final Cause cause = Sponge.getCauseStackManager().getCurrentCause();
    final TypeToken typeToken = TypeToken.of(this.triggerConfigurationClass);
    for (Listener listener : new ArrayList<>(this.listeners.get(playerAdvancements))) {
        final IMixinICriterionTriggerListener mixinListener = (IMixinICriterionTriggerListener) listener;
        final Advancement advancement = (Advancement) mixinListener.getAdvancement();
        final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((net.minecraft.advancements.Advancement) advancement).getCriteria().get(mixinListener.getCriterionName());
        final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, advancementCriterion, typeToken, player, (FilteredTrigger) listener.getCriterionInstance(), this.eventHandler == null);
        if (this.eventHandler != null) {
            this.eventHandler.accept(event);
            if (!event.getResult()) {
                continue;
            }
        }
        SpongeImpl.postEvent(event);
        if (event.getResult()) {
            listener.grantCriterion(playerAdvancements);
        }
    }
}
Also used : IMixinICriterionTriggerListener(org.spongepowered.common.interfaces.advancement.IMixinICriterionTriggerListener) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) TypeToken(com.google.common.reflect.TypeToken) Cause(org.spongepowered.api.event.cause.Cause) IMixinICriterionTriggerListener(org.spongepowered.common.interfaces.advancement.IMixinICriterionTriggerListener) ArrayList(java.util.ArrayList) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Advancement(org.spongepowered.api.advancement.Advancement)

Aggregations

PlayerAdvancements (net.minecraft.advancements.PlayerAdvancements)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2 ICriterionInstance (net.minecraft.advancements.ICriterionInstance)2 TypeToken (com.google.common.reflect.TypeToken)1 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)1 JsonObject (com.google.gson.JsonObject)1 GameProfile (com.mojang.authlib.GameProfile)1 ArrayList (java.util.ArrayList)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Predicate (java.util.function.Predicate)1 RailcraftConstantsAPI (mods.railcraft.api.core.RailcraftConstantsAPI)1 Instance (mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance)1 TileRailcraft (mods.railcraft.common.blocks.TileRailcraft)1 MultiBlockEvent (mods.railcraft.common.events.MultiBlockEvent)1 JsonTools (mods.railcraft.common.util.json.JsonTools)1 Conditions (mods.railcraft.common.util.misc.Conditions)1 Game (mods.railcraft.common.util.misc.Game)1 Advancement (net.minecraft.advancements.Advancement)1