use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class SpongeCommand method getChunksInfo.
// --
protected Component getChunksInfo(final ServerWorld serverWorld) {
if (((LevelBridge) serverWorld).bridge$isFake()) {
return Component.text().append(Component.newline(), Component.text(serverWorld.key().asString() + " is a fake world")).build();
}
final ServerLevel serverLevel = (ServerLevel) serverWorld;
final int entitiesToRemove = (int) serverWorld.entities().stream().filter(x -> ((Entity) x).removed).count();
return LinearComponents.linear(this.key("Loaded chunks: "), this.value(serverLevel.getChunkSource().chunkMap.size()), Component.newline(), this.key("Entities: "), this.value(serverWorld.entities().size()), Component.newline(), this.key("Block Entities: "), this.value(serverWorld.blockEntities().size()), Component.newline(), this.key("Removed Entities:"), this.value(entitiesToRemove), Component.newline(), this.key("Removed Block Entities: "), this.value(((LevelBridge) serverLevel).bridge$blockEntitiesToUnload().size()));
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class DamageSourceMixin method onSetExplosionSource.
@Inject(method = "explosion(Lnet/minecraft/world/level/Explosion;)Lnet/minecraft/world/damagesource/DamageSource;", at = @At("HEAD"), cancellable = true)
private static void onSetExplosionSource(@Nullable final Explosion explosion, final CallbackInfoReturnable<net.minecraft.world.damagesource.DamageSource> cir) {
if (explosion != null) {
final Entity entity = ((ExplosionAccessor) explosion).accessor$source();
if (entity != null && !((LevelBridge) ((ExplosionAccessor) explosion).accessor$level()).bridge$isFake()) {
if (explosion.getSourceMob() == null && entity instanceof CreatorTrackedBridge) {
// check creator
final CreatorTrackedBridge creatorBridge = (CreatorTrackedBridge) entity;
creatorBridge.tracker$getCreatorUUID().flatMap(x -> Sponge.server().player(x)).ifPresent(player -> {
final IndirectEntityDamageSource damageSource = new IndirectEntityDamageSource("explosion.player", entity, (Entity) player);
damageSource.setScalesWithDifficulty().setExplosion();
cir.setReturnValue(damageSource);
});
}
}
}
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class AbstractContainerMenuMixin_Inventory method inventory$wrapDoClickWithTransaction.
@Redirect(method = "clicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AbstractContainerMenu;doClick(IILnet/minecraft/world/inventory/ClickType;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/item/ItemStack;"))
private ItemStack inventory$wrapDoClickWithTransaction(final AbstractContainerMenu menu, final int slotId, final int dragType, final ClickType clickType, final Player player) {
if (((LevelBridge) player.level).bridge$isFake()) {
return this.shadow$doClick(slotId, dragType, clickType, player);
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
try (final EffectTransactor ignored = transactor.logClickContainer(menu, slotId, dragType, clickType, player)) {
this.impl$isClicking = true;
return this.shadow$doClick(slotId, dragType, clickType, player);
} finally {
this.impl$isClicking = false;
}
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class LevelChunkMixin method bridge$trackedUUID.
public Optional<UUID> bridge$trackedUUID(final BlockPos pos, final Function<PlayerTracker, Integer> func) {
if (((LevelBridge) this.level).bridge$isFake()) {
return Optional.empty();
}
final int key = Constants.Sponge.blockPosToInt(pos);
final PlayerTracker intTracker = this.impl$trackedIntBlockPositions.get(key);
if (intTracker != null) {
final int ownerIndex = func.apply(intTracker);
return this.impl$getValidatedUUID(key, ownerIndex);
}
final short shortKey = Constants.Sponge.blockPosToShort(pos);
final PlayerTracker shortTracker = this.impl$trackedShortBlockPositions.get(shortKey);
if (shortTracker != null) {
final int ownerIndex = func.apply(shortTracker);
return this.impl$getValidatedUUID(shortKey, ownerIndex);
}
return Optional.empty();
}
use of org.spongepowered.common.bridge.world.level.LevelBridge in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_EntityCollision method entityCollision$allowEntityCollision.
private <T extends Entity> boolean entityCollision$allowEntityCollision(final List<T> entities) {
if (((LevelBridge) this.shadow$getLevel()).bridge$isFake()) {
return true;
}
final PhaseContext<@NonNull ?> phaseContext = PhaseTracker.getInstance().getPhaseContext();
if (!phaseContext.allowsEntityCollisionEvents()) {
// allow explosions
return true;
}
final Object source = phaseContext.getSource();
if (source == null) {
return true;
}
CollisionCapabilityBridge collisionBridge = null;
if (source instanceof LocatableBlock) {
final LocatableBlock locatable = (LocatableBlock) source;
final BlockType blockType = locatable.location().block().type();
collisionBridge = (CollisionCapabilityBridge) blockType;
} else if (source instanceof CollisionCapabilityBridge) {
collisionBridge = (CollisionCapabilityBridge) source;
}
if (collisionBridge == null) {
return true;
}
if (collisionBridge.collision$requiresCollisionsCacheRefresh()) {
collisionBridge.collision$initializeCollisionState(this.shadow$getLevel());
collisionBridge.collision$requiresCollisionsCacheRefresh(false);
}
return !((collisionBridge.collision$getMaxCollisions() >= 0) && (entities.size() >= collisionBridge.collision$getMaxCollisions()));
}
Aggregations