multiple bags, config

This commit is contained in:
Jenny 2025-05-16 06:59:18 +02:00
parent 06b871c389
commit 0eae3e4088
Signed by: Jenny
GPG Key ID: 2072A14E40940632
32 changed files with 226 additions and 29 deletions

View File

@ -38,7 +38,7 @@ mod_name=QuantumBags
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=0.0.2
mod_version=0.0.3
# 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
@ -46,4 +46,4 @@ mod_group_id=com.smthng
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=xJenny69
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=2^20 items in one slot
mod_description=adds bundles with huge capacities

View File

@ -15,22 +15,23 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeConfigSpec;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.List;
public class QuantumBag extends Item {
private final int maxSize;
ForgeConfigSpec.ConfigValue<Integer> size;
public QuantumBag(Properties pProperties, int maxSize) {
public QuantumBag(Properties pProperties, ForgeConfigSpec.ConfigValue<Integer> size) {
super(pProperties);
this.maxSize = maxSize;
this.size = size;
}
@Override
public boolean overrideOtherStackedOnMe(ItemStack pStack, ItemStack pOther, Slot pSlot, ClickAction pAction, Player pPlayer, SlotAccess pAccess) {
boolean canBeStored = !(pOther.getItem().equals(Items.AIR) || pOther.getItem().equals(items.QUANTUM_BAG.get()));
boolean canBeStored = !(pOther.getItem().equals(Items.AIR) || pOther.getItem().equals(this));
if (pAction.equals(ClickAction.PRIMARY)) { // left click on bag
if (canBeStored && matchesStored(pStack, pOther)) {
addItems(pStack, pOther);
@ -70,9 +71,9 @@ public class QuantumBag extends Item {
} else if (mode(pStack) == 2) { // suck items into bag
ItemStack stored = getStoredStack(pStack);
for (ItemStack itemStack : pPlayer.getInventory().items) {
if (stored.getCount() < maxSize) {
if (stored.getCount() < size.get()) {
if (itemStackSame(stored, itemStack)) {
int removeAmount = Math.min(maxSize - stored.getCount(), itemStack.getCount());
int removeAmount = Math.min(size.get() - stored.getCount(), itemStack.getCount());
stored.setCount(stored.getCount() + removeAmount);
itemStack.setCount(itemStack.getCount() - removeAmount);
@ -108,7 +109,7 @@ public class QuantumBag extends Item {
}
private void addItems(@NotNull ItemStack bag, @NotNull ItemStack itemStack) {
int removeAmount = Math.min(maxSize - storedItemCount(bag), itemStack.getCount());
int removeAmount = Math.min(size.get() - storedItemCount(bag), itemStack.getCount());
if (removeAmount > 0) {
ItemStack stored = itemStack.copy();
stored.setCount(removeAmount + storedItemCount(bag));
@ -118,7 +119,7 @@ public class QuantumBag extends Item {
}
private void addOne(@NotNull ItemStack bag, @NotNull ItemStack itemStack) {
int removeAmount = Math.min(maxSize - storedItemCount(bag), 1);
int removeAmount = Math.min(size.get() - storedItemCount(bag), 1);
if (removeAmount > 0) {
ItemStack stored = itemStack.copy();
stored.setCount(removeAmount + storedItemCount(bag));

View File

@ -3,6 +3,7 @@ package com.smthng.quantumbags;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.commands.LocateCommand;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
@ -42,10 +43,13 @@ public class Quantumbags {
items.register(modEventBus);
MinecraftForge.EVENT_BUS.register(this);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ServerConfig.SPEC, "quantumbags-server.toml");
modEventBus.addListener(this::addCreative);
}
private void addCreative(@NotNull BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) event.accept(items.QUANTUM_BAG);
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
items.ITEMS.getEntries().forEach((e) -> event.accept(e.get().getDefaultInstance()));
}
}
}

View File

@ -0,0 +1,21 @@
package com.smthng.quantumbags;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;
import static com.smthng.quantumbags.Quantumbags.MODID;
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ServerConfig {
public static final ForgeConfigSpec.ConfigValue<Integer> C_SIZE_SMALL, C_SIZE_MEDIUM, C_SIZE_LARGE, C_SIZE_HUGE;
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
static {
C_SIZE_SMALL = BUILDER.define("size_small", 512);
C_SIZE_MEDIUM = BUILDER.define("size_medium", 4096);
C_SIZE_LARGE = BUILDER.define("size_large", 32768);
C_SIZE_HUGE = BUILDER.define("size_huge", 262144);
SPEC = BUILDER.build();
}
}

View File

@ -10,7 +10,11 @@ import static com.smthng.quantumbags.Quantumbags.MODID;
public class items {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final RegistryObject<Item> QUANTUM_BAG = ITEMS.register("quantum_bag", () -> new QuantumBag(new Item.Properties().stacksTo(1), 1048576));
public static final RegistryObject<Item> QUANTUM_BAG_SMALL = ITEMS.register("quantum_bag_small", () -> new QuantumBag(new Item.Properties().stacksTo(1), ServerConfig.C_SIZE_SMALL));
public static final RegistryObject<Item> QUANTUM_BAG_MEDIUM = ITEMS.register("quantum_bag_medium", () -> new QuantumBag(new Item.Properties().stacksTo(1), ServerConfig.C_SIZE_MEDIUM));
public static final RegistryObject<Item> QUANTUM_BAG_LARGE = ITEMS.register("quantum_bag_large", () -> new QuantumBag(new Item.Properties().stacksTo(1), ServerConfig.C_SIZE_LARGE));
public static final RegistryObject<Item> QUANTUM_BAG_HUGE = ITEMS.register("quantum_bag_huge", () -> new QuantumBag(new Item.Properties().stacksTo(1), ServerConfig.C_SIZE_HUGE));
public static void register(IEventBus bus) {
ITEMS.register(bus);

View File

@ -1,3 +1,6 @@
{
"item.quantumbags.quantum_bag": "Quantum Bag"
"item.quantumbags.quantum_bag_small": "Small Quantum Bag",
"item.quantumbags.quantum_bag_medium": "Medium Quantum Bag",
"item.quantumbags.quantum_bag_large": "Large Quantum Bag",
"item.quantumbags.quantum_bag_huge": "Huge Quantum Bag"
}

View File

@ -1,6 +0,0 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_filling"
}
}

View File

@ -1,20 +1,20 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag"
"layer0": "quantumbags:item/quantum_bag_huge"
},
"overrides": [
{
"predicate": {
"custom_model_data": 1
},
"model": "quantumbags:item/quantum_bag_filling"
"model": "quantumbags:item/quantum_bag_huge_filling"
},
{
"predicate": {
"custom_model_data": 2
},
"model": "quantumbags:item/quantum_bag_sucking"
"model": "quantumbags:item/quantum_bag_huge_sucking"
}
]
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_huge",
"layer1": "quantumbags:item/filling"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_huge",
"layer1": "quantumbags:item/sucking"
}
}

View File

@ -0,0 +1,20 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_large"
},
"overrides": [
{
"predicate": {
"custom_model_data": 1
},
"model": "quantumbags:item/quantum_bag_large_filling"
},
{
"predicate": {
"custom_model_data": 2
},
"model": "quantumbags:item/quantum_bag_large_sucking"
}
]
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_large",
"layer1": "quantumbags:item/filling"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_large",
"layer1": "quantumbags:item/sucking"
}
}

View File

@ -0,0 +1,20 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_medium"
},
"overrides": [
{
"predicate": {
"custom_model_data": 1
},
"model": "quantumbags:item/quantum_bag_medium_filling"
},
{
"predicate": {
"custom_model_data": 2
},
"model": "quantumbags:item/quantum_bag_medium_sucking"
}
]
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_medium",
"layer1": "quantumbags:item/filling"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_medium",
"layer1": "quantumbags:item/sucking"
}
}

View File

@ -0,0 +1,20 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_small"
},
"overrides": [
{
"predicate": {
"custom_model_data": 1
},
"model": "quantumbags:item/quantum_bag_small_filling"
},
{
"predicate": {
"custom_model_data": 2
},
"model": "quantumbags:item/quantum_bag_small_sucking"
}
]
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_small",
"layer1": "quantumbags:item/filling"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_small",
"layer1": "quantumbags:item/sucking"
}
}

View File

@ -1,6 +0,0 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quantumbags:item/quantum_bag_sucking"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

View File

@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"#S#",
"S S",
"#S#"
],
"key": {
"#": {
"item": "minecraft:leather"
},
"S": {
"item": "quantumbags:quantum_bag_large"
}
},
"result": {
"item": "quantumbags:quantum_bag_huge",
"count": 1
}
}

View File

@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"#S#",
"S S",
"#S#"
],
"key": {
"#": {
"item": "minecraft:leather"
},
"S": {
"item": "quantumbags:quantum_bag_medium"
}
},
"result": {
"item": "quantumbags:quantum_bag_large",
"count": 1
}
}

View File

@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"#S#",
"S S",
"#S#"
],
"key": {
"#": {
"item": "minecraft:leather"
},
"S": {
"item": "quantumbags:quantum_bag_small"
}
},
"result": {
"item": "quantumbags:quantum_bag_medium",
"count": 1
}
}

View File

@ -14,7 +14,7 @@
}
},
"result": {
"item": "quantumbags:quantum_bag",
"item": "quantumbags:quantum_bag_small",
"count": 1
}
}