Skip to content

Commit

Permalink
Merge branch 'dev-1.21'
Browse files Browse the repository at this point in the history
  • Loading branch information
BVengo committed Jul 11, 2024
2 parents 2ab374d + bfc7f42 commit fccf5f2
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 75 deletions.
17 changes: 8 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
# Fabric API
fabric_version=0.100.1+1.21
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -42,7 +39,7 @@ private void setItemString() {
}

// Group enchantments
if (config.groupEnchantment && itemStack.hasEnchantments()) {
if (SimpleShulkerPreviewMod.CONFIGS.groupEnchantment && itemStack.hasEnchantments()) {
itemString += ".enchanted";
}
}
Expand Down Expand Up @@ -72,9 +69,9 @@ private static Map<ItemStackGrouper, Integer> groupItemStacks(Iterable<ItemStack
}

public static ItemStack getDisplayStackFromIterable(Iterable<ItemStack> 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)
Expand Down Expand Up @@ -117,7 +114,7 @@ public static ItemStack getDisplayStackFromIterable(Iterable<ItemStack> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -32,27 +31,34 @@ 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);
}
}

@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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand All @@ -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": {
Expand Down
Loading

0 comments on commit fccf5f2

Please sign in to comment.