use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class CriterionTrigger_ListenerMixin method impl$callEvents.
// @formatter:on
@SuppressWarnings({ "unchecked", "rawtypes" })
@Inject(method = "run", at = @At("HEAD"), cancellable = true)
private void impl$callEvents(PlayerAdvancements playerAdvancements, CallbackInfo ci) {
final org.spongepowered.api.advancement.Advancement advancement = (org.spongepowered.api.advancement.Advancement) this.advancement;
AdvancementCriterion advancementCriterion = (AdvancementCriterion) this.advancement.getCriteria().get(this.criterion);
final CriterionBridge criterionBridge = (CriterionBridge) advancementCriterion;
if (criterionBridge.bridge$getScoreCriterion() != null) {
advancementCriterion = criterionBridge.bridge$getScoreCriterion();
}
if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
// Some mods do advancement granting on async threads, and we can't allow for the spam to be thrown.
return;
}
// Sponge filters are always handled in the trigger method
if (!(this.trigger instanceof SpongeFilteredTrigger)) {
final FilteredTrigger<FilteredTriggerConfiguration> filteredTrigger = (FilteredTrigger) this.trigger;
if (filteredTrigger.type() instanceof SpongeCriterionTrigger) {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ServerPlayer player = ((PlayerAdvancementsBridge) playerAdvancements).bridge$getPlayer();
final TypeToken<FilteredTriggerConfiguration> typeToken = (TypeToken) TypeToken.get(filteredTrigger.type().configurationType());
final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, advancementCriterion, typeToken, player, filteredTrigger, true);
SpongeCommon.post(event);
if (!event.result()) {
ci.cancel();
return;
}
}
}
PhaseTracker.getCauseStackManager().pushCause(this.trigger);
// the score be increased by one.
if (advancementCriterion instanceof ScoreAdvancementCriterion) {
((PlayerAdvancementsBridge) playerAdvancements).bridge$getPlayer().progress(advancement).get((ScoreAdvancementCriterion) advancementCriterion).get().add(1);
ci.cancel();
PhaseTracker.getCauseStackManager().popCause();
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class BedBlockMixin method impl$onUseBed.
@Inject(method = "use", at = @At(value = "HEAD"), cancellable = true)
private void impl$onUseBed(final BlockState param0, final Level param1, final BlockPos param2, final Player param3, final InteractionHand param4, final BlockHitResult param5, final CallbackInfoReturnable<InteractionResult> cir) {
if (!param1.isClientSide) {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
final BlockPos bedLocation = param5.getBlockPos();
final BlockSnapshot snapshot = ((ServerWorld) param1).createSnapshot(bedLocation.getX(), bedLocation.getY(), bedLocation.getZ());
if (Sponge.eventManager().post(SpongeEventFactory.createSleepingEventPre(currentCause, snapshot, (Living) param3))) {
cir.setReturnValue(InteractionResult.CONSUME);
}
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class CampfireBlockEntityMixin method impl$assembleCampfireResult.
@Surrogate
private void impl$assembleCampfireResult(final CallbackInfo ci, final int i, final ItemStack itemStack, final Container iInventory, final ItemStack itemStack1, final BlockPos blockPos) {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(itemStack1);
final CookingEvent.Finish event = SpongeEventFactory.createCookingEventFinish(cause, (Campfire) this, Collections.singletonList(snapshot), Optional.empty(), Optional.ofNullable((CookingRecipe) this.impl$cookingRecipe[i]));
SpongeCommon.post(event);
this.impl$cookingRecipe[i] = null;
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class CampfireBlockEntityMixin method impl$canCook.
// Tick up
@Inject(method = "cook", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/entity/CampfireBlockEntity;cookingProgress:[I", ordinal = 1))
private void impl$canCook(final CallbackInfo ci, final int i, final ItemStack itemStack) {
final boolean isEmpty = itemStack.isEmpty();
if (!isEmpty) {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ItemStackSnapshot stack = ItemStackUtil.snapshotOf(this.items.get(i));
final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (Campfire) this, stack, Optional.empty(), Optional.ofNullable((CookingRecipe) impl$cookingRecipe[i]));
SpongeCommon.post(event);
if (event.isCancelled()) {
this.cookingProgress[i]--;
}
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class BrewingStandBlockEntityMixin method impl$callBrewEvents.
@Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILEXCEPTION, slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/BrewingStandBlockEntity;isBrewable()Z")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/BrewingStandBlockEntity;setChanged()V"))
private void impl$callBrewEvents(CallbackInfo ci, ItemStack fuelStack, boolean isBrewable, boolean isBrewing, ItemStack ingredientStack) {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
if (isBrewing) {
if (this.brewTime == 0 && isBrewable) {
List<ItemStackSnapshot> stacks = new ArrayList<>();
for (int i = 0; i < 3; ++i) {
stacks.add(ItemStackUtil.snapshotOf(this.items.get(i)));
}
final BrewingEvent.Finish event = SpongeEventFactory.createBrewingEventFinish(currentCause, Collections.unmodifiableList(stacks), (BrewingStand) this, ItemStackUtil.snapshotOf(ingredientStack));
Sponge.eventManager().post(event);
} else if (!isBrewable || this.ingredient != ingredientStack.getItem()) {
final BrewingEvent.Interrupt event = SpongeEventFactory.createBrewingEventInterrupt(currentCause, (BrewingStand) this, ItemStackUtil.snapshotOf(ingredientStack));
Sponge.eventManager().post(event);
}
} else if (isBrewable && this.fuel > 0) {
final BrewingEvent.Start event = SpongeEventFactory.createBrewingEventStart(currentCause, (BrewingStand) this, ItemStackUtil.snapshotOf(ingredientStack));
if (Sponge.eventManager().post(event)) {
this.brewTime = 0;
this.ingredient = Items.AIR;
this.fuel++;
}
}
}
Aggregations