-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3373adc
commit 743f8c8
Showing
7 changed files
with
102 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,20 @@ | ||
# Sets default memory used for gradle commands. Can be overridden by user or command line properties. | ||
# This is required to provide enough memory for the Minecraft decompilation process. | ||
org.gradle.jvmargs=-Xmx3G | ||
org.gradle.jvmargs=-Xmx6G | ||
org.gradle.daemon=false | ||
|
||
|
||
## Environment Properties | ||
|
||
# The Minecraft version must agree with the Forge version to get a valid artifact | ||
# mapping config | ||
minecraft_version=1.20.1 | ||
# The Minecraft version range can use any release version of Minecraft as bounds. | ||
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly | ||
# as they do not follow standard versioning conventions. | ||
minecraft_version_range=[1.20.1,1.21) | ||
# The Forge version must agree with the Minecraft version to get a valid artifact | ||
forge_version=47.2.0 | ||
# The Forge version range can use any version of Forge as bounds or match the loader version range | ||
forge_version_range=[47,) | ||
# The loader version range can only use the major version of Forge/FML as bounds | ||
loader_version_range=[47,) | ||
# The mapping channel to use for mappings. | ||
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. | ||
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin. | ||
# | ||
# | Channel | Version | | | ||
# |-----------|----------------------|--------------------------------------------------------------------------------| | ||
# | official | MCVersion | Official field/method names from Mojang mapping files | | ||
# | parchment | YYYY.MM.DD-MCVersion | Open community-sourced parameter names and javadocs layered on top of official | | ||
# | ||
# You must be aware of the Mojang license when using the 'official' or 'parchment' mappings. | ||
# See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md | ||
# | ||
# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge. | ||
# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started | ||
mapping_channel=official | ||
# The mapping version to query from the mapping channel. | ||
# This must match the format required by the mapping channel. | ||
mapping_version=1.20.1 | ||
|
||
|
||
## Mod Properties | ||
|
||
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} | ||
# Must match the String constant located in the main mod class annotated with @Mod. | ||
# mod config | ||
mod_id=stackone | ||
# The human-readable display name for the mod. | ||
mod_name=Stack One Mod | ||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. | ||
mod_license=Apache License 2.0 | ||
# The mod version. See https://semver.org/ | ||
mod_version=1.20.1-1.0.6 | ||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. | ||
# This should match the base package used for the mod sources. | ||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html | ||
mod_version=1.20.1-1.0.7 | ||
mod_group_id=com.laosun.stackone | ||
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list. | ||
mod_authors=Laosun | ||
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. | ||
mod_description=You can't stack anything. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/laosun/stackone/ItemStackSizeModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.laosun.stackone; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.minecraft.world.item.Item; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
// written by chinese "doubao" ai | ||
public class ItemStackSizeModifier { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ItemStackSizeModifier.class); | ||
|
||
@FunctionalInterface | ||
interface MaxStackSizeFieldGetter { | ||
Field get(Item item) throws NoSuchFieldException; | ||
} | ||
|
||
private static final MaxStackSizeFieldGetter defaultMaxStackSizeFieldGetter = item -> { | ||
try { | ||
return Item.class.getDeclaredField("maxStackSize"); | ||
} catch (NoSuchFieldException e) { | ||
return null; | ||
} | ||
}; | ||
|
||
private static final MaxStackSizeFieldGetter alternativeMaxStackSizeFieldGetter = item -> { | ||
try { | ||
return Item.class.getDeclaredField("f_41370_"); | ||
} catch (NoSuchFieldException e) { | ||
return null; | ||
} | ||
}; | ||
|
||
@SuppressWarnings("deprecation") | ||
public static void modifyItemStackSizes() { | ||
ArrayList<String> ignoreItems = IgnoreItem.getIgnoreItems(); | ||
List<Item> itemsToModify = new ArrayList<>(); | ||
|
||
for (Item i : ForgeRegistries.ITEMS) { | ||
if (!ignoreItems.contains(i.builtInRegistryHolder().key().location().toString())) { | ||
itemsToModify.add(i); | ||
} | ||
} | ||
|
||
List<MaxStackSizeFieldGetter> fieldGetterStrategies = List.of(defaultMaxStackSizeFieldGetter, alternativeMaxStackSizeFieldGetter); | ||
|
||
for (Item item : itemsToModify) { | ||
Field maxStackSizeField = null; | ||
for (MaxStackSizeFieldGetter strategy : fieldGetterStrategies) { | ||
try { | ||
maxStackSizeField = strategy.get(item); | ||
if (maxStackSizeField != null) { | ||
break; | ||
} | ||
} catch (NoSuchFieldException ignored) { | ||
} | ||
} | ||
|
||
if (maxStackSizeField == null) { | ||
LOGGER.error("Could not find valid maxStackSize field for item {}", item); | ||
continue; | ||
} | ||
|
||
maxStackSizeField.setAccessible(true); | ||
try { | ||
maxStackSizeField.set(item, 1); | ||
} catch (IllegalAccessException e) { | ||
LOGGER.error("Failed to set maxStackSize field for item {}", item, e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters