Skip to content

Commit

Permalink
Merge pull request #246 from P3pp3rF1y/1.20.x-dev
Browse files Browse the repository at this point in the history
feat: ✨ Add configurable check for whether container items can go int…
  • Loading branch information
P3pp3rF1y authored Jul 11, 2023
2 parents ccfff0e + 13cfa4e commit de30fda
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/net/p3pp3rf1y/sophisticatedstorage/Config.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<List<String>> disallowedItemsList;
private boolean initialized = false;
private Set<Item> 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));
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit de30fda

Please sign in to comment.