Search in sources :

Example 1 with CallbackInfo

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

the class ServerPlayerMixin method impl$handleClientSettings.

@SuppressWarnings({ "ConstantConditions", "UnstableApiUsage" })
@Inject(method = "updateOptions", at = @At("HEAD"))
private void impl$handleClientSettings(final ServerboundClientInformationPacket packet, final CallbackInfo ci) {
    if (!ShouldFire.PLAYER_CHANGE_CLIENT_SETTINGS_EVENT) {
        return;
    }
    final ServerboundClientInformationPacketAccessor $packet = (ServerboundClientInformationPacketAccessor) packet;
    final Locale newLocale = LocaleCache.getLocale($packet.accessor$language());
    final ImmutableSet<SkinPart> skinParts = Sponge.game().registry(RegistryTypes.SKIN_PART).stream().map(part -> (SpongeSkinPart) part).filter(part -> part.test(packet.getModelCustomisation())).collect(ImmutableSet.toImmutableSet());
    final int viewDistance = $packet.accessor$viewDistance();
    // Post before the player values are updated
    try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
        final ChatVisibility visibility = (ChatVisibility) (Object) packet.getChatVisibility();
        final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(frame.currentCause(), visibility, skinParts, newLocale, (ServerPlayer) this, packet.getChatColors(), viewDistance);
        SpongeCommon.post(event);
    }
}
Also used : Locale(java.util.Locale) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PermissionService(org.spongepowered.api.service.permission.PermissionService) PlayerList(net.minecraft.server.players.PlayerList) Team(net.minecraft.world.scores.Team) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) ClientboundPlayerCombatPacket(net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) Living(org.spongepowered.api.entity.living.Living) BossEventBridge(org.spongepowered.common.bridge.world.BossEventBridge) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Set(java.util.Set) InteractionResult(net.minecraft.world.InteractionResult) Locales(org.spongepowered.api.util.locale.Locales) EntityUtil(org.spongepowered.common.entity.EntityUtil) TextComponent(net.minecraft.network.chat.TextComponent) PlatformHooks(org.spongepowered.common.hooks.PlatformHooks) TicketType(net.minecraft.server.level.TicketType) Shadow(org.spongepowered.asm.mixin.Shadow) ItemStack(net.minecraft.world.item.ItemStack) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) EventContextKeys(org.spongepowered.api.event.EventContextKeys) ServerWorld(org.spongepowered.api.world.server.ServerWorld) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) ClientboundContainerSetSlotPacket(net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeSkinPart(org.spongepowered.common.data.type.SpongeSkinPart) ClientboundLevelEventPacket(net.minecraft.network.protocol.game.ClientboundLevelEventPacket) LevelData(net.minecraft.world.level.storage.LevelData) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) ServerboundClientInformationPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundClientInformationPacketAccessor) DataCompoundHolder(org.spongepowered.common.bridge.data.DataCompoundHolder) RotateEntityEvent(org.spongepowered.api.event.entity.RotateEntityEvent) Stats(net.minecraft.stats.Stats) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Opcodes(org.objectweb.asm.Opcodes) Identity(net.kyori.adventure.identity.Identity) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) Scoreboard(org.spongepowered.api.scoreboard.Scoreboard) ShouldFire(org.spongepowered.common.event.ShouldFire) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) DataUtil(org.spongepowered.common.data.DataUtil) Cause(org.spongepowered.api.event.Cause) Channel(io.netty.channel.Channel) ChunkPos(net.minecraft.world.level.ChunkPos) VecHelper(org.spongepowered.common.util.VecHelper) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) InteractionHand(net.minecraft.world.InteractionHand) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) ClientboundGameEventPacket(net.minecraft.network.protocol.game.ClientboundGameEventPacket) Either(com.mojang.datafixers.util.Either) LivingEntity(net.minecraft.world.entity.LivingEntity) Score(net.minecraft.world.scores.Score) PlayerBridge(org.spongepowered.common.bridge.world.entity.player.PlayerBridge) SpongeCommonEventFactory(org.spongepowered.common.event.SpongeCommonEventFactory) ClientboundBossEventPacket(net.minecraft.network.protocol.game.ClientboundBossEventPacket) LocaleCache(org.spongepowered.common.util.LocaleCache) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) PortalLogic(org.spongepowered.common.world.portal.PortalLogic) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) PlayerChangeClientSettingsEvent(org.spongepowered.api.event.entity.living.player.PlayerChangeClientSettingsEvent) ServerGamePacketListenerImplBridge(org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) ChatFormatting(net.minecraft.ChatFormatting) ServerboundClientInformationPacket(net.minecraft.network.protocol.game.ServerboundClientInformationPacket) Locale(java.util.Locale) At(org.spongepowered.asm.mixin.injection.At) Stat(net.minecraft.stats.Stat) BiomeManager(net.minecraft.world.level.biome.BiomeManager) ImmutableSet(com.google.common.collect.ImmutableSet) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) KickPlayerEvent(org.spongepowered.api.event.entity.living.player.KickPlayerEvent) GameRules(net.minecraft.world.level.GameRules) Sponge(org.spongepowered.api.Sponge) ChatType(net.minecraft.network.chat.ChatType) UUID(java.util.UUID) Final(org.spongepowered.asm.mixin.Final) ClientboundUpdateMobEffectPacket(net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket) Player(net.minecraft.world.entity.player.Player) Tristate(org.spongepowered.api.util.Tristate) HoverEvent(net.minecraft.network.chat.HoverEvent) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) PlayerMixin(org.spongepowered.common.mixin.core.world.entity.player.PlayerMixin) Optional(java.util.Optional) Level(net.minecraft.world.level.Level) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ClientboundPlayerAbilitiesPacket(net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket) Unit(net.minecraft.util.Unit) ResultSlot(net.minecraft.world.inventory.ResultSlot) ServerLevel(net.minecraft.server.level.ServerLevel) HashSet(java.util.HashSet) ChangeEntityWorldEvent(org.spongepowered.api.event.entity.ChangeEntityWorldEvent) Component(net.kyori.adventure.text.Component) DamageSource(net.minecraft.world.damagesource.DamageSource) ObjectiveCriteria(net.minecraft.world.scores.criteria.ObjectiveCriteria) SkinPart(org.spongepowered.api.data.type.SkinPart) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Audiences(org.spongepowered.api.adventure.Audiences) PortalInfo(net.minecraft.world.level.portal.PortalInfo) SpongeCommon(org.spongepowered.common.SpongeCommon) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) MovementTypes(org.spongepowered.api.event.cause.entity.MovementTypes) ServerPlayerGameMode(net.minecraft.server.level.ServerPlayerGameMode) Entity(net.minecraft.world.entity.Entity) SubjectBridge(org.spongepowered.common.bridge.permissions.SubjectBridge) ClientboundRespawnPacket(net.minecraft.network.protocol.game.ClientboundRespawnPacket) Vector3d(org.spongepowered.math.vector.Vector3d) ConnectionAccessor(org.spongepowered.common.accessor.network.ConnectionAccessor) Slice(org.spongepowered.asm.mixin.injection.Slice) PlayerOwnBorderListener(org.spongepowered.common.world.border.PlayerOwnBorderListener) PlayerChangeClientSettingsEvent(org.spongepowered.api.event.entity.living.player.PlayerChangeClientSettingsEvent) ChatVisibility(org.spongepowered.api.entity.living.player.chat.ChatVisibility) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerboundClientInformationPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundClientInformationPacketAccessor) SpongeSkinPart(org.spongepowered.common.data.type.SpongeSkinPart) SkinPart(org.spongepowered.api.data.type.SkinPart) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with CallbackInfo

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

the class TitleScreenMixin_Vanilla method vanilla$addPluginsButton.

@Inject(method = "init", at = @At("TAIL"))
private void vanilla$addPluginsButton(final CallbackInfo ci) {
    final Optional<AbstractWidget> realmsButton = this.buttons.stream().filter(b -> b.getMessage().equals(new TranslatableComponent("menu.online"))).findFirst();
    realmsButton.ifPresent(b -> {
        b.setWidth(98);
        b.x = this.width / 2 + 2;
    });
    // Plugins Button
    this.addButton(new Button(this.width / 2 - 100, realmsButton.map(b -> b.y).orElse(0), 98, 20, new TextComponent("Plugins"), b -> this.minecraft.setScreen(new PluginScreen(this))));
}
Also used : Component(net.minecraft.network.chat.Component) Inject(org.spongepowered.asm.mixin.injection.Inject) Screen(net.minecraft.client.gui.screens.Screen) PluginScreen(org.spongepowered.vanilla.client.gui.screen.PluginScreen) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) TextComponent(net.minecraft.network.chat.TextComponent) Mixin(org.spongepowered.asm.mixin.Mixin) Optional(java.util.Optional) AbstractWidget(net.minecraft.client.gui.components.AbstractWidget) TitleScreen(net.minecraft.client.gui.screens.TitleScreen) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) At(org.spongepowered.asm.mixin.injection.At) Button(net.minecraft.client.gui.components.Button) TextComponent(net.minecraft.network.chat.TextComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) PluginScreen(org.spongepowered.vanilla.client.gui.screen.PluginScreen) Button(net.minecraft.client.gui.components.Button) AbstractWidget(net.minecraft.client.gui.components.AbstractWidget) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with CallbackInfo

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

the class ServerGamePacketListenerImplMixin_Vanilla method vanilla$onProcessChatMessage.

@Inject(method = "handleChat(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void vanilla$onProcessChatMessage(String var1, CallbackInfo ci, net.minecraft.network.chat.Component component) {
    ChatFormatter.formatChatComponent((net.minecraft.network.chat.TranslatableComponent) component);
    final ServerPlayer player = (ServerPlayer) this.player;
    final PlayerChatFormatter chatFormatter = player.chatFormatter();
    final TextComponent rawMessage = Component.text(var1);
    try (CauseStackManager.StackFrame frame = PhaseTracker.SERVER.pushCauseFrame()) {
        frame.pushCause(this.player);
        final Audience audience = (Audience) this.server;
        final PlayerChatEvent event = SpongeEventFactory.createPlayerChatEvent(frame.currentCause(), audience, Optional.of(audience), chatFormatter, Optional.of(chatFormatter), rawMessage, rawMessage);
        if (SpongeCommon.post(event)) {
            ci.cancel();
        } else {
            event.chatFormatter().ifPresent(formatter -> event.audience().map(SpongeAdventure::unpackAudiences).ifPresent(targets -> {
                for (Audience target : targets) {
                    formatter.format(player, target, event.message(), event.originalMessage()).ifPresent(formattedMessage -> target.sendMessage(player, formattedMessage));
                }
            }));
        }
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) Inventory(org.spongepowered.api.item.inventory.Inventory) NonNull(org.checkerframework.checker.nullness.qual.NonNull) RecipeBookMenu(net.minecraft.world.inventory.RecipeBookMenu) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) PlayerList(net.minecraft.server.players.PlayerList) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) Component(net.kyori.adventure.text.Component) ServerboundCustomPayloadPacket(net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket) CauseStackManager(org.spongepowered.api.event.CauseStackManager) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) ServerGamePacketListener(net.minecraft.network.protocol.game.ServerGamePacketListener) LocalCapture(org.spongepowered.asm.mixin.injection.callback.LocalCapture) At(org.spongepowered.asm.mixin.injection.At) TextComponent(net.kyori.adventure.text.TextComponent) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) EngineConnection(org.spongepowered.api.network.EngineConnection) Sponge(org.spongepowered.api.Sponge) PlayerChatEvent(org.spongepowered.api.event.message.PlayerChatEvent) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) Group(org.spongepowered.asm.mixin.injection.Group) ChatType(net.minecraft.network.chat.ChatType) SpongeCommon(org.spongepowered.common.SpongeCommon) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) UUID(java.util.UUID) Final(org.spongepowered.asm.mixin.Final) QueryTypes(org.spongepowered.api.item.inventory.query.QueryTypes) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) PlayerChatFormatter(org.spongepowered.api.entity.living.player.PlayerChatFormatter) Audience(net.kyori.adventure.audience.Audience) Recipe(net.minecraft.world.item.crafting.Recipe) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) ServerboundCustomPayloadPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundCustomPayloadPacketAccessor) ChatFormatter(org.spongepowered.vanilla.chat.ChatFormatter) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) PlayerChatEvent(org.spongepowered.api.event.message.PlayerChatEvent) Audience(net.kyori.adventure.audience.Audience) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PlayerChatFormatter(org.spongepowered.api.entity.living.player.PlayerChatFormatter) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with CallbackInfo

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

the class MixinInventoryPlayer method onConstructed.

@Inject(method = "<init>*", at = @At("RETURN"), remap = false)
private void onConstructed(EntityPlayer playerIn, CallbackInfo ci) {
    // Find offhand slot
    for (NonNullList<ItemStack> inventory : this.allInventories) {
        if (inventory == this.offHandInventory) {
            break;
        }
        this.offhandIndex += inventory.size();
    }
    // Set Carrier if we got a real Player
    if (playerIn instanceof EntityPlayerMP) {
        this.carrier = (Player) playerIn;
        this.inventory = new IInventoryFabric((IInventory) this);
        Class clazz = this.getClass();
        if (clazz == InventoryPlayer.class) {
            // Build Player Lens
            // We only care about Server inventories
            this.slots = new SlotCollection.Builder().add(this.mainInventory.size()).add(this.offHandInventory.size()).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.BOOTS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.LEGGINGS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.CHESTPLATE)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.HEADWEAR)).add(this.armorInventory.size() - 4, EquipmentSlotAdapter.class).add(this.getSizeInventory() - this.mainInventory.size() - this.offHandInventory.size() - this.armorInventory.size()).build();
            this.lens = new PlayerInventoryLens(this, this.slots);
        } else if (this.getSizeInventory() != 0) {
            // Fallback OrderedLens when not 0 sized inventory
            this.slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
            this.lens = new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, slots);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) InventoryEventArgs(org.spongepowered.common.item.inventory.observer.InventoryEventArgs) Inject(org.spongepowered.asm.mixin.injection.Inject) EnumHand(net.minecraft.util.EnumHand) EquipmentInventory(org.spongepowered.api.item.inventory.equipment.EquipmentInventory) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Overwrite(org.spongepowered.asm.mixin.Overwrite) MainPlayerInventoryAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.MainPlayerInventoryAdapter) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) IMixinInventoryPlayer(org.spongepowered.common.interfaces.entity.player.IMixinInventoryPlayer) Mixin(org.spongepowered.asm.mixin.Mixin) NonNullList(net.minecraft.util.NonNullList) At(org.spongepowered.asm.mixin.injection.At) Fabric(org.spongepowered.common.item.inventory.lens.Fabric) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) Redirect(org.spongepowered.asm.mixin.injection.Redirect) EquipmentInventoryAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.EquipmentInventoryAdapter) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(org.spongepowered.api.item.inventory.Slot) Final(org.spongepowered.asm.mixin.Final) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) HotbarAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.HotbarAdapter) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) Player(org.spongepowered.api.entity.living.player.Player) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) SlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.SlotAdapter) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) SPacketHeldItemChange(net.minecraft.network.play.server.SPacketHeldItemChange) MainPlayerInventory(org.spongepowered.api.item.inventory.entity.MainPlayerInventory) IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with CallbackInfo

use of org.spongepowered.asm.mixin.injection.callback.CallbackInfo in project Almura by AlmuraDev.

the class MixinGuiOptions method onInitGui.

// Add our button to the list and move the Done button lower
@Inject(method = "initGui", at = @At("RETURN"))
public void onInitGui(CallbackInfo ci) {
    final GuiButton almuraButton = new GuiButton(301, this.width / 2 - 155, this.height / 6 + 144 - 6, 150, 20, "Almura");
    this.buttonList.add(almuraButton);
    /*
         * Button IDs                     Buttons
         * 108                          = Difficulty
         * 109                          = Lock
         * REALMS_NOTIFICATIONS ordinal = Realms notification
         * 200                          = Done
         */
    // Move every button that isn't any of the above listed up by 12
    this.buttonList.stream().filter(btn -> !(btn instanceof GuiOptionSlider) && btn.id != 200 && btn.id != 108 && btn.id != 109 && btn.id != GameSettings.Options.REALMS_NOTIFICATIONS.getOrdinal()).forEach(btn -> btn.y = btn.y - 12);
}
Also used : CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) GuiScreen(net.minecraft.client.gui.GuiScreen) SimpleOptionsMenu(com.almuradev.almura.feature.menu.SimpleOptionsMenu) GuiOptions(net.minecraft.client.gui.GuiOptions) GuiButton(net.minecraft.client.gui.GuiButton) Mixin(org.spongepowered.asm.mixin.Mixin) Inject(org.spongepowered.asm.mixin.injection.Inject) GameSettings(net.minecraft.client.settings.GameSettings) IOException(java.io.IOException) GuiOptionSlider(net.minecraft.client.gui.GuiOptionSlider) At(org.spongepowered.asm.mixin.injection.At) GuiOptionSlider(net.minecraft.client.gui.GuiOptionSlider) GuiButton(net.minecraft.client.gui.GuiButton) 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