use of org.spongepowered.common.data.value.ImmutableSpongeValue in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$ThrowIgniteEventForFire.
@Redirect(method = "setRemainingFireTicks", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;remainingFireTicks:I", opcode = Opcodes.PUTFIELD))
private void impl$ThrowIgniteEventForFire(final Entity entity, final int ticks) {
if (!((LevelBridge) this.level).bridge$isFake() && ShouldFire.IGNITE_ENTITY_EVENT && this.remainingFireTicks < 1 && ticks >= Constants.Entity.MINIMUM_FIRE_TICKS && this.impl$canCallIgniteEntityEvent()) {
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(((org.spongepowered.api.entity.Entity) this).location().world());
final IgniteEntityEvent event = SpongeEventFactory.createIgniteEntityEvent(frame.currentCause(), Ticks.of(ticks), Ticks.of(ticks), (org.spongepowered.api.entity.Entity) this);
if (SpongeCommon.post(event)) {
// Don't do anything
return;
}
final DataTransactionResult transaction = DataTransactionResult.builder().replace(new ImmutableSpongeValue<>(Keys.FIRE_TICKS, Ticks.of(Math.max(this.remainingFireTicks, 0)))).success(new ImmutableSpongeValue<>(Keys.FIRE_TICKS, event.fireTicks())).result(DataTransactionResult.Type.SUCCESS).build();
final ChangeDataHolderEvent.ValueChange valueChange = SpongeEventFactory.createChangeDataHolderEventValueChange(PhaseTracker.SERVER.currentCause(), transaction, (DataHolder.Mutable) this);
Sponge.eventManager().post(valueChange);
if (valueChange.isCancelled()) {
// If the event is cancelled, well, don't change the underlying value.
return;
}
this.remainingFireTicks = valueChange.endResult().successfulValue(Keys.FIRE_TICKS).map(Value::get).map(t -> (int) t.ticks()).orElse(0);
}
return;
}
// Vanilla functionality
this.remainingFireTicks = ticks;
}
Aggregations