Skip to content

Commit

Permalink
Merge pull request #962 from P3pp3rF1y/1.20.x-dev
Browse files Browse the repository at this point in the history
Release merge
  • Loading branch information
P3pp3rF1y authored Feb 4, 2024
2 parents 2a9cc05 + b0786f7 commit 06fe4ed
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 107 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedbackpacks
mod_group_id=sophisticatedbackpacks
mod_version=3.19.5
mod_version=3.19.8
sonar_project_key=sophisticatedbackpacks:SophisticatedBackpacks
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedBackpacks

Expand All @@ -22,8 +22,8 @@ botania_version=1.19.2-439-FORGE-SNAPSHOT
patchouli_version=1.19.2-78-SNAPSHOT
balm_cf_file_id=4597440
crafting_tweaks_cf_file_id=4596466
chipped_cf_file_id=4634856
resourcefullib_cf_file_id=4851864
chipped_cf_file_id=5077656
resourcefullib_cf_file_id=5070629
athena_cf_file_id=4764357
sc_version=[1.20.1-0.5.112,1.21)
sc_version=[1.20.1-0.5.116,1.21)
parchment_version=1.19.3-2023.03.12-1.20
104 changes: 92 additions & 12 deletions src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.registries.ForgeRegistries;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackItem;
import net.p3pp3rf1y.sophisticatedbackpacks.init.ModItems;
import net.p3pp3rf1y.sophisticatedcore.upgrades.FilteredUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.IUpgradeCountLimitConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeGroup;
import net.p3pp3rf1y.sophisticatedcore.upgrades.battery.BatteryUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.cooking.AutoCookingUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.cooking.CookingUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.cooking.ICookingUpgrade;
import net.p3pp3rf1y.sophisticatedcore.upgrades.magnet.MagnetUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.pump.PumpUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.stack.StackUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.stack.StackUpgradeItem;
import net.p3pp3rf1y.sophisticatedcore.upgrades.tank.TankUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.voiding.VoidUpgradeConfig;
import net.p3pp3rf1y.sophisticatedcore.upgrades.xppump.XpPumpUpgradeConfig;
import org.apache.commons.lang3.tuple.Pair;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

@SuppressWarnings("java:S1192") //don't complain about repeated config names if two upgrades happen to have the same setting
@SuppressWarnings("java:S1192")
//don't complain about repeated config names if two upgrades happen to have the same setting
public class Config {

private static final String REGISTRY_NAME_MATCHER = "([a-z0-9_.-]+:[a-z0-9_/.-]+)";

private Config() {}
private Config() {
}

public static final Server SERVER;
public static final ForgeConfigSpec SERVER_SPEC;
Expand Down Expand Up @@ -103,12 +103,29 @@ public static class Server {
public final PumpUpgradeConfig pumpUpgrade;
public final XpPumpUpgradeConfig xpPumpUpgrade;
public final NerfsConfig nerfsConfig;
public final MaxUgradesPerStorageConfig maxUpgradesPerStorage;

public void initListeners(IEventBus modBus) {
modBus.addListener(this::onConfigReload);
modBus.addListener(this::onConfigLoad);
}

@SuppressWarnings("unused") //need the Event parameter for forge reflection to understand what event this listens to
@SuppressWarnings("unused")
//need the Event parameter for forge reflection to understand what event this listens to
public void onConfigReload(ModConfigEvent.Reloading event) {
clearCache();
}

@SuppressWarnings("unused")
//need the Event parameter for forge reflection to understand what event this listens to
public void onConfigLoad(ModConfigEvent.Loading event) {
clearCache();
}

private void clearCache() {
disallowedItems.initialized = false;
stackUpgrade.clearNonStackableItems();
maxUpgradesPerStorage.clearCache();
}

Server(ForgeConfigSpec.Builder builder) {
Expand Down Expand Up @@ -157,6 +174,13 @@ public void onConfigReload(ModConfigEvent.Reloading event) {
xpPumpUpgrade = new XpPumpUpgradeConfig(builder);
entityBackpackAdditions = new EntityBackpackAdditionsConfig(builder);
nerfsConfig = new NerfsConfig(builder);
maxUpgradesPerStorage = new MaxUgradesPerStorageConfig(builder,
Map.of(
StackUpgradeItem.UPGRADE_GROUP.name(), 3,
ICookingUpgrade.UPGRADE_GROUP.name(), 1,
ModItems.JUKEBOX_UPGRADE_NAME, 1
)
);

itemFluidHandlerEnabled = builder.comment("Turns on/off item fluid handler of backpack in its item form. There are some dupe bugs caused by default fluid handling implementation that manifest when backpack is drained / filled in its item form in another mod's tank and the only way to prevent them is disallowing drain/fill in item form altogether").define("itemFluidHandlerEnabled", true);
allowOpeningOtherPlayerBackpacks = builder.comment("Determines whether player can right click on backpack that another player is wearing to open it. If off will turn off that capability for everyone and remove related settings from backpack.").define("allowOpeningOtherPlayerBackpacks", true);
Expand All @@ -166,11 +190,13 @@ public void onConfigReload(ModConfigEvent.Reloading event) {

builder.pop();
}

public static class NerfsConfig {
public final ForgeConfigSpec.BooleanValue tooManyBackpacksSlowness;
public final ForgeConfigSpec.IntValue maxNumberOfBackpacks;
public final ForgeConfigSpec.DoubleValue slownessLevelsPerAdditionalBackpack;
public final ForgeConfigSpec.BooleanValue onlyWornBackpackTriggersUpgrades;

public NerfsConfig(ForgeConfigSpec.Builder builder) {
builder.push("nerfs");
tooManyBackpacksSlowness = builder.comment("Determines if too many backpacks in player's inventory cause slowness to the player").define("tooManyBackpacksSlowness", false);
Expand All @@ -181,6 +207,7 @@ public NerfsConfig(ForgeConfigSpec.Builder builder) {
}

}

public static class EntityBackpackAdditionsConfig {
private static final String ENTITY_LOOT_MATCHER = "([a-z0-9_.-]+:[a-z0-9_/.-]+)\\|(null|[a-z0-9_.-]+:[a-z0-9/_.-]+)";
public final ForgeConfigSpec.DoubleValue chance;
Expand Down Expand Up @@ -414,10 +441,63 @@ private void loadDisallowedSet() {
}
}
}

public static class MaxUgradesPerStorageConfig implements IUpgradeCountLimitConfig {
private final ForgeConfigSpec.ConfigValue<List<String>> maxUpgradesPerStorageList;

@Nullable
private Map<String, Integer> maxUpgradesPerStorage = null;

protected MaxUgradesPerStorageConfig(ForgeConfigSpec.Builder builder, Map<String, Integer> defaultUpgradesPerStorage) {
maxUpgradesPerStorageList = builder.comment("Maximum number of upgrades of type per backpack in format of \"UpgradeRegistryName[or UpgradeGroup]|MaxNumber\"").define("maxUpgradesPerStorage", convertToList(defaultUpgradesPerStorage));
}

private List<String> convertToList(Map<String, Integer> defaultUpgradesPerStorage) {
return defaultUpgradesPerStorage.entrySet().stream().map(e -> e.getKey() + "|" + e.getValue()).collect(Collectors.toList());
}

public void clearCache() {
maxUpgradesPerStorage = null;
}

@Override
public int getMaxUpgradesPerStorage(String storageType, @org.jetbrains.annotations.Nullable ResourceLocation upgradeRegistryName) {
if (maxUpgradesPerStorage == null) {
initMaxUpgradesPerStorage();
}
if (upgradeRegistryName == null) {
return Integer.MAX_VALUE;
}

return maxUpgradesPerStorage.getOrDefault(upgradeRegistryName.getPath(), Integer.MAX_VALUE);
}

private void initMaxUpgradesPerStorage() {
maxUpgradesPerStorage = new HashMap<>();
for (String mapping : maxUpgradesPerStorageList.get()) {
String[] upgradeMax = mapping.split("\\|");
if (upgradeMax.length < 2) {
continue;
}
String name = upgradeMax[0];
int max = Integer.parseInt(upgradeMax[1]);
maxUpgradesPerStorage.put(name, max);
}
}

@Override
public int getMaxUpgradesInGroupPerStorage(String storageType, UpgradeGroup upgradeGroup) {
if (maxUpgradesPerStorage == null) {
initMaxUpgradesPerStorage();
}
return maxUpgradesPerStorage.getOrDefault(upgradeGroup.name(), Integer.MAX_VALUE);
}
}
}

public static class Common {
public final ForgeConfigSpec.BooleanValue chestLootEnabled;

Common(ForgeConfigSpec.Builder builder) {
builder.comment("Common Settings").push("common");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SophisticatedBackpacks() {

modBus.addListener(SophisticatedBackpacks::setup);
modBus.addListener(DataGenerators::gatherData);
modBus.addListener(Config.SERVER::onConfigReload);
Config.SERVER.initListeners(modBus);
modBus.addListener(CapabilityBackpackWrapper::onRegister);
modBus.addListener(SophisticatedBackpacks::clientSetup);
SBPCommand.init(modBus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -31,20 +32,10 @@
import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeHandler;
import net.p3pp3rf1y.sophisticatedcore.upgrades.stack.StackUpgradeItem;
import net.p3pp3rf1y.sophisticatedcore.upgrades.tank.TankUpgradeItem;
import net.p3pp3rf1y.sophisticatedcore.util.InventoryHelper;
import net.p3pp3rf1y.sophisticatedcore.util.InventorySorter;
import net.p3pp3rf1y.sophisticatedcore.util.LootHelper;
import net.p3pp3rf1y.sophisticatedcore.util.NBTHelper;
import net.p3pp3rf1y.sophisticatedcore.util.RandHelper;
import net.p3pp3rf1y.sophisticatedcore.util.*;

import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.function.IntConsumer;

public class BackpackWrapper implements IBackpackWrapper {
Expand All @@ -62,8 +53,10 @@ public class BackpackWrapper implements IBackpackWrapper {
private static final String COLUMNS_TAKEN_TAG = "columnsTaken";

private final ItemStack backpack;
private Runnable backpackSaveHandler = () -> {};
private Runnable inventorySlotChangeHandler = () -> {};
private Runnable backpackSaveHandler = () -> {
};
private Runnable inventorySlotChangeHandler = () -> {
};

@Nullable
private InventoryHandler handler = null;
Expand All @@ -84,10 +77,13 @@ public class BackpackWrapper implements IBackpackWrapper {

private final BackpackRenderInfo renderInfo;

private IntConsumer onSlotsChange = diff -> {};
private IntConsumer onSlotsChange = diff -> {
};

private Runnable onInventoryHandlerRefresh = () -> {};
private Runnable upgradeCachesInvalidatedHandler = () -> {};
private Runnable onInventoryHandlerRefresh = () -> {
};
private Runnable upgradeCachesInvalidatedHandler = () -> {
};

public BackpackWrapper(ItemStack backpack) {
this.backpack = backpack;
Expand Down Expand Up @@ -471,7 +467,8 @@ public void registerOnSlotsChangeListener(IntConsumer onSlotsChange) {

@Override
public void unregisterOnSlotsChangeListener() {
onSlotsChange = diff -> {};
onSlotsChange = diff -> {
};
}

@Override
Expand Down Expand Up @@ -526,11 +523,22 @@ public void registerOnInventoryHandlerRefreshListener(Runnable onInventoryHandle

@Override
public void unregisterOnInventoryHandlerRefreshListener() {
onInventoryHandlerRefresh = () -> {};
onInventoryHandlerRefresh = () -> {
};
}

@Override
public ItemStack getWrappedStorageStack() {
return getBackpack();
}

@Override
public String getStorageType() {
return "backpack";
}

@Override
public Component getDisplayName() {
return getBackpack().getHoverName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Noop extends NoopStorageWrapper implements IBackpackWrapper {
public static final Noop INSTANCE = new Noop();

private final ItemStack backpack = new ItemStack(ModItems.BACKPACK.get());
private final BackpackSettingsHandler settingsHandler = new BackpackSettingsHandler(this, new CompoundTag(), () -> {});
private final BackpackSettingsHandler settingsHandler = new BackpackSettingsHandler(this, new CompoundTag(), () -> {
});

@Override
public BackpackSettingsHandler getSettingsHandler() {
Expand All @@ -76,5 +77,20 @@ public ItemStack cloneBackpack() {
public void copyDataTo(IStorageWrapper otherStorageWrapper) {
//noop
}

@Override
public void setSlotNumbers(int numberOfInventorySlots, int numberOfUpgradeSlots) {
//noop
}

@Override
public void setLoot(ResourceLocation lootTableName, float lootPercentage) {
//noop
}

@Override
public void setContentsUuid(UUID storageUuid) {
//noop
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.registries.RegistryObject;
import net.p3pp3rf1y.sophisticatedbackpacks.Config;
import net.p3pp3rf1y.sophisticatedbackpacks.client.gui.SBPButtonDefinitions;
import net.p3pp3rf1y.sophisticatedbackpacks.compat.jei.SBPPlugin;
import net.p3pp3rf1y.sophisticatedbackpacks.init.ModItems;
Expand All @@ -31,19 +32,19 @@
public class ChippedCompat implements ICompat {

public static final RegistryObject<BlockTransformationUpgradeItem> BOTANIST_WORKBENCH_UPGRADE = ModItems.ITEMS.register("chipped/botanist_workbench_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.BOTANIST_WORKBENCH_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.BOTANIST_WORKBENCH, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<BlockTransformationUpgradeItem> GLASSBLOWER_UPGRADE = ModItems.ITEMS.register("chipped/glassblower_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.GLASSBLOWER_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.GLASSBLOWER, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<BlockTransformationUpgradeItem> CARPENTERS_TABLE_UPGRADE = ModItems.ITEMS.register("chipped/carpenters_table_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.CARPENTERS_TABLE_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.CARPENTERS_TABLE, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<BlockTransformationUpgradeItem> LOOM_TABLE_UPGRADE = ModItems.ITEMS.register("chipped/loom_table_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.LOOM_TABLE_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.LOOM_TABLE, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<BlockTransformationUpgradeItem> MASON_TABLE_UPGRADE = ModItems.ITEMS.register("chipped/mason_table_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.MASON_TABLE_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.MASON_TABLE, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<BlockTransformationUpgradeItem> ALCHEMY_BENCH_UPGRADE = ModItems.ITEMS.register("chipped/alchemy_bench_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.ALCHEMY_BENCH_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.ALCHEMY_BENCH, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<BlockTransformationUpgradeItem> TINKERING_TABLE_UPGRADE = ModItems.ITEMS.register("chipped/tinkering_table_upgrade",
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.TINKERING_TABLE_TYPE));
() -> new BlockTransformationUpgradeItem(ModRecipeTypes.TINKERING_TABLE, Config.SERVER.maxUpgradesPerStorage));

@Override
public void init() {
Expand Down
Loading

0 comments on commit 06fe4ed

Please sign in to comment.