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);
}
}
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);
}
}
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");
}
}
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);
}
}
}
Aggregations