Search in sources :

Example 26 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class UseItemPacketState method handleBlockChangeWithUser.

@Override
public void handleBlockChangeWithUser(@Nullable BlockChange blockChange, Transaction<BlockSnapshot> transaction, BasicPacketContext context) {
    Player player = context.getSpongePlayer();
    BlockPos pos = ((IMixinLocation) (Object) transaction.getFinal().getLocation().get()).getBlockPos();
    IMixinChunk spongeChunk = (IMixinChunk) EntityUtil.getMinecraftWorld(player).getChunkFromBlockCoords(pos);
    if (blockChange == BlockChange.PLACE) {
        spongeChunk.addTrackedBlockPosition((Block) transaction.getFinal().getState().getType(), pos, player, PlayerTracker.Type.OWNER);
    }
    spongeChunk.addTrackedBlockPosition((Block) transaction.getFinal().getState().getType(), pos, player, PlayerTracker.Type.NOTIFIER);
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos)

Example 27 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class BlockEventTickPhaseState method associateNeighborStateNotifier.

@Override
public void associateNeighborStateNotifier(BlockEventTickContext context, @Nullable BlockPos sourcePos, Block block, BlockPos notifyPos, WorldServer minecraftWorld, PlayerTracker.Type notifier) {
    if (sourcePos == null) {
        LocatableBlock locatableBlock = context.getSource(LocatableBlock.class).orElse(null);
        if (locatableBlock == null) {
            TileEntity tileEntity = context.getSource(TileEntity.class).orElseThrow(TrackingUtil.throwWithContext("Expected to be ticking over at a TileEntity!", context));
            locatableBlock = tileEntity.getLocatableBlock();
        }
        sourcePos = ((IMixinLocation) (Object) locatableBlock.getLocation()).getBlockPos();
    }
    final User user = context.getNotifier().orElse(TrackingUtil.getNotifierOrOwnerFromBlock(minecraftWorld, sourcePos));
    if (user != null) {
        final IMixinChunk mixinChunk = (IMixinChunk) minecraftWorld.getChunkFromBlockCoords(notifyPos);
        mixinChunk.addTrackedBlockPosition(block, notifyPos, user, PlayerTracker.Type.NOTIFIER);
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) LocatableBlock(org.spongepowered.api.world.LocatableBlock)

Example 28 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class LocationBasedTickPhaseState method handleBlockChangeWithUser.

@Override
public void handleBlockChangeWithUser(@Nullable BlockChange blockChange, Transaction<BlockSnapshot> snapshotTransaction, T context) {
    final Location<World> location = getLocatableBlockSourceFromContext(context).getLocation();
    final Block block = (Block) snapshotTransaction.getOriginal().getState().getType();
    final Location<World> changedLocation = snapshotTransaction.getOriginal().getLocation().get();
    final BlockPos changedBlockPos = ((IMixinLocation) (Object) changedLocation).getBlockPos();
    final IMixinChunk changedMixinChunk = (IMixinChunk) ((WorldServer) changedLocation.getExtent()).getChunkFromBlockCoords(changedBlockPos);
    final User user = context.getNotifier().orElse(TrackingUtil.getNotifierOrOwnerFromBlock(location));
    if (user != null) {
        changedMixinChunk.addTrackedBlockPosition(block, changedBlockPos, user, PlayerTracker.Type.NOTIFIER);
    }
}
Also used : User(org.spongepowered.api.entity.living.player.User) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(org.spongepowered.api.world.World)

Example 29 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class LocationBasedTickPhaseState method associateNeighborStateNotifier.

@Override
public void associateNeighborStateNotifier(T context, @Nullable BlockPos sourcePos, Block block, BlockPos notifyPos, WorldServer minecraftWorld, PlayerTracker.Type notifier) {
    if (sourcePos == null) {
        LocatableBlock locatableBlock = this.getLocatableBlockSourceFromContext(context);
        sourcePos = ((IMixinLocation) (Object) locatableBlock.getLocation()).getBlockPos();
    }
    User user = context.getNotifier().orElse(TrackingUtil.getNotifierOrOwnerFromBlock(minecraftWorld, sourcePos));
    if (user != null) {
        final IMixinChunk mixinChunk = (IMixinChunk) minecraftWorld.getChunkFromBlockCoords(notifyPos);
        mixinChunk.addTrackedBlockPosition(block, notifyPos, user, PlayerTracker.Type.NOTIFIER);
    }
}
Also used : User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) LocatableBlock(org.spongepowered.api.world.LocatableBlock)

Example 30 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinChunk method onLoadReturn.

@Inject(method = "onLoad", at = @At("RETURN"))
public void onLoadReturn(CallbackInfo ci) {
    for (Direction direction : CARDINAL_DIRECTIONS) {
        Vector3i neighborPosition = this.getPosition().add(direction.asBlockOffset());
        IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) this.world.getChunkProvider();
        net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.getLoadedChunkWithoutMarkingActive(neighborPosition.getX(), neighborPosition.getZ());
        if (neighbor != null) {
            int neighborIndex = directionToIndex(direction);
            int oppositeNeighborIndex = directionToIndex(direction.getOpposite());
            this.setNeighborChunk(neighborIndex, neighbor);
            ((IMixinChunk) neighbor).setNeighborChunk(oppositeNeighborIndex, (net.minecraft.world.chunk.Chunk) (Object) this);
        }
    }
    SpongeImpl.postEvent(SpongeEventFactory.createLoadChunkEvent(Sponge.getCauseStackManager().getCurrentCause(), (Chunk) this));
    if (!this.world.isRemote) {
        SpongeHooks.logChunkLoad(this.world, this.chunkPos);
    }
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Vector3i(com.flowpowered.math.vector.Vector3i) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(org.spongepowered.api.world.Chunk) Direction(org.spongepowered.api.util.Direction) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)49 Chunk (net.minecraft.world.chunk.Chunk)21 BlockPos (net.minecraft.util.math.BlockPos)18 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)12 User (org.spongepowered.api.entity.living.player.User)11 Inject (org.spongepowered.asm.mixin.injection.Inject)8 IBlockState (net.minecraft.block.state.IBlockState)7 World (org.spongepowered.api.world.World)7 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)7 LocatableBlock (org.spongepowered.api.world.LocatableBlock)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 Block (net.minecraft.block.Block)5 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)5 Direction (org.spongepowered.api.util.Direction)5 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 PhaseData (org.spongepowered.common.event.tracking.PhaseData)4 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)4 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)4 Vector3d (com.flowpowered.math.vector.Vector3d)3