Search in sources :

Example 6 with CallbackInfo

use of org.spongepowered.asm.mixin.injection.callback.CallbackInfo in project SpongeCommon by SpongePowered.

the class ServerLoginPacketListenerImplMixin_Vanilla method impl$onTick.

@Inject(method = "tick", at = @At("HEAD"))
private void impl$onTick(final CallbackInfo ci) {
    if (this.state == ServerLoginPacketListenerImpl.State.NEGOTIATING) {
        final ServerSideConnection connection = (ServerSideConnection) this;
        if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_NOT_STARTED) {
            this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_CLIENT_TYPE;
            ((SpongeChannelManager) Sponge.channelManager()).requestClientType(connection).thenAccept(result -> {
                this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS;
            });
        } else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS) {
            ((SpongeChannelManager) Sponge.channelManager()).sendLoginChannelRegistry(connection).thenAccept(result -> {
                final Cause cause = Cause.of(EventContext.empty(), this);
                final ServerSideConnectionEvent.Handshake event = SpongeEventFactory.createServerSideConnectionEventHandshake(cause, connection);
                SpongeCommon.post(event);
                this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_PLUGIN_DATA;
            });
        } else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_PLUGIN_DATA) {
            final TransactionStore store = ConnectionUtil.getTransactionStore(connection);
            if (store.isEmpty()) {
                this.state = ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT;
            }
        }
    }
}
Also used : ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) ServerLoginPacketListener(net.minecraft.network.protocol.login.ServerLoginPacketListener) ServerLoginPacketListenerImpl(net.minecraft.server.network.ServerLoginPacketListenerImpl) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) TransactionStore(org.spongepowered.common.network.channel.TransactionStore) ServerboundCustomQueryPacket(net.minecraft.network.protocol.login.ServerboundCustomQueryPacket) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) EngineConnection(org.spongepowered.api.network.EngineConnection) Sponge(org.spongepowered.api.Sponge) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) SpongeCommon(org.spongepowered.common.SpongeCommon) Final(org.spongepowered.asm.mixin.Final) EventContext(org.spongepowered.api.event.EventContext) Cause(org.spongepowered.api.event.Cause) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) ConnectionUtil(org.spongepowered.common.network.channel.ConnectionUtil) ServerboundHelloPacket(net.minecraft.network.protocol.login.ServerboundHelloPacket) Shadow(org.spongepowered.asm.mixin.Shadow) At(org.spongepowered.asm.mixin.injection.At) TransactionStore(org.spongepowered.common.network.channel.TransactionStore) Cause(org.spongepowered.api.event.Cause) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with CallbackInfo

use of org.spongepowered.asm.mixin.injection.callback.CallbackInfo in project SpongeCommon by SpongePowered.

the class AdvancementMixin method impl$setUpSpongeFields.

@SuppressWarnings({ "ConstantConditions" })
@Inject(method = "<init>", at = @At("RETURN"))
private void impl$setUpSpongeFields(ResourceLocation location, @Nullable Advancement parent, @Nullable DisplayInfo displayInfo, AdvancementRewards rewards, Map<String, Criterion> criteria, String[][] requirements, CallbackInfo ci) {
    // Don't do anything on the client, unless we're performing registry initialization
    if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
        return;
    }
    if (displayInfo != null) {
        ((DisplayInfoBridge) displayInfo).bridge$setAdvancement((org.spongepowered.api.advancement.Advancement) this);
    }
    this.impl$toastText = this.impl$generateToastText();
    final Map<String, DefaultedAdvancementCriterion> criteriaMap = new LinkedHashMap<>();
    final Map<String, List<DefaultedAdvancementCriterion>> scoreCriteria = new HashMap<>();
    for (Map.Entry<String, Criterion> entry : criteria.entrySet()) {
        final CriterionBridge mixinCriterion = (CriterionBridge) entry.getValue();
        final String groupName = mixinCriterion.bridge$getScoreCriterionName();
        if (groupName != null) {
            scoreCriteria.computeIfAbsent(groupName, k -> new ArrayList<>()).add((DefaultedAdvancementCriterion) entry.getValue());
        }
        criteriaMap.put(entry.getKey(), (DefaultedAdvancementCriterion) mixinCriterion);
        mixinCriterion.bridge$setName(entry.getKey());
    }
    for (Map.Entry<String, List<DefaultedAdvancementCriterion>> groupEntry : scoreCriteria.entrySet()) {
        criteriaMap.put(groupEntry.getKey(), new SpongeScoreCriterion(groupEntry.getKey(), groupEntry.getValue()));
        groupEntry.getValue().forEach(c -> criteriaMap.remove(c.name()));
    }
    final Set<AdvancementCriterion> andCriteria = new HashSet<>();
    for (final String[] array : requirements) {
        final Set<AdvancementCriterion> orCriteria = new HashSet<>();
        for (final String name : array) {
            DefaultedAdvancementCriterion criterion = criteriaMap.get(name);
            if (criterion == null && criteria.get(name) != null) {
                // internal removed by scoreCriterion
                criterion = criteriaMap.get(((CriterionBridge) criteria.get(name)).bridge$getScoreCriterionName());
            }
            orCriteria.add(criterion);
        }
        andCriteria.add(OrCriterion.of(orCriteria));
    }
    this.impl$criterion = AndCriterion.of(andCriteria);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Inject(org.spongepowered.asm.mixin.injection.Inject) Criterion(net.minecraft.advancements.Criterion) HashMap(java.util.HashMap) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) DisplayInfoBridge(org.spongepowered.common.bridge.advancements.DisplayInfoBridge) ArrayList(java.util.ArrayList) FrameType(net.minecraft.advancements.FrameType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ImmutableList(com.google.common.collect.ImmutableList) DisplayInfo(net.minecraft.advancements.DisplayInfo) Mixin(org.spongepowered.asm.mixin.Mixin) Component(net.kyori.adventure.text.Component) Map(java.util.Map) AdvancementBridge(org.spongepowered.common.bridge.advancements.AdvancementBridge) Nullable(javax.annotation.Nullable) At(org.spongepowered.asm.mixin.injection.At) AdvancementRewards(net.minecraft.advancements.AdvancementRewards) Mutable(org.spongepowered.asm.mixin.Mutable) Advancement(net.minecraft.advancements.Advancement) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) Set(java.util.Set) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Final(org.spongepowered.asm.mixin.Final) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) PlatformHooks(org.spongepowered.common.hooks.PlatformHooks) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DisplayInfoBridge(org.spongepowered.common.bridge.advancements.DisplayInfoBridge) LinkedHashMap(java.util.LinkedHashMap) Criterion(net.minecraft.advancements.Criterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) HashSet(java.util.HashSet) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Mixin (org.spongepowered.asm.mixin.Mixin)7 At (org.spongepowered.asm.mixin.injection.At)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 CallbackInfo (org.spongepowered.asm.mixin.injection.callback.CallbackInfo)7 Optional (java.util.Optional)5 Final (org.spongepowered.asm.mixin.Final)5 Shadow (org.spongepowered.asm.mixin.Shadow)5 Component (net.kyori.adventure.text.Component)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 UUID (java.util.UUID)2 ChatType (net.minecraft.network.chat.ChatType)2 TextComponent (net.minecraft.network.chat.TextComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)2 PlayerList (net.minecraft.server.players.PlayerList)2 Sponge (org.spongepowered.api.Sponge)2