use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeForge by SpongePowered.
the class MixinBlockLog 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) {
if (SpongeCommonEventFactory.callChangeBlockEventPre((IMixinWorldServer) worldIn, pos).isCancelled()) {
return;
}
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState currentState = phaseTracker.getCurrentState();
final boolean isBlockAlready = currentState.getPhase() != TrackingPhases.BLOCK;
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();
BlockPhase.State.BLOCK_DECAY.createPhaseContext().source(locatable).buildAndSwitch();
}
block.beginLeavesDecay(state, worldIn, pos);
if (isBlockAlready && !isWorldGen) {
phaseTracker.completePhase(BlockPhase.State.BLOCK_DECAY);
}
} else {
block.beginLeavesDecay(state, worldIn, pos);
}
}
Aggregations