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);
}
}
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))));
}
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));
}
}));
}
}
}
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);
}
}
}
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);
}
Aggregations