use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class FireworkRocketItemMixin method impl$throwConstructPreEvent.
/**
* Private method for bridging the duplicate between
* {@link #spongeImpl$ThrowPreBeforeSpawning(World, PlayerEntity, Hand, CallbackInfoReturnable, ItemStack)} and
* {@link #spongeImpl$ThrowPrimeEventsIfCancelled(ItemUseContext, CallbackInfoReturnable)}
* since both follow the same logic, but differ in how they are called.
*
* @param world The world
* @param player The player
* @param usedItem The used item
* @return True if the event is cancelled and the callback needs to be cancelled
*/
private boolean impl$throwConstructPreEvent(final Level world, final net.minecraft.world.entity.player.Player player, final ItemStack usedItem) {
if (ShouldFire.CONSTRUCT_ENTITY_EVENT_PRE && !((LevelBridge) world).bridge$isFake()) {
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContextKeys.USED_ITEM, ItemStackUtil.snapshotOf(usedItem));
frame.addContext(EventContextKeys.PROJECTILE_SOURCE, (ProjectileSource) player);
frame.pushCause(player);
final ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(frame.currentCause(), ServerLocation.of((ServerWorld) world, player.getX(), player.getY(), player.getZ()), new Vector3d(0, 0, 0), EntityTypes.FIREWORK_ROCKET.get());
return SpongeCommon.post(event);
}
}
return false;
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class ResultSlotMixin_Inventory method impl$afterTake.
@Inject(method = "onTake", cancellable = true, at = @At("RETURN"))
private void impl$afterTake(final Player thePlayer, final ItemStack stack, final CallbackInfoReturnable<ItemStack> cir) {
if (((LevelBridge) thePlayer.level).bridge$isFake()) {
return;
}
final AbstractContainerMenu container = thePlayer.containerMenu;
final Inventory craftInv = ((Inventory) container).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class));
if (!(craftInv instanceof CraftingInventory)) {
SpongeCommon.logger().warn("Detected crafting without a InventoryCrafting!? Crafting Event will not fire.");
return;
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
transactor.logCrafting(thePlayer, this.impl$craftedStack, (CraftingInventory) craftInv, this.impl$onTakeRecipe);
this.impl$craftedStack = null;
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class EntityMixin_Tracker method tracker$ensureDropEffectCompleted.
@Inject(method = "remove()V", at = @At("RETURN"))
private void tracker$ensureDropEffectCompleted(final CallbackInfo ci) {
final PhaseTracker instance = PhaseTracker.SERVER;
if (!instance.onSidedThread()) {
return;
}
if (((LevelBridge) this.level).bridge$isFake()) {
return;
}
final PhaseContext<@NonNull ?> context = instance.getPhaseContext();
if (!context.doesBlockEventTracking()) {
return;
}
if (this.tracker$dropsTransactor != null) {
this.tracker$dropsTransactor.close();
}
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class EntityMixin_Tracker method tracker$logEntityDropTransactionIfNecessary.
@Inject(method = "spawnAtLocation(Lnet/minecraft/world/item/ItemStack;F)Lnet/minecraft/world/entity/item/ItemEntity;", at = @At("HEAD"))
private void tracker$logEntityDropTransactionIfNecessary(final ItemStack stack, final float offsetY, final CallbackInfoReturnable<ItemEntity> cir) {
final PhaseTracker instance = PhaseTracker.SERVER;
if (!instance.onSidedThread()) {
return;
}
if (((LevelBridge) this.level).bridge$isFake()) {
return;
}
final PhaseContext<@NonNull ?> context = instance.getPhaseContext();
if (!context.doesBlockEventTracking()) {
return;
}
if (this.tracker$dropsTransactor == null) {
this.tracker$dropsTransactor = context.getTransactor().ensureEntityDropTransactionEffect((Entity) (Object) this);
}
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class LivingEntityMixin_Tracker method tracker$wrapOnDeathWithState.
/**
* @author gabizou
* @reason Instead of inlining the onDeath method with the main mixin, we can "toggle"
* the usage of the death state control in the tracker mixin.
*/
@Redirect(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;die(Lnet/minecraft/world/damagesource/DamageSource;)V"))
private void tracker$wrapOnDeathWithState(final LivingEntity thisEntity, final DamageSource cause) {
// Sponge Start - notify the cause tracker
final PhaseTracker instance = PhaseTracker.SERVER;
if (!instance.onSidedThread()) {
return;
}
if (((LevelBridge) this.level).bridge$isFake()) {
return;
}
final PhaseContext<@NonNull ?> context = instance.getPhaseContext();
if (!context.doesBlockEventTracking()) {
return;
}
try (final EffectTransactor ignored = context.getTransactor().ensureEntityDropTransactionEffect((LivingEntity) (Object) this)) {
// Create new EntityDeathTransaction
// Add new EntityDeathEffect
this.shadow$die(cause);
}
// Sponge End
}
Aggregations