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