Search in sources :

Example 1 with LevelBridge

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()));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge)

Example 2 with LevelBridge

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);
                });
            }
        }
    }
}
Also used : ExplosionAccessor(org.spongepowered.common.accessor.world.level.ExplosionAccessor) LivingEntity(net.minecraft.world.entity.LivingEntity) Inject(org.spongepowered.asm.mixin.injection.Inject) Supplier(java.util.function.Supplier) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) Mixin(org.spongepowered.asm.mixin.Mixin) DamageSource(net.minecraft.world.damagesource.DamageSource) ResourceKey(org.spongepowered.api.ResourceKey) IndirectEntityDamageSource(net.minecraft.world.damagesource.IndirectEntityDamageSource) Nullable(javax.annotation.Nullable) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) At(org.spongepowered.asm.mixin.injection.At) DamageSourceToTypeProvider(org.spongepowered.common.registry.provider.DamageSourceToTypeProvider) Mutable(org.spongepowered.asm.mixin.Mutable) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Component(net.minecraft.network.chat.Component) DamageType(org.spongepowered.api.event.cause.entity.damage.DamageType) MoreObjects(com.google.common.base.MoreObjects) Sponge(org.spongepowered.api.Sponge) DamageTypes(org.spongepowered.api.event.cause.entity.damage.DamageTypes) ExplosionAccessor(org.spongepowered.common.accessor.world.level.ExplosionAccessor) Final(org.spongepowered.asm.mixin.Final) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) Explosion(net.minecraft.world.level.Explosion) Entity(net.minecraft.world.entity.Entity) MemoizedSupplier(org.spongepowered.common.util.MemoizedSupplier) Shadow(org.spongepowered.asm.mixin.Shadow) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) IndirectEntityDamageSource(net.minecraft.world.damagesource.IndirectEntityDamageSource) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with LevelBridge

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;
    }
}
Also used : LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with LevelBridge

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();
}
Also used : LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) PlayerTracker(org.spongepowered.common.entity.PlayerTracker)

Example 5 with LevelBridge

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()));
}
Also used : LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) BlockType(org.spongepowered.api.block.BlockType) CollisionCapabilityBridge(org.spongepowered.common.bridge.entitycollision.CollisionCapabilityBridge) LocatableBlock(org.spongepowered.api.world.LocatableBlock)

Aggregations

LevelBridge (org.spongepowered.common.bridge.world.level.LevelBridge)20 Inject (org.spongepowered.asm.mixin.injection.Inject)5 Redirect (org.spongepowered.asm.mixin.injection.Redirect)5 Entity (net.minecraft.world.entity.Entity)4 LivingEntity (net.minecraft.world.entity.LivingEntity)3 ItemEntity (net.minecraft.world.entity.item.ItemEntity)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)3 EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)3 ArrayList (java.util.ArrayList)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 ItemStack (net.minecraft.world.item.ItemStack)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)2 ServerWorld (org.spongepowered.api.world.server.ServerWorld)2 CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)2 MoreObjects (com.google.common.base.MoreObjects)1 WeakReference (java.lang.ref.WeakReference)1