Search in sources :

Example 21 with LevelChunkBridge

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

the class IPhaseState method appendNotifierPreBlockTick.

/**
 * Appends additional information from the block's position in the world to provide notifier/owner
 * information. Overridden in world generation states to reduce chunk lookup costs and since
 * world generation does not track owners/notifiers.
 *  @param world The world reference
 * @param pos The position being updated
 * @param context The context
 * @param phaseContext the block tick context being entered
 */
default void appendNotifierPreBlockTick(final ServerLevel world, final BlockPos pos, final C context, final LocationBasedTickContext<@NonNull ?> phaseContext) {
    final LevelChunk chunk = world.getChunkAt(pos);
    final LevelChunkBridge mixinChunk = (LevelChunkBridge) chunk;
    if (chunk != null && !chunk.isEmpty()) {
        mixinChunk.bridge$getBlockCreatorUUID(pos).ifPresent(phaseContext::creator);
        mixinChunk.bridge$getBlockNotifierUUID(pos).ifPresent(phaseContext::notifier);
    }
}
Also used : LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)

Example 22 with LevelChunkBridge

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

the class UseItemPacketState method postBlockTransactionApplication.

@Override
public void postBlockTransactionApplication(final BasicPacketContext context, final BlockChange blockChange, final BlockTransactionReceipt transaction) {
    final ServerPlayer player = context.getSpongePlayer();
    final BlockPos pos = VecHelper.toBlockPos(transaction.finalBlock().position());
    final LevelChunkBridge spongeChunk = (LevelChunkBridge) ((ServerLevel) player.world()).getChunkAt(pos);
    if (blockChange == BlockChange.PLACE) {
        spongeChunk.bridge$addTrackedBlockPosition((Block) transaction.finalBlock().state().type(), pos, player.uniqueId(), PlayerTracker.Type.CREATOR);
    }
    spongeChunk.bridge$addTrackedBlockPosition((Block) transaction.finalBlock().state().type(), pos, player.uniqueId(), PlayerTracker.Type.NOTIFIER);
}
Also used : ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) BlockPos(net.minecraft.core.BlockPos) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)

Example 23 with LevelChunkBridge

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

the class ServerLevelMixin_Tracker method bridge$createSnapshot.

@Override
public SpongeBlockSnapshot bridge$createSnapshot(final net.minecraft.world.level.block.state.BlockState state, final BlockPos pos, final BlockChangeFlag updateFlag) {
    final SpongeBlockSnapshot.BuilderImpl builder = SpongeBlockSnapshot.BuilderImpl.pooled();
    builder.reset();
    builder.blockState(state).world((ServerLevel) (Object) this).position(VecHelper.toVector3i(pos));
    final LevelChunk chunk = this.shadow$getChunkAt(pos);
    if (chunk == null) {
        return builder.flag(updateFlag).build();
    }
    final Optional<UUID> creator = ((LevelChunkBridge) chunk).bridge$getBlockCreatorUUID(pos);
    final Optional<UUID> notifier = ((LevelChunkBridge) chunk).bridge$getBlockNotifierUUID(pos);
    creator.ifPresent(builder::creator);
    notifier.ifPresent(builder::notifier);
    final boolean hasTileEntity = ((BlockStateBridge) state).bridge$hasTileEntity();
    final net.minecraft.world.level.block.entity.BlockEntity tileEntity = chunk.getBlockEntity(pos, LevelChunk.EntityCreationType.CHECK);
    if (hasTileEntity || tileEntity != null) {
        // We MUST only check to see if a TE exists to avoid creating a new one.
        if (tileEntity != null) {
            // TODO - custom data.
            final CompoundTag nbt = new CompoundTag();
            // Some mods like OpenComputers assert if attempting to save robot while moving
            try {
                tileEntity.save(nbt);
                builder.addUnsafeCompound(nbt);
            } catch (final Throwable t) {
            // ignore
            }
        }
    }
    builder.flag(updateFlag);
    return builder.build();
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) TrackedLevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.TrackedLevelChunkBridge) UUID(java.util.UUID) CompoundTag(net.minecraft.nbt.CompoundTag) BlockStateBridge(org.spongepowered.common.bridge.world.level.block.state.BlockStateBridge)

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