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);
}
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);
}
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();
}
}
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;
}
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");
}
Aggregations