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