diff --git a/gradle.properties b/gradle.properties index 58a353c0..e18f6a8d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ minecraft_version=1.20.1 forge_version=47.0.16 -mod_version=0.8.41 +mod_version=0.8.42 jei_mc_version=1.20.1-forge jei_version=15.1.0.19 rubidium_cf_file_id=4573226 diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/Config.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/Config.java index 02538e21..e2f43fe3 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/Config.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/Config.java @@ -1,7 +1,10 @@ package net.p3pp3rf1y.sophisticatedstorage; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.fml.event.config.ModConfigEvent; +import net.minecraftforge.registries.ForgeRegistries; import net.p3pp3rf1y.sophisticatedcore.upgrades.FilteredUpgradeConfig; import net.p3pp3rf1y.sophisticatedcore.upgrades.cooking.AutoCookingUpgradeConfig; import net.p3pp3rf1y.sophisticatedcore.upgrades.cooking.CookingUpgradeConfig; @@ -14,6 +17,11 @@ import net.p3pp3rf1y.sophisticatedstorage.upgrades.hopper.HopperUpgradeConfig; import org.apache.commons.lang3.tuple.Pair; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class Config { private Config() {} @@ -87,6 +95,7 @@ public static class Server { public final StorageConfig goldShulkerBox; public final StorageConfig diamondShulkerBox; public final StorageConfig netheriteShulkerBox; + public final ShulkerBoxDisallowedItems shulkerBoxDisallowedItems; public final StackUpgradeConfig stackUpgrade; public final FilteredUpgradeConfig compactingUpgrade; @@ -166,6 +175,7 @@ public Server(ForgeConfigSpec.Builder builder) { goldShulkerBox = new StorageConfig(builder, "Gold Shulker Box", 81, 3); diamondShulkerBox = new StorageConfig(builder, "Diamond Shulker Box", 108, 4); netheriteShulkerBox = new StorageConfig(builder, "Netherite Shulker Box", 132, 5); + shulkerBoxDisallowedItems = new ShulkerBoxDisallowedItems(builder); stackUpgrade = new StackUpgradeConfig(builder); compactingUpgrade = new FilteredUpgradeConfig(builder, "Compacting Upgrade", "compactingUpgrade", 9, 3); @@ -221,5 +231,48 @@ public LimitedBarrelConfig(ForgeConfigSpec.Builder builder, String storagePrefix builder.pop(); } } + + public static class ShulkerBoxDisallowedItems { + private final ForgeConfigSpec.BooleanValue containerItemsDisallowed; + private final ForgeConfigSpec.ConfigValue> disallowedItemsList; + private boolean initialized = false; + private Set disallowedItemsSet = null; + + ShulkerBoxDisallowedItems(ForgeConfigSpec.Builder builder) { + builder.push("shulkerBoxDisallowedItems"); + disallowedItemsList = builder.comment("List of items that are not allowed to be put in shulkerboxes - e.g. \"minecraft:bundle\"").define("disallowedItems", new ArrayList<>()); + containerItemsDisallowed = builder.comment("Determines if container items (those that override canFitInsideContainerItems to false) are able to fit in shulker boxes") + .define("containerItemsDisallowed", false); + builder.pop(); + } + + public boolean isItemDisallowed(Item item) { + if (!SERVER_SPEC.isLoaded()) { + return true; + } + + if (!initialized) { + loadDisallowedSet(); + } + + if (Boolean.TRUE.equals(containerItemsDisallowed.get()) && !item.canFitInsideContainerItems()) { + return true; + } + + return disallowedItemsSet.contains(item); + } + + private void loadDisallowedSet() { + initialized = true; + disallowedItemsSet = new HashSet<>(); + + for (String disallowedItemName : disallowedItemsList.get()) { + ResourceLocation registryName = new ResourceLocation(disallowedItemName); + if (ForgeRegistries.ITEMS.containsKey(registryName)) { + disallowedItemsSet.add(ForgeRegistries.ITEMS.getValue(registryName)); + } + } + } + } } } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlockEntity.java index f5890f54..62cc4b1f 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlockEntity.java @@ -16,6 +16,7 @@ import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.p3pp3rf1y.sophisticatedstorage.Config; import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks; import java.util.List; @@ -88,10 +89,8 @@ private void updateAnimation(Level level, BlockPos pos, BlockState state) { @Override protected boolean isAllowedInStorage(ItemStack stack) { - //TODO add config with other things that can't go in - //TODO add backpacks compat so that they can't go in Block block = Block.byItem(stack.getItem()); - return !(block instanceof ShulkerBoxBlock) && !(block instanceof net.minecraft.world.level.block.ShulkerBoxBlock); + return !(block instanceof ShulkerBoxBlock) && !(block instanceof net.minecraft.world.level.block.ShulkerBoxBlock) && !Config.SERVER.shulkerBoxDisallowedItems.isItemDisallowed(stack.getItem()); } private static void doNeighborUpdates(Level level, BlockPos pos, BlockState state) {