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