Search in sources :

Example 1 with Trigger

use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.

the class MixinICriterionInstance method getType.

@Override
default Trigger getType() {
    final ICriterionTrigger triggerType = CriteriaTriggers.get(getId());
    checkNotNull(triggerType, "triggerType");
    return (Trigger) triggerType;
}
Also used : Trigger(org.spongepowered.api.advancement.criteria.trigger.Trigger) FilteredTrigger(org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger) ICriterionTrigger(net.minecraft.advancements.ICriterionTrigger) ICriterionTrigger(net.minecraft.advancements.ICriterionTrigger)

Example 2 with Trigger

use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.

the class SpongeTriggerBuilder method build.

@Override
public Trigger<C> build() {
    checkState(this.id != null, "The id must be set");
    checkState(this.configType != null, "The configType must be set");
    final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
    final String name = StringUtils.isNotEmpty(this.name) ? this.name : this.id;
    return (Trigger<C>) new SpongeTrigger((Class) this.configType, (Function) this.constructor, new ResourceLocation(plugin.getId(), id), (Consumer) this.eventHandler, name);
}
Also used : Function(java.util.function.Function) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Trigger(org.spongepowered.api.advancement.criteria.trigger.Trigger) Consumer(java.util.function.Consumer) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 3 with Trigger

use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.

the class CriterionTriggerInstanceMixin_API method type.

@Override
default Trigger type() {
    final CriterionTrigger triggerType = CriteriaTriggers.getCriterion(this.shadow$getCriterion());
    Preconditions.checkNotNull(triggerType, "triggerType");
    return (Trigger) triggerType;
}
Also used : Trigger(org.spongepowered.api.advancement.criteria.trigger.Trigger) FilteredTrigger(org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger) CriterionTrigger(net.minecraft.advancements.CriterionTrigger) CriterionTrigger(net.minecraft.advancements.CriterionTrigger)

Example 4 with Trigger

use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project SpongeCommon by SpongePowered.

the class AdvancementTest method onRegisterTriggers.

@Listener
public void onRegisterTriggers(GameRegistryEvent.Register<Trigger> event) {
    this.logger.info("Advancements test source: " + this.pluginContainer.getSource().orElse(null));
    this.trigger = Trigger.builder().typeSerializableConfig(MyTriggerConfig.class).listener(triggerEvent -> {
        final Random random = new Random();
        final float value = random.nextFloat();
        final float chance = triggerEvent.getTrigger().getConfiguration().chance;
        triggerEvent.setResult(value < chance);
        triggerEvent.getTargetEntity().sendMessage(Text.of(value + " < " + chance + " -> " + triggerEvent.getResult()));
    }).id("my_trigger").build();
    event.register(this.trigger);
}
Also used : DisplayInfo(org.spongepowered.api.advancement.DisplayInfo) Getter(org.spongepowered.api.event.filter.Getter) ScoreAdvancementCriterion(org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) GameRegistryEvent(org.spongepowered.api.event.game.GameRegistryEvent) ConfigSerializable(ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable) Inject(com.google.inject.Inject) ItemTypes(org.spongepowered.api.item.ItemTypes) HashMap(java.util.HashMap) Random(java.util.Random) Key(org.spongepowered.api.data.key.Key) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) AdvancementTypes(org.spongepowered.api.advancement.AdvancementTypes) Text(org.spongepowered.api.text.Text) Map(java.util.Map) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Transaction(org.spongepowered.api.data.Transaction) Nullable(javax.annotation.Nullable) Setting(ninja.leaping.configurate.objectmapping.Setting) Logger(org.slf4j.Logger) BlockTypes(org.spongepowered.api.block.BlockTypes) Trigger(org.spongepowered.api.advancement.criteria.trigger.Trigger) Vector2d(com.flowpowered.math.vector.Vector2d) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) Carrier(org.spongepowered.api.item.inventory.Carrier) Plugin(org.spongepowered.api.plugin.Plugin) FilteredTriggerConfiguration(org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration) Explosion(org.spongepowered.api.world.explosion.Explosion) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Furnace(org.spongepowered.api.block.tileentity.carrier.Furnace) Advancement(org.spongepowered.api.advancement.Advancement) TreeLayoutElement(org.spongepowered.api.advancement.TreeLayoutElement) Player(org.spongepowered.api.entity.living.player.Player) AdvancementTreeEvent(org.spongepowered.api.event.advancement.AdvancementTreeEvent) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Listener(org.spongepowered.api.event.Listener) AdvancementTree(org.spongepowered.api.advancement.AdvancementTree) First(org.spongepowered.api.event.filter.cause.First) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Random(java.util.Random) Listener(org.spongepowered.api.event.Listener)

Example 5 with Trigger

use of org.spongepowered.api.advancement.criteria.trigger.Trigger in project LanternServer by LanternPowered.

the class AdvancementTest method onRegisterTriggers.

@Listener
public void onRegisterTriggers(GameRegistryEvent.Register<Trigger> event) {
    this.trigger = Trigger.builder().typeSerializableConfig(MyTriggerConfig.class).listener(triggerEvent -> {
        final Random random = new Random();
        final float value = random.nextFloat();
        final float chance = triggerEvent.getTrigger().getConfiguration().chance;
        triggerEvent.setResult(value < chance);
    }).id("my_trigger").build();
    event.register(this.trigger);
}
Also used : DisplayInfo(org.spongepowered.api.advancement.DisplayInfo) Getter(org.spongepowered.api.event.filter.Getter) ScoreAdvancementCriterion(org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion) GameRegistryEvent(org.spongepowered.api.event.game.GameRegistryEvent) ConfigSerializable(ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable) Inject(com.google.inject.Inject) ItemTypes(org.spongepowered.api.item.ItemTypes) HashMap(java.util.HashMap) Random(java.util.Random) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) AdvancementTypes(org.spongepowered.api.advancement.AdvancementTypes) Text(org.spongepowered.api.text.Text) Map(java.util.Map) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Nullable(javax.annotation.Nullable) Setting(ninja.leaping.configurate.objectmapping.Setting) Logger(org.slf4j.Logger) Trigger(org.spongepowered.api.advancement.criteria.trigger.Trigger) Vector2d(com.flowpowered.math.vector.Vector2d) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) FilteredTrigger(org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger) Carrier(org.spongepowered.api.item.inventory.Carrier) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Plugin(org.spongepowered.api.plugin.Plugin) FilteredTriggerConfiguration(org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Furnace(org.spongepowered.api.block.tileentity.carrier.Furnace) Advancement(org.spongepowered.api.advancement.Advancement) TreeLayoutElement(org.spongepowered.api.advancement.TreeLayoutElement) Player(org.spongepowered.api.entity.living.player.Player) AdvancementTreeEvent(org.spongepowered.api.event.advancement.AdvancementTreeEvent) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Listener(org.spongepowered.api.event.Listener) AdvancementTree(org.spongepowered.api.advancement.AdvancementTree) First(org.spongepowered.api.event.filter.cause.First) Random(java.util.Random) Listener(org.spongepowered.api.event.Listener)

Aggregations

Trigger (org.spongepowered.api.advancement.criteria.trigger.Trigger)5 FilteredTrigger (org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger)3 PluginContainer (org.spongepowered.api.plugin.PluginContainer)3 Vector2d (com.flowpowered.math.vector.Vector2d)2 Inject (com.google.inject.Inject)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Random (java.util.Random)2 Nullable (javax.annotation.Nullable)2 Setting (ninja.leaping.configurate.objectmapping.Setting)2 ConfigSerializable (ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable)2 Logger (org.slf4j.Logger)2 Advancement (org.spongepowered.api.advancement.Advancement)2 AdvancementTree (org.spongepowered.api.advancement.AdvancementTree)2 AdvancementTypes (org.spongepowered.api.advancement.AdvancementTypes)2 DisplayInfo (org.spongepowered.api.advancement.DisplayInfo)2 TreeLayoutElement (org.spongepowered.api.advancement.TreeLayoutElement)2 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)2 ScoreAdvancementCriterion (org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion)2 FilteredTriggerConfiguration (org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration)2