Search in sources :

Example 61 with ResourceKey

use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.

the class SpongeChannelManager method handleLoginResponsePayload.

private void handleLoginResponsePayload(final EngineConnection connection, final int transactionId, @Nullable final ChannelBuf payload) {
    // Sponge magic... Allows normal packets to be send during the login phase from the client to server
    if (transactionId == Constants.Channels.LOGIN_PAYLOAD_IGNORED_TRANSACTION_ID) {
        return;
    }
    if (transactionId == Constants.Channels.LOGIN_PAYLOAD_TRANSACTION_ID) {
        if (payload != null) {
            final ResourceKey channelKey = ResourceKey.resolve(payload.readString());
            this.handlePlayPayload(connection, channelKey, payload);
        }
        return;
    }
    // Normal handling
    final TransactionStore transactionStore = ConnectionUtil.getTransactionStore(connection);
    final TransactionStore.Entry entry = transactionStore.remove(transactionId);
    if (entry == null) {
        return;
    }
    if (entry.getData() instanceof ClientTypeSyncFuture) {
        if (payload != null) {
            this.handleClientType(connection, payload);
        }
        ((ClientTypeSyncFuture) entry.getData()).future.complete(null);
        return;
    }
    if (entry.getData() instanceof ChannelRegistrySyncFuture) {
        if (payload != null) {
            this.handleChannelRegistry(connection, payload);
        }
        ((ChannelRegistrySyncFuture) entry.getData()).future.complete(null);
        return;
    }
    final TransactionResult result = payload == null ? TransactionResult.failure(new NoResponseException()) : TransactionResult.success(payload);
    entry.getChannel().handleTransactionResponse(connection, entry.getData(), result);
}
Also used : NoResponseException(org.spongepowered.api.network.channel.NoResponseException) ResourceKey(org.spongepowered.api.ResourceKey)

Example 62 with ResourceKey

use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.

the class SpongeFluidStack method toContainer.

@Override
@NonNull
public DataContainer toContainer() {
    final ResourceKey resourceKey = Sponge.game().registry(RegistryTypes.FLUID_TYPE).valueKey(this.fluidType);
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, this.contentVersion()).set(Constants.Fluids.FLUID_TYPE, resourceKey).set(Constants.Fluids.FLUID_VOLUME, this.volume);
    if (this.extraData != null) {
        container.set(Constants.Sponge.UNSAFE_NBT, this.extraData);
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) ResourceKey(org.spongepowered.api.ResourceKey) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 63 with ResourceKey

use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.

the class SpongeFluidStackSnapshot method toContainer.

@Override
@NonNull
public DataContainer toContainer() {
    final ResourceKey resourceKey = Sponge.game().registry(RegistryTypes.FLUID_TYPE).valueKey(this.fluidType);
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, this.contentVersion()).set(Constants.Fluids.FLUID_TYPE, resourceKey).set(Constants.Fluids.FLUID_VOLUME, this.volume);
    if (this.extraData != null) {
        container.set(Constants.Sponge.UNSAFE_NBT, this.extraData);
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) ResourceKey(org.spongepowered.api.ResourceKey) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 64 with ResourceKey

use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.

the class EntitySelectorParserMixin_API method addNotEntityType.

@Override
public Selector.@NonNull Builder addNotEntityType(@NonNull final EntityType<@NonNull ?> type) {
    final ResourceKey key = (ResourceKey) (Object) Registry.ENTITY_TYPE.getKey((net.minecraft.world.entity.EntityType<?>) type);
    this.api$handle("type", "!" + key.asString());
    return this;
}
Also used : ResourceKey(org.spongepowered.api.ResourceKey)

Example 65 with ResourceKey

use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.

the class EntitySelectorParserMixin_API method addNotGameMode.

@Override
public Selector.@NonNull Builder addNotGameMode(@NonNull final GameMode mode) {
    final ResourceKey key = Sponge.game().registry(RegistryTypes.GAME_MODE).valueKey(mode);
    this.api$handle("gamemode", key.value(), Tristate.TRUE);
    return this;
}
Also used : ResourceKey(org.spongepowered.api.ResourceKey)

Aggregations

ResourceKey (org.spongepowered.api.ResourceKey)71 Sponge (org.spongepowered.api.Sponge)13 List (java.util.List)11 Map (java.util.Map)11 DataContainer (org.spongepowered.api.data.persistence.DataContainer)11 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 CompoundTag (net.minecraft.nbt.CompoundTag)8 NonNull (org.checkerframework.checker.nullness.qual.NonNull)8 RegistryTypes (org.spongepowered.api.registry.RegistryTypes)8 IOException (java.io.IOException)7 Component (net.kyori.adventure.text.Component)7 Nullable (org.checkerframework.checker.nullness.qual.Nullable)7 Keys (org.spongepowered.api.data.Keys)7 Constants (org.spongepowered.common.util.Constants)7 ImmutableList (com.google.common.collect.ImmutableList)6 ServerLevel (net.minecraft.server.level.ServerLevel)6 DataQuery (org.spongepowered.api.data.persistence.DataQuery)6