Search in sources :

Example 21 with IPhaseState

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

the class MixinWorldServer method onCallEntityRidingUpdate.

@Override
public void onCallEntityRidingUpdate(net.minecraft.entity.Entity entity) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final IPhaseState state = phaseTracker.getCurrentState();
    if (state.alreadyCapturingEntityTicks()) {
        entity.updateRidden();
        return;
    }
    TrackingUtil.tickRidingEntity(entity);
    updateRotation(entity);
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState)

Example 22 with IPhaseState

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

the class MixinWorldServer method updateTileEntity.

// separated from onUpdateEntities for TileEntityActivation mixin
private void updateTileEntity(ITickable tile) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final IPhaseState state = phaseTracker.getCurrentState();
    if (state.alreadyCapturingTileTicks()) {
        tile.update();
        return;
    }
    TrackingUtil.tickTileEntity(this, tile);
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState)

Example 23 with IPhaseState

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

the class MixinWorldServer method getBlockState.

/**
 * @author gabizou - August 4th, 2016
 * @author blood - May 11th, 2017 - Forces chunk requests if TE is ticking.
 * @reason Rewrites the check to be inlined to {@link IMixinBlockPos}.
 *
 * @param pos The position
 * @return The block state at the desired position
 */
@Override
public IBlockState getBlockState(BlockPos pos) {
    // if (this.isOutsideBuildHeight(pos)) // Vanilla
    if (((IMixinBlockPos) pos).isInvalidYPosition()) {
        // Sponge end
        return Blocks.AIR.getDefaultState();
    } else {
        // ExtraUtilities 2 expects to get the proper chunk while mining or it gets stuck in infinite loop
        // TODO add TE config to disable/enable chunk loads
        final boolean forceChunkRequests = this.mixinChunkProviderServer.getForceChunkRequests();
        final PhaseTracker phaseTracker = PhaseTracker.getInstance();
        final IPhaseState currentState = phaseTracker.getCurrentState();
        if (currentState == TickPhase.Tick.TILE_ENTITY) {
            ((IMixinChunkProviderServer) this.getChunkProvider()).setForceChunkRequests(true);
        }
        net.minecraft.world.chunk.Chunk chunk = this.getChunkFromBlockCoords(pos);
        this.mixinChunkProviderServer.setForceChunkRequests(forceChunkRequests);
        return chunk.getBlockState(pos);
    }
}
Also used : IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 24 with IPhaseState

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

the class MixinWorldServer method spawnEntity.

@Override
public boolean spawnEntity(Entity entity) {
    checkNotNull(entity, "The entity cannot be null!");
    if (!PhaseTracker.validateEntitySpawn(this, entity)) {
        return true;
    }
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final IPhaseState state = phaseTracker.getCurrentState();
    if (!state.alreadyCapturingEntitySpawns()) {
        try (final BasicPluginContext context = PluginPhase.State.CUSTOM_SPAWN.createPhaseContext().addCaptures().buildAndSwitch()) {
            phaseTracker.spawnEntityWithCause(this, entity);
            return true;
        }
    }
    return phaseTracker.spawnEntityWithCause(this, entity);
}
Also used : BasicPluginContext(org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState)

Example 25 with IPhaseState

use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeForge by SpongePowered.

the class MixinBlockLeaves method onBreakBlock.

@Redirect(method = "breakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;beginLeavesDecay(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V", remap = false))
public void onBreakBlock(Block block, IBlockState state, net.minecraft.world.World worldIn, BlockPos pos) {
    if (!worldIn.isRemote) {
        final PhaseTracker phaseTracker = PhaseTracker.getInstance();
        final IPhaseState currentState = phaseTracker.getCurrentState();
        final boolean isBlockAlready = currentState.getPhase() != TrackingPhases.BLOCK;
        @Nullable PhaseContext<?> blockDecay = null;
        final boolean isWorldGen = currentState.isWorldGeneration();
        if (isBlockAlready && !isWorldGen) {
            final LocatableBlock locatable = LocatableBlock.builder().location(new Location<World>((World) worldIn, pos.getX(), pos.getY(), pos.getZ())).state((BlockState) state).build();
            blockDecay = BlockPhase.State.BLOCK_DECAY.createPhaseContext().source(locatable);
        }
        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
            PhaseContext<?> context = blockDecay != null ? blockDecay.buildAndSwitch() : null) {
            frame.addContext(EventContextKeys.LEAVES_DECAY, (World) worldIn);
            if (SpongeCommonEventFactory.callChangeBlockEventPre((IMixinWorldServer) worldIn, pos).isCancelled()) {
                return;
            }
            block.beginLeavesDecay(state, worldIn, pos);
        }
    } else {
        block.beginLeavesDecay(state, worldIn, pos);
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) CauseStackManager(org.spongepowered.api.event.CauseStackManager) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(org.spongepowered.api.world.World) Nullable(javax.annotation.Nullable) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)26 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)20 PhaseData (org.spongepowered.common.event.tracking.PhaseData)10 Redirect (org.spongepowered.asm.mixin.injection.Redirect)7 IBlockState (net.minecraft.block.state.IBlockState)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 BlockPos (net.minecraft.util.math.BlockPos)4 LocatableBlock (org.spongepowered.api.world.LocatableBlock)4 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)4 EntityItem (net.minecraft.entity.item.EntityItem)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 World (org.spongepowered.api.world.World)3 ArrayList (java.util.ArrayList)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Chunk (net.minecraft.world.chunk.Chunk)2 BlockState (org.spongepowered.api.block.BlockState)2 Entity (org.spongepowered.api.entity.Entity)2 Player (org.spongepowered.api.entity.living.player.Player)2 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)2