Search in sources :

Example 26 with PhaseTracker

use of org.spongepowered.common.event.tracking.PhaseTracker in project SpongeCommon by SpongePowered.

the class BlockMixin_Tracker method tracker$captureBlockProposedToBeSpawningDrops.

@Inject(method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V", at = @At("HEAD"))
private static void tracker$captureBlockProposedToBeSpawningDrops(final BlockState state, final Level worldIn, final BlockPos pos, @Nullable final BlockEntity tileEntity, final Entity entity, final ItemStack itemStack, final CallbackInfo ci) {
    final PhaseTracker server = PhaseTracker.SERVER;
    if (server.getSidedThread() != Thread.currentThread()) {
        return;
    }
    final PhaseContext<@NonNull ?> context = server.getPhaseContext();
    BlockMixin_Tracker.tracker$effectTransactorForDrops = context.getTransactor().logBlockDrops(worldIn, pos, state, tileEntity);
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 27 with PhaseTracker

use of org.spongepowered.common.event.tracking.PhaseTracker in project SpongeCommon by SpongePowered.

the class BlockMixin_Tracker method tracker$closeEffectIfCapturing.

@Inject(method = { "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V", "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V" }, at = @At("TAIL"))
private static void tracker$closeEffectIfCapturing(final CallbackInfo ci) {
    final PhaseTracker server = PhaseTracker.SERVER;
    if (server.getSidedThread() != Thread.currentThread()) {
        return;
    }
    final PhaseContext<@NonNull ?> context = server.getPhaseContext();
    context.getTransactor().completeBlockDrops(BlockMixin_Tracker.tracker$effectTransactorForDrops);
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 28 with PhaseTracker

use of org.spongepowered.common.event.tracking.PhaseTracker in project SpongeCommon by SpongePowered.

the class LivingEntityMixin_Tracker method tracker$enterDeathPhase.

/**
 * @author i509VCB
 * @author gabizou
 *
 * @reason We can enter in to the entity drops transaction here which will
 * successfully batch the side effects (this is effectively a singular side
 * effect/transaction instead of a pipeline) to perform some things around
 * the entity's death. This successfully records the transactions associated
 * with this entity entering into the death state.
 */
@Redirect(method = "baseTick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;tickDeath()V"))
private void tracker$enterDeathPhase(final LivingEntity livingEntity) {
    final PhaseTracker instance = PhaseTracker.SERVER;
    if (!instance.onSidedThread()) {
        this.shadow$tickDeath();
        return;
    }
    if (((LevelBridge) this.level).bridge$isFake()) {
        this.shadow$tickDeath();
        return;
    }
    final PhaseContext<@NonNull ?> context = instance.getPhaseContext();
    if (!context.doesBlockEventTracking()) {
        this.shadow$tickDeath();
        return;
    }
    try (final EffectTransactor ignored = context.getTransactor().ensureEntityDropTransactionEffect((LivingEntity) (Object) this)) {
        this.shadow$tickDeath();
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 29 with PhaseTracker

use of org.spongepowered.common.event.tracking.PhaseTracker in project SpongeCommon by SpongePowered.

the class MixinNetHandlerPlayServer method onProcessRightClickBlock.

@Redirect(method = "processTryUseItemOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerInteractionManager;processRightClickBlock(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/EnumHand;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;FFF)Lnet/minecraft/util/EnumActionResult;"))
public EnumActionResult onProcessRightClickBlock(PlayerInteractionManager interactionManager, EntityPlayer player, net.minecraft.world.World worldIn, @Nullable ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ) {
    EnumActionResult actionResult = interactionManager.processRightClickBlock(this.player, worldIn, stack, hand, pos, facing, hitX, hitY, hitZ);
    // since the client will send the server a CPacketTryUseItem right after this packet is done processing.
    if (actionResult != EnumActionResult.SUCCESS) {
        // If a plugin or mod has changed the item, avoid restoring
        if (!SpongeCommonEventFactory.playerInteractItemChanged) {
            final PhaseTracker phaseTracker = PhaseTracker.getInstance();
            final PhaseData peek = phaseTracker.getCurrentPhaseData();
            final ItemStack itemStack = ItemStackUtil.toNative(((PacketContext<?>) peek.context).getItemUsed());
            // cancelling item usage (e.g. eating food) that occurs while targeting a block
            if (!ItemStack.areItemStacksEqual(itemStack, player.getHeldItem(hand)) || SpongeCommonEventFactory.interactBlockEventCancelled) {
                PacketPhaseUtil.handlePlayerSlotRestore((EntityPlayerMP) player, itemStack, hand);
            }
        }
    }
    SpongeCommonEventFactory.playerInteractItemChanged = false;
    SpongeCommonEventFactory.interactBlockEventCancelled = false;
    return actionResult;
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) ItemStack(net.minecraft.item.ItemStack) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 30 with PhaseTracker

use of org.spongepowered.common.event.tracking.PhaseTracker in project SpongeCommon by SpongePowered.

the class MixinDedicatedServer method isBlockProtected.

/**
 * @author zml - March 9th, 2016
 * @author blood - July 7th, 2016 - Add cause tracker handling for throwing pre change block checks
 * @author gabizou - July 7th, 2016 - Update for 1.10's cause tracking changes
 *
 * @reason Change spawn protection to take advantage of Sponge permissions. Rather than affecting only the default world like vanilla, this
 * will apply to any world. Additionally, fire a spawn protection event
 */
@Overwrite
@Override
public boolean isBlockProtected(net.minecraft.world.World worldIn, BlockPos pos, EntityPlayer playerIn) {
    // Mods such as ComputerCraft and Thaumcraft check this method before attempting to set a blockstate.
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final PhaseData peek = phaseTracker.getCurrentPhaseData();
    final IPhaseState phaseState = peek.state;
    if (phaseState == null || !phaseState.isInteraction()) {
        // TODO BLOCK_PROTECTED flag
        if (SpongeCommonEventFactory.callChangeBlockEventPre((IMixinWorldServer) worldIn, pos, playerIn).isCancelled()) {
            return true;
        }
    }
    BlockPos spawnPoint = worldIn.getSpawnPoint();
    int protectionRadius = getSpawnProtectionSize();
    return protectionRadius > 0 && Math.max(Math.abs(pos.getX() - spawnPoint.getX()), Math.abs(pos.getZ() - spawnPoint.getZ())) <= protectionRadius && !((Player) playerIn).hasPermission("minecraft.spawn-protection.override");
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)67 PhaseData (org.spongepowered.common.event.tracking.PhaseData)22 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)20 BlockPos (net.minecraft.util.math.BlockPos)15 CauseStackManager (org.spongepowered.api.event.CauseStackManager)15 World (org.spongepowered.api.world.World)12 Redirect (org.spongepowered.asm.mixin.injection.Redirect)12 IBlockState (net.minecraft.block.state.IBlockState)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 User (org.spongepowered.api.entity.living.player.User)11 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)10 Inject (org.spongepowered.asm.mixin.injection.Inject)10 ArrayList (java.util.ArrayList)8 Overwrite (org.spongepowered.asm.mixin.Overwrite)8 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)8 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 BlockState (org.spongepowered.api.block.BlockState)6 LocatableBlock (org.spongepowered.api.world.LocatableBlock)6 Location (org.spongepowered.api.world.Location)6 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)6