Skip to content

Commit

Permalink
Full update and changes
Browse files Browse the repository at this point in the history
- Updated to 1.21.3
- Updated capacity colours to match bundles
- Resolved #33 by adding shulker size options
- Better capacity calculations
  • Loading branch information
BVengo committed Nov 12, 2024
1 parent da3af4b commit 21e4bd9
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 156 deletions.
38 changes: 21 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

maven { url = "https://api.modrinth.com/maven" } // Modrinth
maven { url "https://maven.terraformersmc.com/" } // Mod Menu
maven { url "https://maven.shedaniel.me/" } // Cloth Config
}
Expand All @@ -25,20 +25,21 @@ dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Tells Gradle to use cloth config
modImplementation "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}", {
exclude module: 'fabric-api'
}
include "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Tells Gradle to use mod menu
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}", {
exclude module: 'fabric-api'
}

// Tells Gradle to use cloth config
modImplementation "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}", {
exclude module: 'fabric-api'
}
include "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}"
}

processResources {
Expand All @@ -50,7 +51,6 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.20.5 (1.20.5-pre1) upwards uses Java 21.
it.options.release = 21
}

Expand All @@ -59,18 +59,22 @@ java {
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${project.base.archivesName.get()}"}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
Expand All @@ -82,4 +86,4 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}
14 changes: 7 additions & 7 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.4
mod_version = 2.4.5
maven_group = com.bvengo
archives_base_name = simpleshulkerpreview

Expand All @@ -11,12 +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=15.0.127
modmenu_version=11.0.1
cloth_version=16.0.141
modmenu_version=12.0.0-beta.1

minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9

# Fabric API
fabric_version=0.100.1+1.21
fabric_version=0.107.0+1.21.3
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
9 changes: 6 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -246,4 +249,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
4 changes: 3 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -89,4 +91,4 @@ exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega
61 changes: 0 additions & 61 deletions notes/inventory.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ public class ConfigOptions implements ConfigData {
@ConfigEntry.Category("compatibility")
@ConfigEntry.Gui.Tooltip()
public boolean supportOtherContainers = false;

/**
* Support mods that change the default size of shulkers.
* Requested in https://github.com/BVengo/simple-shulker-preview/issues/33
*/
@ConfigEntry.Category("compatibility")
@ConfigEntry.Gui.CollapsibleObject()
@ConfigEntry.Gui.Tooltip()
public ShulkerInventoryOptions shulkerInventoryOptions = new ShulkerInventoryOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class IconPositionOptions {
public int translateY;

@ConfigEntry.Gui.Tooltip()
@ConfigEntry.BoundedDiscrete(min = 0, max = 16)
@ConfigEntry.BoundedDiscrete(min = 0, max = 64)
public int translateZ;

@ConfigEntry.Gui.Tooltip()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bvengo.simpleshulkerpreview.config;

import me.shedaniel.autoconfig.annotation.ConfigEntry;

public class ShulkerInventoryOptions {
@ConfigEntry.Gui.Tooltip()
@ConfigEntry.BoundedDiscrete(max = 64)
public int shulkerInventoryRows = 3;

@ConfigEntry.Gui.Tooltip()
@ConfigEntry.BoundedDiscrete(max = 64)
public int shulkerInventoryCols = 9;

public int getSize() {
return shulkerInventoryRows * shulkerInventoryCols;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.component.type.ContainerComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.apache.commons.lang3.math.Fraction;

public class ContainerManager {
private ItemStack containerStack;
Expand Down Expand Up @@ -71,48 +72,62 @@ public int getStackSize() {
* Returns the ratio full that a container is.
* @return A float between 0 and 1 indicating how full the container is
*/
public float getCapacity() {
switch(containerContentsType) {
case CONTAINER:
return getContainerCapacity();
case BUNDLE:
return getBundleCapacity();
default:
// String msg = String.format("Cannot get capacity of container '%s' with no contents type.", containerId);
// SimpleShulkerPreviewMod.LOGGER.warn(msg);
return 0.0f;
public Fraction getCapacity() {
Fraction capacity = switch (containerContentsType) {
case CONTAINER -> getContainerCapacity();
case BUNDLE -> getBundleCapacity();
default ->
// String msg = String.format("Cannot get capacity of container '%s' with no contents type.", containerId);
// SimpleShulkerPreviewMod.LOGGER.warn(msg);
Fraction.ZERO;
};

// Cap the capacity at 1, in case unsupported large containers are used without using the configs to
// modify inventory sizes
if(capacity.compareTo(Fraction.ONE) > 0) {
capacity = Fraction.ONE;
}

return capacity;
}

public ContainerType getContainerType() {
return containerType;
}

private float getContainerCapacity() {
private Fraction getContainerCapacity() {
if(containerType != ContainerType.SHULKER_BOX) {
// String msg = String.format("Cannot get maximum inventory size of the container '%s'.", containerId);
// SimpleShulkerPreviewMod.LOGGER.warn(msg);
return 0.0f;
return Fraction.ZERO;
}

return getShulkerCapacity();
}

private float getShulkerCapacity() {
private Fraction getShulkerCapacity() {
ContainerComponent containerComponent = containerStack.get(DataComponentTypes.CONTAINER);
Iterable<ItemStack> itemIterable = containerComponent.iterateNonEmpty();
if(containerComponent == null) {
// String msg = String.format("Cannot get container component for container '%s'.", containerId);
// SimpleShulkerPreviewMod.LOGGER.warn(msg);
return Fraction.ZERO;
}

float sumCapacity = 0.0f;
int maxItems = SimpleShulkerPreviewMod.CONFIGS.shulkerInventoryOptions.getSize() * 64; // Maximum number of items in the shulker
int numItems = 0; // Actual number of items in the shulker

Iterable<ItemStack> itemIterable = containerComponent.iterateNonEmpty();
for(ItemStack itemStack : itemIterable) {
sumCapacity += (float) itemStack.getCount() / itemStack.getItem().getMaxCount();;
numItems += itemStack.getCount();
maxItems += itemStack.getItem().getMaxCount() - 64; // Replace the previous 64 with the actual max size of the item
}

return sumCapacity / ShulkerBoxBlockEntity.INVENTORY_SIZE;
return Fraction.getFraction(numItems, maxItems);
}

private float getBundleCapacity() {
private Fraction getBundleCapacity() {
BundleContentsComponent bundleComponent = containerStack.get(DataComponentTypes.BUNDLE_CONTENTS);
return bundleComponent.getOccupancy().floatValue();
return bundleComponent.getOccupancy();
}

private void setContainerContentsType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ public static ItemStack getItemFromCustomName(ItemStack itemStack) {
Identifier itemId = Identifier.tryParse(customName.getString());
if(itemId == null) return null;

Item item = Registries.ITEM.getOrEmpty(itemId).orElse(null);
if(item == null) return null;

Item item = Registries.ITEM.get(itemId);
return new ItemStack(item);
}

Expand Down
Loading

0 comments on commit 21e4bd9

Please sign in to comment.