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