Search in sources :

Example 1 with VanishableBridge

use of org.spongepowered.common.bridge.data.VanishableBridge in project SpongeCommon by SpongePowered.

the class PlayerListMixin method impl$onlySendAddPlayerForUnvanishedPlayers.

@Redirect(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;send(Lnet/minecraft/network/protocol/Packet;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Ljava/util/List;size()I", remap = false), to = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V")))
private void impl$onlySendAddPlayerForUnvanishedPlayers(ServerGamePacketListenerImpl connection, Packet<?> packet) {
    ClientboundPlayerInfoPacketAccessor playerInfoPacketAccessor = (ClientboundPlayerInfoPacketAccessor) packet;
    // size is always 1
    VanishableBridge p = (VanishableBridge) this.playersByUUID.get(playerInfoPacketAccessor.accessor$entries().get(0).getProfile().getId());
    // Effectively, don't notify new players of vanished players
    if (p.bridge$vanishState().invisible()) {
        return;
    }
    connection.send(packet);
}
Also used : ClientboundPlayerInfoPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor) VanishableBridge(org.spongepowered.common.bridge.data.VanishableBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with VanishableBridge

use of org.spongepowered.common.bridge.data.VanishableBridge in project SpongeCommon by SpongePowered.

the class VanishableData method register.

// @formatter:off
@SuppressWarnings("unchecked")
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(VanishableBridge.class).create(Keys.IS_INVISIBLE).get(VanishableBridge::bridge$isInvisible).set(VanishableBridge::bridge$setInvisible).create(Keys.VANISH).get(bridge -> bridge.bridge$vanishState().invisible()).setAnd((h, v) -> {
        if (h instanceof Entity && ((Entity) h).level.isClientSide) {
            return false;
        }
        h.bridge$vanishState(v ? VanishState.vanished() : VanishState.unvanished());
        return true;
    }).create(Keys.VANISH_IGNORES_COLLISION).get(b -> b.bridge$vanishState().ignoresCollisions()).setAnd((h, v) -> {
        if (h instanceof Entity && ((Entity) h).level.isClientSide) {
            return false;
        }
        if (!h.bridge$vanishState().invisible()) {
            return false;
        }
        h.bridge$vanishState(h.bridge$vanishState().ignoreCollisions(v));
        return true;
    }).create(Keys.VANISH_PREVENTS_TARGETING).get(b -> b.bridge$vanishState().untargetable()).setAnd((h, v) -> {
        if (h instanceof Entity && ((Entity) h).level.isClientSide) {
            return false;
        }
        if (!h.bridge$vanishState().invisible()) {
            return false;
        }
        h.bridge$vanishState(h.bridge$vanishState().untargetable(v));
        return true;
    }).create(Keys.VANISH_STATE).get(VanishableBridge::bridge$vanishState).setAnd((h, v) -> {
        if (h instanceof Entity && ((Entity) h).level.isClientSide) {
            return false;
        }
        h.bridge$vanishState(v);
        return true;
    });
    final ResourceKey dataStoreKey = ResourceKey.sponge("invisibility");
    registrator.spongeDataStore(dataStoreKey, VanishableBridge.class, Keys.IS_INVISIBLE, Keys.VANISH_STATE);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.IS_INVISIBLE, dataStoreKey, Keys.IS_INVISIBLE);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.IS_VANISHED, dataStoreKey, Keys.VANISH_STATE);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.VANISH_UNCOLLIDEABLE, dataStoreKey, Keys.VANISH_IGNORES_COLLISION);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.VANISH_UNTARGETABLE, dataStoreKey, Keys.VANISH_PREVENTS_TARGETING);
}
Also used : VanishState(org.spongepowered.api.effect.VanishState) Keys(org.spongepowered.api.data.Keys) VanishableBridge(org.spongepowered.common.bridge.data.VanishableBridge) Entity(net.minecraft.world.entity.Entity) Constants(org.spongepowered.common.util.Constants) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) ResourceKey(org.spongepowered.api.ResourceKey) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) Entity(net.minecraft.world.entity.Entity) VanishableBridge(org.spongepowered.common.bridge.data.VanishableBridge) ResourceKey(org.spongepowered.api.ResourceKey)

Aggregations

VanishableBridge (org.spongepowered.common.bridge.data.VanishableBridge)2 Entity (net.minecraft.world.entity.Entity)1 ResourceKey (org.spongepowered.api.ResourceKey)1 Keys (org.spongepowered.api.data.Keys)1 VanishState (org.spongepowered.api.effect.VanishState)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 ClientboundPlayerInfoPacketAccessor (org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor)1 SpongeDataManager (org.spongepowered.common.data.SpongeDataManager)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 Constants (org.spongepowered.common.util.Constants)1