Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.asodev.islandutils.modules.cosmetics.CosmeticState;
import net.asodev.islandutils.modules.cosmetics.CosmeticType;
import net.asodev.islandutils.options.IslandOptions;
import net.asodev.islandutils.state.Game;
import net.asodev.islandutils.state.MccIslandState;
import net.asodev.islandutils.util.IslandSoundEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
Expand All @@ -15,7 +16,6 @@
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -35,6 +35,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

import static net.asodev.islandutils.util.Utils.getCustomItemID;


Expand All @@ -59,7 +61,7 @@ private void onInit(AbstractContainerMenu abstractContainerMenu, Inventory inven

@Inject(method = "renderSlot", at = @At("TAIL"))
private void renderSlot(GuiGraphics guiGraphics, Slot slot, CallbackInfo ci) {
if (!MccIslandState.isOnline()) return;
if (!CosmeticState.shouldShowCosmeticPreview()) return;
if (!slot.hasItem()) return;

boolean shouldRender = false;
Expand Down Expand Up @@ -99,6 +101,7 @@ private void render(GuiGraphics guiGraphics, int i, int j, float f, CallbackInfo
CosmeticState.hoveredColor = null;
}

@Unique
private CosmeticType setHovered(ItemStack item) {
CosmeticType type = CosmeticState.getType(item);
if (type == null) return null;
Expand All @@ -110,7 +113,7 @@ private CosmeticType setHovered(ItemStack item) {

@Inject(method = "mouseDragged", at = @At("HEAD"))
private void mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY, CallbackInfoReturnable<Boolean> cir) {
if (!MccIslandState.isOnline()) return;
if (!CosmeticState.shouldShowCosmeticPreview()) return;

CosmeticState.yRot = CosmeticState.yRot - Double.valueOf(deltaX).floatValue();
CosmeticState.xRot = CosmeticState.xRot - Double.valueOf(deltaY).floatValue();
Expand All @@ -128,6 +131,8 @@ private void mouseReleased(double d, double e, int keyCode, CallbackInfoReturnab
@Inject(method = "slotClicked", at = @At("HEAD"))
private void slotClicked(Slot slot, int i, int j, ClickType clickType, CallbackInfo ci) {
if (!MccIslandState.isOnline()) return;
if (!MccIslandState.getGame().isHubGame()) return;

if (slot == null || !slot.hasItem()) return;
ItemStack stack = slot.getItem();
if (CosmeticState.canBeEquipped(stack)) {
Expand All @@ -140,9 +145,9 @@ private void slotClicked(Slot slot, int i, int j, ClickType clickType, CallbackI
}
}

@Unique
private void triggerPreviewClicked(int keyCode) {
if (!MccIslandState.isOnline()) return;
if (!IslandOptions.getCosmetics().isShowPlayerPreview()) return;
if (!CosmeticState.shouldShowCosmeticPreview()) return;
if (hoveredSlot == null || !hoveredSlot.hasItem()) return;
InputConstants.Key previewBind = KeyBindingHelper.getBoundKeyOf(minecraft.options.keyPickItem);
if (keyCode == previewBind.getValue()) {
Expand All @@ -164,10 +169,11 @@ private void setPreview(ItemStack item) {

@Unique
private void setOrNotSet(Cosmetic cosmetic, ResourceLocation itemCMD) {
if (cosmetic.preview == null || itemCMD != getCustomItemID(cosmetic.preview.item))
cosmetic.preview = new CosmeticSlot(hoveredSlot);
else
if (cosmetic.preview != null && Objects.equals(getCustomItemID(cosmetic.preview.item), itemCMD)) {
cosmetic.preview = null;
} else {
cosmetic.preview = new CosmeticSlot(hoveredSlot);
}
this.minecraft.getSoundManager().play(SimpleSoundInstance.forUI(IslandSoundEvents.UI_CLICK_NORMAL, 1f, 1f));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.asodev.islandutils.mixins.cosmetics;

import com.llamalad7.mixinextras.sugar.Local;
import net.asodev.islandutils.modules.cosmetics.CosmeticState;
import net.asodev.islandutils.options.IslandOptions;
import net.asodev.islandutils.state.Game;
import net.asodev.islandutils.state.MccIslandState;
import net.asodev.islandutils.util.ChatUtils;
import net.asodev.islandutils.util.FontUtils;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -47,8 +48,8 @@ public class PreviewTutorialMixin {
)
)
private void injectedTooltipLines(Item.TooltipContext tooltipContext, TooltipDisplay tooltipDisplay, @Nullable Player player, TooltipFlag tooltipFlag, Consumer<Component> consumer, CallbackInfo ci) {
if (!CosmeticState.shouldShowCosmeticPreview()) return;
if (CosmeticState.getType((ItemStack) (Object) this) == null) return;
if (!IslandOptions.getCosmetics().isShowPlayerPreview()) return;
consumer.accept(previewComponent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.asodev.islandutils.modules.cosmetics.CosmeticUI;
import net.asodev.islandutils.options.IslandOptions;
import net.asodev.islandutils.options.categories.CosmeticsOptions;
import net.asodev.islandutils.state.Game;
import net.asodev.islandutils.state.MccIslandState;
import net.asodev.islandutils.util.FontUtils;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -33,10 +34,9 @@ public UIMixin(ChestMenu abstractContainerMenu, Inventory inventory, Component c

@Inject(method = "renderBg", at = @At("TAIL"))
public void renderBg(GuiGraphics guiGraphics, float f, int i, int j, CallbackInfo ci) {
if (!MccIslandState.isOnline()) return;
if (!CosmeticState.shouldShowCosmeticPreview()) return;

CosmeticsOptions options = IslandOptions.getCosmetics();
if (!options.isShowPlayerPreview()) return;
boolean isCosmeticMenu = false;
if (options.isShowOnOnlyCosmeticMenus() && !(isCosmeticMenu = CosmeticState.isCosmeticMenu(this))) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.asodev.islandutils.modules.cosmetics;

import net.asodev.islandutils.options.IslandOptions;
import net.asodev.islandutils.state.MccIslandState;
import net.asodev.islandutils.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
Expand Down Expand Up @@ -82,6 +84,7 @@ public static CosmeticType getType(ItemStack item) {
if (path.endsWith(".icon_empty") || path.endsWith(".icon")) return null;
if (path.contains("hat.") || path.contains("hair.")) return CosmeticType.HAT;
if (path.contains("accessory.")) return CosmeticType.ACCESSORY;
if (path.contains("weapon_skins.")) return CosmeticType.MAIN_HAND;
if (path.startsWith("island_lobby.fishing.rods")) return CosmeticType.MAIN_HAND;
return null;
}
Expand All @@ -99,6 +102,15 @@ public static boolean isCosmeticMenu(AbstractContainerScreen<ChestMenu> screen)
return false;
}

public static boolean shouldShowCosmeticPreview() {
// don't show if we're not on mcci
if (!MccIslandState.isOnline()) return false;
// don't show if we have them disabled
if (!IslandOptions.getCosmetics().isShowPlayerPreview()) return false;
// if we have chosen to NOT show in games and we are in a game, disable. otherwise show!
return IslandOptions.getCosmetics().isShowInGames() || MccIslandState.getGame().isHubGame();
}

public static boolean itemsMatch(ItemStack item, ItemStack compare) {
ItemStack item1 = item != null ? item : ItemStack.EMPTY;
ItemStack item2 = compare != null ? compare : ItemStack.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CosmeticsOptions implements OptionsCategory {
boolean showPlayerPreview = true;
boolean showOnHover = true;
boolean showOnOnlyCosmeticMenus = true;
boolean showInGames = true;

public boolean isShowPlayerPreview() {
return showPlayerPreview;
Expand All @@ -26,6 +27,10 @@ public boolean isShowOnOnlyCosmeticMenus() {
return showOnOnlyCosmeticMenus;
}

public boolean isShowInGames() {
return showInGames;
}

@Override
public ConfigCategory getCategory() {
Option<Boolean> showPreviewOption = Option.<Boolean>createBuilder()
Expand All @@ -43,11 +48,17 @@ public ConfigCategory getCategory() {
.controller(TickBoxControllerBuilder::create)
.binding(defaults.showOnOnlyCosmeticMenus, () -> showOnOnlyCosmeticMenus, value -> this.showOnOnlyCosmeticMenus = value)
.build();
Option<Boolean> showInGamesOption = Option.<Boolean>createBuilder()
.name(Component.translatable("text.autoconfig.islandutils.option.showInGames"))
.controller(TickBoxControllerBuilder::create)
.binding(defaults.showInGames, () -> showInGames, value -> this.showInGames = value)
.build();
return ConfigCategory.createBuilder()
.name(Component.translatable("text.autoconfig.islandutils.category.cosmetics"))
.option(showPreviewOption)
.option(showHoverOption)
.option(showInOnlyCosmeticMenu)
.option(showInGamesOption)
.build();
}
}
17 changes: 12 additions & 5 deletions src/main/java/net/asodev/islandutils/state/Game.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.asodev.islandutils.state;

import com.noxcrew.noxesium.network.clientbound.ClientboundMccServerPacket;
import net.asodev.islandutils.discord.FishingPresenceUpdator;
import net.minecraft.resources.ResourceLocation;

import java.util.NoSuchElementException;
Expand Down Expand Up @@ -51,17 +50,25 @@ public ResourceLocation getMusicLocation() {
public boolean hasTeamChat() {
return hasTeamChat;
}
public boolean isHubGame() {
return this == FISHING || this == HUB;
}

public static ResourceLocation getMusicLocation(String name) {
return ResourceLocation.fromNamespaceAndPath("island", "island.music." + name);
}

public static Game fromPacket(ClientboundMccServerPacket packet) throws NoSuchElementException {
if (packet.serverType().equals("lobby")) {
for (String temperature : FishingPresenceUpdator.temperatures) {
if (packet.subType().startsWith(temperature + "_")) return FISHING;
switch (packet.serverType()) {
case "fishing" -> {
return FISHING;
}
case "dojo" -> {
return PARKOUR_WARRIOR_DOJO;
}
case "lobby" -> {
return HUB;
}
return HUB;
}

for (Game game : values()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/island/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"text.autoconfig.islandutils.option.showPlayerPreview": "Show Cosmetic Previews",
"text.autoconfig.islandutils.option.showOnHover": "Preview cosmetics on hover",
"text.autoconfig.islandutils.option.showOnOnlyCosmeticMenus": "Show cosmetic preview only in Cosmetic Menus",
"text.autoconfig.islandutils.option.showInGames": "Show cosmetic preview in games",

"text.autoconfig.islandutils.category.discord": "Discord Presence",
"text.autoconfig.islandutils.group.presenceDisplayOptions": "Presence Display Options",
Expand Down
Loading