Search in sources :

Example 6 with LevelChunkBridge

use of org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge in project SpongeCommon by SpongePowered.

the class PacketState method associateNeighborStateNotifier.

@Override
public void associateNeighborStateNotifier(final P unwindingContext, final BlockPos sourcePos, final Block block, final BlockPos notifyPos, final ServerLevel minecraftWorld, final PlayerTracker.Type notifier) {
    final Player player = unwindingContext.getSpongePlayer();
    final LevelChunk chunk = minecraftWorld.getChunkAt(notifyPos);
    ((LevelChunkBridge) chunk).bridge$setBlockNotifier(notifyPos, player.uniqueId());
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)

Example 7 with LevelChunkBridge

use of org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge in project SpongeCommon by SpongePowered.

the class HopperBlockEntityMixin method impl$trackNotifierWhenTransferring.

@Inject(method = "addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/entity/item/ItemEntity;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;getItem()Lnet/minecraft/world/item/ItemStack;"))
private static void impl$trackNotifierWhenTransferring(final Container inventory, final ItemEntity entityItem, final CallbackInfoReturnable<Boolean> callbackInfo) {
    if (entityItem instanceof CreatorTrackedBridge) {
        ((CreatorTrackedBridge) entityItem).tracker$getCreatorUUID().ifPresent(creator -> {
            if (inventory instanceof ActiveChunkReferantBridge && inventory instanceof BlockEntity) {
                final BlockEntity te = (BlockEntity) inventory;
                final LevelChunkBridge spongeChunk = ((ActiveChunkReferantBridge) inventory).bridge$getActiveChunk();
                spongeChunk.bridge$addTrackedBlockPosition(te.getBlockState().getBlock(), te.getBlockPos(), creator, PlayerTracker.Type.NOTIFIER);
            }
        });
    }
}
Also used : CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) ActiveChunkReferantBridge(org.spongepowered.common.bridge.world.level.chunk.ActiveChunkReferantBridge) HopperBlockEntity(net.minecraft.world.level.block.entity.HopperBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with LevelChunkBridge

use of org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge in project SpongeCommon by SpongePowered.

the class DispenserBlockMixin_Tracker method tracker$createContextOnDispensing.

@Inject(method = "dispenseFrom", at = @At(value = "HEAD"))
private void tracker$createContextOnDispensing(final ServerLevel worldIn, final BlockPos pos, final CallbackInfo ci) {
    final net.minecraft.world.level.block.state.BlockState state = worldIn.getBlockState(pos);
    final SpongeBlockSnapshot spongeBlockSnapshot = ((TrackedWorldBridge) worldIn).bridge$createSnapshot(state, pos, BlockChangeFlags.ALL);
    final LevelChunkBridge mixinChunk = (LevelChunkBridge) worldIn.getChunkAt(pos);
    this.tracker$context = BlockPhase.State.DISPENSE.createPhaseContext(PhaseTracker.SERVER).source(spongeBlockSnapshot).creator(() -> mixinChunk.bridge$getBlockCreatorUUID(pos)).notifier(() -> mixinChunk.bridge$getBlockNotifierUUID(pos)).buildAndSwitch();
}
Also used : SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) TrackedWorldBridge(org.spongepowered.common.bridge.world.TrackedWorldBridge) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with LevelChunkBridge

use of org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge in project SpongeCommon by SpongePowered.

the class LocationBasedTickPhaseState method associateNeighborStateNotifier.

@Override
public void associateNeighborStateNotifier(final T context, @Nullable final BlockPos sourcePos, final Block block, final BlockPos notifyPos, final ServerLevel minecraftWorld, final PlayerTracker.Type notifier) {
    // If we do not have a notifier at this point then there is no need to attempt to retrieve one from the chunk
    context.applyNotifierIfAvailable(user -> {
        final LevelChunkBridge mixinChunk = (LevelChunkBridge) minecraftWorld.getChunkAt(notifyPos);
        mixinChunk.bridge$addTrackedBlockPosition(block, notifyPos, user, PlayerTracker.Type.NOTIFIER);
    });
}
Also used : LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)

Example 10 with LevelChunkBridge

use of org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge in project SpongeCommon by SpongePowered.

the class ChunkMapMixin method impl$onSetUnloaded.

@Redirect(method = "lambda$scheduleUnload$10", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;unload(Lnet/minecraft/world/level/chunk/LevelChunk;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;save(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")))
private void impl$onSetUnloaded(final ServerLevel level, final LevelChunk chunk) {
    final Vector3i chunkPos = new Vector3i(chunk.getPos().x, 0, chunk.getPos().z);
    if (ShouldFire.CHUNK_EVENT_UNLOAD_PRE) {
        final ChunkEvent.Unload event = SpongeEventFactory.createChunkEventUnloadPre(PhaseTracker.getInstance().currentCause(), (WorldChunk) chunk, chunkPos, (ResourceKey) (Object) this.level.dimension().location());
        SpongeCommon.post(event);
    }
    level.unload(chunk);
    for (final Direction dir : Constants.Chunk.CARDINAL_DIRECTIONS) {
        final Vector3i neighborPos = chunkPos.add(dir.asBlockOffset());
        final ChunkAccess neighbor = this.level.getChunk(neighborPos.x(), neighborPos.z(), ChunkStatus.EMPTY, false);
        if (neighbor instanceof LevelChunk) {
            final int index = DirectionUtil.directionToIndex(dir);
            final int oppositeIndex = DirectionUtil.directionToIndex(dir.opposite());
            ((LevelChunkBridge) chunk).bridge$setNeighborChunk(index, null);
            ((LevelChunkBridge) neighbor).bridge$setNeighborChunk(oppositeIndex, null);
        }
    }
    if (ShouldFire.CHUNK_EVENT_UNLOAD_POST) {
        final ChunkEvent.Unload event = SpongeEventFactory.createChunkEventUnloadPost(PhaseTracker.getInstance().currentCause(), chunkPos, (ResourceKey) (Object) this.level.dimension().location());
        SpongeCommon.post(event);
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) Vector3i(org.spongepowered.math.vector.Vector3i) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) ChunkEvent(org.spongepowered.api.event.world.chunk.ChunkEvent) Direction(org.spongepowered.api.util.Direction) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

LevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)23 BlockPos (net.minecraft.core.BlockPos)9 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)8 CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)6 UUID (java.util.UUID)5 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)5 CompoundTag (net.minecraft.nbt.CompoundTag)4 ServerLocation (org.spongepowered.api.world.server.ServerLocation)4 ActiveChunkReferantBridge (org.spongepowered.common.bridge.world.level.chunk.ActiveChunkReferantBridge)4 TrackedLevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.TrackedLevelChunkBridge)4 ListTag (net.minecraft.nbt.ListTag)3 Block (net.minecraft.world.level.block.Block)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 Direction (org.spongepowered.api.util.Direction)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 Timing (co.aikar.timings.Timing)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2