diff --git a/gradle.properties b/gradle.properties index 6a66b48..8cd053a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Mod Properties -mod_version = 2.4.3 +mod_version = 2.4.4 maven_group = com.bvengo archives_base_name = simpleshulkerpreview @@ -11,13 +11,12 @@ archives_base_name = simpleshulkerpreview ## https://maven.shedaniel.me/me/shedaniel/cloth/cloth-config-fabric/ ## https://maven.terraformersmc.com/com/terraformersmc/modmenu -cloth_version=14.0.125 -modmenu_version=10.0.0-beta.1 +cloth_version=15.0.127 +modmenu_version=11.0.1 +minecraft_version=1.21 +yarn_mappings=1.21+build.1 +loader_version=0.15.11 -minecraft_version=1.20.5 -yarn_mappings=1.20.5+build.1 -loader_version=0.15.10 - -#Fabric api -fabric_version=0.97.6+1.20.5 \ No newline at end of file +# Fabric API +fabric_version=0.100.1+1.21 \ No newline at end of file diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/SimpleShulkerPreviewMod.java b/src/main/java/com/bvengo/simpleshulkerpreview/SimpleShulkerPreviewMod.java index f9108a2..d4db4af 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/SimpleShulkerPreviewMod.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/SimpleShulkerPreviewMod.java @@ -16,13 +16,12 @@ public class SimpleShulkerPreviewMod implements ClientModInitializer { public static final String MOD_ID = "simpleshulkerpreview"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static ConfigOptions CONFIGS; @Override public void onInitializeClient() { LOGGER.info("{} loading...", LOGGER.getName()); - - AutoConfig.register(ConfigOptions.class, GsonConfigSerializer::new); - + CONFIGS = AutoConfig.register(ConfigOptions.class, GsonConfigSerializer::new).getConfig(); LOGGER.info("{} loaded.", LOGGER.getName()); } } diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/container/ContainerManager.java b/src/main/java/com/bvengo/simpleshulkerpreview/container/ContainerManager.java index bd8292b..e4b8e99 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/container/ContainerManager.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/container/ContainerManager.java @@ -1,10 +1,9 @@ package com.bvengo.simpleshulkerpreview.container; -import com.bvengo.simpleshulkerpreview.config.ConfigOptions; +import com.bvengo.simpleshulkerpreview.SimpleShulkerPreviewMod; import com.bvengo.simpleshulkerpreview.config.CustomNameOption; -import me.shedaniel.autoconfig.AutoConfig; import net.minecraft.block.entity.ShulkerBoxBlockEntity; import net.minecraft.component.ComponentMap; import net.minecraft.component.DataComponentTypes; @@ -14,8 +13,6 @@ import net.minecraft.item.Items; public class ContainerManager { - private final static ConfigOptions config = AutoConfig.getConfigHolder(ConfigOptions.class).getConfig(); - private ItemStack containerStack; private ComponentMap containerComponents; private String containerId; @@ -40,7 +37,7 @@ public ItemStack getDisplayStack() { // Use item from custom name (if necessary) ItemStack displayStack = ItemStackManager.getItemFromCustomName(containerStack); - if(displayStack != null || config.customName == CustomNameOption.ALWAYS) { + if(displayStack != null || SimpleShulkerPreviewMod.CONFIGS.customName == CustomNameOption.ALWAYS) { return displayStack; } @@ -72,8 +69,6 @@ public int getStackSize() { /** * Returns the ratio full that a container is. - * @param stack A container's NbtCompound - * @param config The current config options for SimpleShulkerPreview * @return A float between 0 and 1 indicating how full the container is */ public float getCapacity() { @@ -149,10 +144,10 @@ private void setContainerSupported() { isContainerSupported = true; return; case BUNDLE: - isContainerSupported = config.supportBundles; + isContainerSupported = SimpleShulkerPreviewMod.CONFIGS.supportBundles; return; case OTHER: - isContainerSupported = config.supportOtherContainers; + isContainerSupported = SimpleShulkerPreviewMod.CONFIGS.supportOtherContainers; return; default: isContainerSupported = false; diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/container/ItemStackManager.java b/src/main/java/com/bvengo/simpleshulkerpreview/container/ItemStackManager.java index 28c31c6..0d5007c 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/container/ItemStackManager.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/container/ItemStackManager.java @@ -5,10 +5,9 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import com.bvengo.simpleshulkerpreview.config.ConfigOptions; +import com.bvengo.simpleshulkerpreview.SimpleShulkerPreviewMod; import com.bvengo.simpleshulkerpreview.config.CustomNameOption; -import me.shedaniel.autoconfig.AutoConfig; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.ProfileComponent; import net.minecraft.item.Item; @@ -19,8 +18,6 @@ import net.minecraft.util.Identifier; public class ItemStackManager { - private final static ConfigOptions config = AutoConfig.getConfigHolder(ConfigOptions.class).getConfig(); - private static class ItemStackGrouper { public final ItemStack itemStack; public String itemString; @@ -42,7 +39,7 @@ private void setItemString() { } // Group enchantments - if (config.groupEnchantment && itemStack.hasEnchantments()) { + if (SimpleShulkerPreviewMod.CONFIGS.groupEnchantment && itemStack.hasEnchantments()) { itemString += ".enchanted"; } } @@ -72,9 +69,9 @@ private static Map groupItemStacks(Iterable itemIterable) { - int itemThreshold = config.stackSizeOptions.minStackSize * config.stackSizeOptions.minStackCount; + int itemThreshold = SimpleShulkerPreviewMod.CONFIGS.stackSizeOptions.minStackSize * SimpleShulkerPreviewMod.CONFIGS.stackSizeOptions.minStackCount; - switch (config.displayIcon) { + switch (SimpleShulkerPreviewMod.CONFIGS.displayIcon) { case FIRST: return StreamSupport.stream(itemIterable.spliterator(), false) .filter(itemStack -> itemStack.getCount() >= itemThreshold) @@ -117,7 +114,7 @@ public static ItemStack getDisplayStackFromIterable(Iterable itemIter } public static ItemStack getItemFromCustomName(ItemStack itemStack) { - if(config.customName == CustomNameOption.NEVER) return null; + if(SimpleShulkerPreviewMod.CONFIGS.customName == CustomNameOption.NEVER) return null; Text customName = itemStack.getComponents().get(DataComponentTypes.CUSTOM_NAME); if(customName == null) return null; diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/mixin/DrawContextMixin.java b/src/main/java/com/bvengo/simpleshulkerpreview/mixin/DrawContextMixin.java index 140c16c..e754cad 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/mixin/DrawContextMixin.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/mixin/DrawContextMixin.java @@ -1,12 +1,11 @@ package com.bvengo.simpleshulkerpreview.mixin; +import com.bvengo.simpleshulkerpreview.SimpleShulkerPreviewMod; import com.bvengo.simpleshulkerpreview.access.DrawContextAccess; -import com.bvengo.simpleshulkerpreview.config.ConfigOptions; import com.bvengo.simpleshulkerpreview.container.ContainerManager; import com.bvengo.simpleshulkerpreview.container.ContainerType; import com.bvengo.simpleshulkerpreview.positioners.CapacityBarRenderer; import com.bvengo.simpleshulkerpreview.positioners.IconRenderer; -import me.shedaniel.autoconfig.AutoConfig; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.item.ItemStack; @@ -32,20 +31,23 @@ public abstract class DrawContextMixin implements DrawContextAccess { method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V") private void renderShulkerItemOverlay(TextRenderer renderer, ItemStack stack, int x, int y, @Nullable String countLabel, CallbackInfo info) { - ConfigOptions config = AutoConfig.getConfigHolder(ConfigOptions.class).getConfig(); + if(SimpleShulkerPreviewMod.CONFIGS.disableMod) { + return; + } + ContainerManager containerParser = new ContainerManager(stack); ItemStack displayStack = containerParser.getDisplayStack(); if(displayStack == null) return; - iconRenderer = new IconRenderer(config, containerParser, displayStack, x, y); + iconRenderer = new IconRenderer(containerParser, displayStack, x, y); iconRenderer.renderOptional((DrawContext)(Object)this); // Display itemBar for containers. Ignore bundles - they already have this feature boolean isBundle = containerParser.getContainerType().equals(ContainerType.BUNDLE); - if(config.showCapacity && !isBundle) { - CapacityBarRenderer capacityBarRenderer = new CapacityBarRenderer(config, containerParser, stack, x, y); + if(SimpleShulkerPreviewMod.CONFIGS.showCapacity && !isBundle) { + CapacityBarRenderer capacityBarRenderer = new CapacityBarRenderer(containerParser, stack, x, y); capacityBarRenderer.renderOptional((DrawContext)(Object)this); } } @@ -53,6 +55,10 @@ private void renderShulkerItemOverlay(TextRenderer renderer, ItemStack stack, in @ModifyArgs(method = "drawItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;IIII)V", at = @At(value = "INVOKE", target = "net/minecraft/client/util/math/MatrixStack.translate(FFF)V")) private void injectedTranslateXYZ(Args args) { + if(SimpleShulkerPreviewMod.CONFIGS.disableMod) { + return; + } + if(adjustSize) { args.set(0, (float)args.get(0) + iconRenderer.xOffset); args.set(1, (float)args.get(1) + iconRenderer.yOffset); @@ -63,6 +69,10 @@ private void injectedTranslateXYZ(Args args) { @ModifyArgs(method = "drawItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;IIII)V", at = @At(value = "INVOKE", target = "net/minecraft/client/util/math/MatrixStack.scale(FFF)V")) private void injectedScale(Args args) { + if(SimpleShulkerPreviewMod.CONFIGS.disableMod) { + return; + } + if(adjustSize) { args.set(0, iconRenderer.scale); args.set(1, -iconRenderer.scale); diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/positioners/CapacityBarRenderer.java b/src/main/java/com/bvengo/simpleshulkerpreview/positioners/CapacityBarRenderer.java index 4c74942..f737c41 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/positioners/CapacityBarRenderer.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/positioners/CapacityBarRenderer.java @@ -1,7 +1,6 @@ package com.bvengo.simpleshulkerpreview.positioners; import com.bvengo.simpleshulkerpreview.SimpleShulkerPreviewMod; -import com.bvengo.simpleshulkerpreview.config.ConfigOptions; import com.bvengo.simpleshulkerpreview.container.ContainerManager; import net.minecraft.client.gui.DrawContext; @@ -25,60 +24,60 @@ public class CapacityBarRenderer extends OverlayRenderer { public int xCapacityEnd; public int yCapacityEnd; - public CapacityBarRenderer(ConfigOptions config, ContainerManager containerParser, ItemStack stack, int x, int y) { - super(config, stack, x, y); + public CapacityBarRenderer(ContainerManager containerParser, ItemStack stack, int x, int y) { + super(stack, x, y); this.capacity = containerParser.getCapacity(); } protected boolean canDisplay() { return ( - (!config.capacityBarOptions.hideWhenEmpty || capacity > 0.0f) && - (!config.capacityBarOptions.hideWhenFull || capacity < 1.0f) + (!SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.hideWhenEmpty || capacity > 0.0f) && + (!SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.hideWhenFull || capacity < 1.0f) ); } protected void calculatePositions() { - int step = (int)(config.capacityBarOptions.length * capacity); - int shadowHeight = config.capacityBarOptions.displayShadow ? 1 : 0; + int step = (int)(SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.length * capacity); + int shadowHeight = SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.displayShadow ? 1 : 0; - xBackgroundStart = stackX + config.capacityBarOptions.translateX; - yBackgroundStart = stackY + config.capacityBarOptions.translateY; + xBackgroundStart = stackX + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.translateX; + yBackgroundStart = stackY + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.translateY; - switch(config.capacityBarOptions.direction) { + switch(SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.direction) { case LEFT_TO_RIGHT -> { - xBackgroundEnd = xBackgroundStart + config.capacityBarOptions.length; - yBackgroundEnd = yBackgroundStart + config.capacityBarOptions.width + shadowHeight; + xBackgroundEnd = xBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.length; + yBackgroundEnd = yBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.width + shadowHeight; xCapacityStart = xBackgroundStart; yCapacityStart = yBackgroundStart; xCapacityEnd = xBackgroundStart + step; - yCapacityEnd = yCapacityStart + config.capacityBarOptions.width; + yCapacityEnd = yCapacityStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.width; } case RIGHT_TO_LEFT -> { - xBackgroundEnd = xBackgroundStart + config.capacityBarOptions.length; - yBackgroundEnd = yBackgroundStart + config.capacityBarOptions.width + shadowHeight; + xBackgroundEnd = xBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.length; + yBackgroundEnd = yBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.width + shadowHeight; xCapacityStart = xBackgroundEnd - step; yCapacityStart = yBackgroundStart; xCapacityEnd = xBackgroundEnd; - yCapacityEnd = yCapacityStart + config.capacityBarOptions.width; + yCapacityEnd = yCapacityStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.width; } case TOP_TO_BOTTOM -> { - xBackgroundEnd = xBackgroundStart + config.capacityBarOptions.width; - yBackgroundEnd = yBackgroundStart + config.capacityBarOptions.length; + xBackgroundEnd = xBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.width; + yBackgroundEnd = yBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.length; xCapacityStart = xBackgroundStart; yCapacityStart = yBackgroundStart; xCapacityEnd = xBackgroundEnd; yCapacityEnd = yCapacityStart + step; } case BOTTOM_TO_TOP -> { - xBackgroundEnd = xBackgroundStart + config.capacityBarOptions.width; - yBackgroundEnd = yBackgroundStart + config.capacityBarOptions.length; + xBackgroundEnd = xBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.width; + yBackgroundEnd = yBackgroundStart + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.length; xCapacityStart = xBackgroundStart; yCapacityStart = yBackgroundEnd - step; xCapacityEnd = xBackgroundEnd; yCapacityEnd = yBackgroundEnd; } default -> { - String err = "Unexpected value for capacity direction: " + config.capacityBarOptions.direction; + String err = "Unexpected value for capacity direction: " + SimpleShulkerPreviewMod.CONFIGS.capacityBarOptions.direction; SimpleShulkerPreviewMod.LOGGER.error(err); throw new IllegalStateException(err); diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/positioners/IconRenderer.java b/src/main/java/com/bvengo/simpleshulkerpreview/positioners/IconRenderer.java index 3fb497e..742acf7 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/positioners/IconRenderer.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/positioners/IconRenderer.java @@ -1,7 +1,7 @@ package com.bvengo.simpleshulkerpreview.positioners; +import com.bvengo.simpleshulkerpreview.SimpleShulkerPreviewMod; import com.bvengo.simpleshulkerpreview.access.DrawContextAccess; -import com.bvengo.simpleshulkerpreview.config.ConfigOptions; import com.bvengo.simpleshulkerpreview.config.IconPositionOptions; import com.bvengo.simpleshulkerpreview.container.ContainerManager; @@ -17,25 +17,25 @@ public class IconRenderer extends OverlayRenderer { public float yOffset; public float zOffset; - public IconRenderer(ConfigOptions config, ContainerManager containerParser, ItemStack displayStack, int x, int y) { - super(config, displayStack, x, y); - setPositionOptions(config, containerParser); + public IconRenderer(ContainerManager containerParser, ItemStack displayStack, int x, int y) { + super(displayStack, x, y); + setPositionOptions(containerParser); } - private void setPositionOptions(ConfigOptions config, ContainerManager containerParser) { + private void setPositionOptions(ContainerManager containerParser) { switch(containerParser.getContainerType()) { case SHULKER_BOX: iconPositionOptions = ( - containerParser.getStackSize() > 1 ? - config.iconPositionOptionsStacked : - config.iconPositionOptionsGeneral + containerParser.getStackSize() > 1 ? + SimpleShulkerPreviewMod.CONFIGS.iconPositionOptionsStacked : + SimpleShulkerPreviewMod.CONFIGS.iconPositionOptionsGeneral ); break; case BUNDLE: - iconPositionOptions = config.iconPositionOptionsBundle; + iconPositionOptions = SimpleShulkerPreviewMod.CONFIGS.iconPositionOptionsBundle; break; case OTHER: - iconPositionOptions = config.iconPositionOptionsGeneral; + iconPositionOptions = SimpleShulkerPreviewMod.CONFIGS.iconPositionOptionsGeneral; break; case NONE: break; diff --git a/src/main/java/com/bvengo/simpleshulkerpreview/positioners/OverlayRenderer.java b/src/main/java/com/bvengo/simpleshulkerpreview/positioners/OverlayRenderer.java index c274386..4fd2123 100644 --- a/src/main/java/com/bvengo/simpleshulkerpreview/positioners/OverlayRenderer.java +++ b/src/main/java/com/bvengo/simpleshulkerpreview/positioners/OverlayRenderer.java @@ -1,19 +1,16 @@ package com.bvengo.simpleshulkerpreview.positioners; -import com.bvengo.simpleshulkerpreview.config.ConfigOptions; import net.minecraft.client.gui.DrawContext; import net.minecraft.item.ItemStack; public abstract class OverlayRenderer { - ConfigOptions config; ItemStack stack; int stackX; int stackY; - public OverlayRenderer(ConfigOptions config, ItemStack stack, int x, int y) { - this.config = config; + public OverlayRenderer(ItemStack stack, int x, int y) { this.stack = stack; this.stackX = x; this.stackY = y; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b4576a6..a3c87c4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "simpleshulkerpreview", - "version": "2.4.3", + "version": "2.4.4", "icon": "assets/simpleshulkerpreview/icon.png", "name": "Simple Shulker Preview", "description": "Display a configurable icon indicating the contents of a shulker box, as well as a capacity bar.", @@ -20,11 +20,11 @@ "mixins": ["simpleshulkerpreview.mixins.json"], "depends": { "fabricloader": ">=0.15.0", - "minecraft": ">=1.20.5", + "minecraft": "~1.21", "java": ">=21" }, "recommends": { - "modmenu": ">=10.0.0" + "modmenu": ">=11.0" }, "custom": { "modmenu": { diff --git a/src/main/resources/simpleshulkerpreview.mixins.json b/src/main/resources/simpleshulkerpreview.mixins.json index 4af8544..17b6f0d 100644 --- a/src/main/resources/simpleshulkerpreview.mixins.json +++ b/src/main/resources/simpleshulkerpreview.mixins.json @@ -3,8 +3,6 @@ "minVersion": "0.8", "package": "com.bvengo.simpleshulkerpreview.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [ - ], "client": [ "DrawContextMixin" ],