Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
Add config option to blacklist certain blocks/mods (Closes #507)
Rewritten JEI/REI/EMI recipe integrations (Closes #466)
Fixed crash with 0 size inventories (Closes #516)
  • Loading branch information
tom5454 committed Jan 16, 2025
1 parent e02fde7 commit 707aff8
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 203 deletions.
6 changes: 3 additions & 3 deletions Fabric/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/use
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.2
loader_version=0.16.10

# Fabric API
fabric_version=0.102.1+1.21.1
fabric_version=0.114.0+1.21.1

# Mod Properties
mod_version = 2.0.13
mod_version = 2.1.0
maven_group = com.tom5454.toms_storage
archives_base_name = toms_storage_fabric-1.21

Expand Down
25 changes: 25 additions & 0 deletions Fabric/src/main/java/com/tom/storagemod/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package com.tom.storagemod;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.Tooltip;

Expand All @@ -15,8 +26,22 @@ public class Config implements ConfigData {
@Tooltip
public int invLinkBeaconLvl = 0, invLinkBeaconRange = 4096, invLinkBeaconLvlSameDim = 1, invLinkBeaconLvlCrossDim = 2;
//public int inventoryConnectorMaxSlots = Integer.MAX_VALUE;
public List<String> blockedBlocks = new ArrayList<>(Arrays.asList("create:belt"));
public List<String> blockedMods = new ArrayList<>();

public static Config get() {
return StorageMod.CONFIG;
}

public Set<Block> getBlockedBlocks() {
if (StorageMod.blockedBlocks == null) {
StorageMod.blockedBlocks = blockedBlocks.stream().map(ResourceLocation::tryParse).filter(e -> e != null).
map(id -> BuiltInRegistries.BLOCK.get(id)).filter(e -> e != null && e != Blocks.AIR).collect(Collectors.toSet());
}
return StorageMod.blockedBlocks;
}

public List<String> getBlockedMods() {
return blockedMods;
}
}
9 changes: 9 additions & 0 deletions Fabric/src/main/java/com/tom/storagemod/StorageMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Set;
import java.util.function.Function;

import org.apache.logging.log4j.LogManager;
Expand All @@ -28,6 +29,7 @@
import net.minecraft.server.TickTask;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -60,6 +62,7 @@ public class StorageMod implements ModInitializer {
public static Config CONFIG = new Config();

public static boolean polymorph;
public static Set<Block> blockedBlocks;

public StorageMod() {
}
Expand Down Expand Up @@ -109,6 +112,7 @@ public void onInitialize() {

ServerLifecycleEvents.SERVER_STARTING.register(server -> {
CONFIG = LOADED_CONFIG;
blockedBlocks = null;
});

ItemStorage.SIDED.registerForBlockEntity((be, side) -> PlatformItemHandler.of(be), Content.connectorBE.get());
Expand Down Expand Up @@ -150,5 +154,10 @@ public void onInitialize() {
});

polymorph = FabricLoader.getInstance().isModLoaded("polymorph");

configHolder.registerSaveListener((a, b) -> {
blockedBlocks = null;
return InteractionResult.PASS;
});
}
}
10 changes: 5 additions & 5 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ dependencies {
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
compileOnly "mezz.jei:jei-1.21.1-neoforge-api:19.19.0.219"
compileOnly "mezz.jei:jei-1.21.1-common-api:19.19.0.219"
compileOnly "mezz.jei:jei-1.21.1-neoforge-api:19.21.0.247"
compileOnly "mezz.jei:jei-1.21.1-common-api:19.21.0.247"
// at runtime, use the full JEI jar
runtimeOnly "mezz.jei:jei-1.21.1-neoforge:19.19.0.219"
runtimeOnly "mezz.jei:jei-1.21.1-neoforge:19.21.0.247"

if(useLib) {
compileOnly "me.shedaniel:RoughlyEnoughItems-api-neoforge:14.0.688"
Expand All @@ -148,8 +148,8 @@ dependencies {

compileOnly "curse.maven:vivecraft-667903:6060487"

compileOnly "dev.emi:emi-neoforge:1.1.7+1.21:api"
runtimeOnly "dev.emi:emi-neoforge:1.1.7+1.21"
compileOnly "dev.emi:emi-neoforge:1.1.19+1.21.1:api"
runtimeOnly "dev.emi:emi-neoforge:1.1.19+1.21.1"

implementation "curse.maven:polymorph-388800:5480541"

Expand Down
2 changes: 1 addition & 1 deletion NeoForge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod_name=Tom's Simple Storage Mod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT License
# The mod version. See https://semver.org/
mod_version=2.0.12
mod_version=2.1.0
# 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
Expand Down
36 changes: 36 additions & 0 deletions NeoForge/src/main/java/com/tom/storagemod/Config.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.tom.storagemod;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.Pair;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.config.ModConfig.Type;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.neoforge.common.ModConfigSpec;
import net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
import net.neoforged.neoforge.common.ModConfigSpec.ConfigValue;
import net.neoforged.neoforge.common.ModConfigSpec.IntValue;

public class Config {
Expand All @@ -21,6 +32,8 @@ public class Config {
public int wirelessTermBeaconLvl, wirelessTermBeaconLvlCrossDim;
public int invLinkBeaconLvl, invLinkBeaconRange, invLinkBeaconLvlSameDim, invLinkBeaconLvlCrossDim;
//public int inventoryConnectorMaxSlots;
private Set<String> blockedMods = new HashSet<>();
private Set<Block> blockedBlocks = new HashSet<>();

public static Config get() {
return INSTANCE;
Expand Down Expand Up @@ -103,6 +116,8 @@ private Server(ModConfigSpec.Builder builder) {
}

public static class Common {
public ConfigValue<List<? extends String>> blockedMods;
public ConfigValue<List<? extends String>> blockedBlocks;

public Common(ModConfigSpec.Builder builder) {
builder.comment("IMPORTANT NOTICE:",
Expand All @@ -112,6 +127,14 @@ public Common(ModConfigSpec.Builder builder) {
"You can then take that config file and put it in the 'defaultconfigs' folder to make it apply automatically to all NEW worlds you generate FROM THERE ON.",
"This may appear confusing to many of you, but it is a new sensible way to handle configuration, because the server configuration is synced when playing multiplayer.").
define("importantInfo", true);

blockedMods = builder.comment("List of mod ids whose blocks is ignored by the inventory connector").
translation("config.toms_storage.inv_blocked_mods").
defineList("blockedMods", Collections.emptyList(), () -> "", s -> true);

blockedBlocks = builder.comment("List of block ids ignored by the inventory connector").
translation("config.toms_storage.inv_blocked_blocks").
defineList("blockedBlocks", Collections.emptyList(), () -> "", s -> true);
}
}

Expand Down Expand Up @@ -147,6 +170,11 @@ private void load(ModConfig modConfig) {
runMultithreaded = SERVER.runMultithreaded.getAsBoolean();
//inventoryConnectorMaxSlots = SERVER.inventoryConnectorMaxSlots.getAsInt();
} else if(modConfig.getType() == Type.COMMON) {
blockedMods = new HashSet<>(COMMON.blockedMods.get());

blockedBlocks = COMMON.blockedBlocks.get().stream().map(ResourceLocation::tryParse).filter(e -> e != null).
map(BuiltInRegistries.BLOCK::get).filter(e -> e != null && e != Blocks.AIR).
collect(Collectors.toSet());
}
}

Expand All @@ -161,4 +189,12 @@ public void onFileChange(final ModConfigEvent.Reloading configEvent) {
StorageMod.LOGGER.info("Tom's Simple Storage config just got changed on the file system!");
load(configEvent.getConfig());
}

public Set<Block> getBlockedBlocks() {
return blockedBlocks;
}

public Set<String> getBlockedMods() {
return blockedMods;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public boolean isItemValid(int slot, ItemStack stack) {
calling = true;

int arrayIndex = findInventory(slot);
int invSlot = slot - offsets[arrayIndex];

boolean r = getHandler(arrayIndex).isItemValid(slot - offsets[arrayIndex], stack);
boolean r = getHandler(arrayIndex, invSlot).isItemValid(invSlot, stack);
calling = false;
return r;
}
Expand All @@ -44,8 +45,9 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
calling = true;

int arrayIndex = findInventory(slot);
int invSlot = slot - offsets[arrayIndex];

ItemStack s = getHandler(arrayIndex).insertItem(slot - offsets[arrayIndex], stack, simulate);
ItemStack s = getHandler(arrayIndex, invSlot).insertItem(invSlot, stack, simulate);
calling = false;
return s;
}
Expand All @@ -57,8 +59,9 @@ public ItemStack getStackInSlot(int slot) {
calling = true;

int arrayIndex = findInventory(slot);
int invSlot = slot - offsets[arrayIndex];

ItemStack s = getHandler(arrayIndex).getStackInSlot(slot - offsets[arrayIndex]);
ItemStack s = getHandler(arrayIndex, invSlot).getStackInSlot(invSlot);
calling = false;
return s;
}
Expand All @@ -75,8 +78,9 @@ public int getSlotLimit(int slot) {
calling = true;

int arrayIndex = findInventory(slot);
int invSlot = slot - offsets[arrayIndex];

int r = getHandler(arrayIndex).getSlotLimit(slot - offsets[arrayIndex]);
int r = getHandler(arrayIndex, invSlot).getSlotLimit(invSlot);
calling = false;
return r;
}
Expand All @@ -88,8 +92,9 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
calling = true;

int arrayIndex = findInventory(slot);
int invSlot = slot - offsets[arrayIndex];

ItemStack s = getHandler(arrayIndex).extractItem(slot - offsets[arrayIndex], amount, simulate);
ItemStack s = getHandler(arrayIndex, invSlot).extractItem(invSlot, amount, simulate);
calling = false;
return s;
}
Expand All @@ -106,21 +111,23 @@ public void refresh() {
invSize = 0;
int hOff = 0;
for (int i = 0; i < offsets.length; i++) {
IItemHandler ih = getHandler(i);
if(ih == null) {
IItemHandler ih = getHandler(i, 0);
int s = ih.getSlots();
if (s == 0) {
hOff++;
} else {
int s = ih.getSlots();
offsets[i - hOff] = invSize;
invSize += s;
}
}
offsetsSize = offsets.length - hOff;
}

private IItemHandler getHandler(int i) {
private IItemHandler getHandler(int i, int invSlot) {
IItemHandler h = connected.get(i).getPlatformHandler();
if (h == null)return EmptyItemHandler.INSTANCE;
return h;
if (invSlot < h.getSlots())
return h;
return EmptyItemHandler.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,56 +197,22 @@ private Optional<RecipeHolder<CraftingRecipe>> getRecipe(CraftingInput input) {
return level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, input, level);
}

public void clear() {
public void clear(Player player) {
for (int i = 0; i < craftMatrix.getContainerSize(); i++) {
ItemStack st = craftMatrix.removeItemNoUpdate(i);
if(!st.isEmpty()) {
pushOrDrop(st);
}
}
onCraftingMatrixChanged();
}

public void handlerItemTransfer(Player player, ItemStack[][] items) {
clear();
for (int i = 0;i < 9;i++) {
if (items[i] != null) {
ItemStack stack = ItemStack.EMPTY;
for (int j = 0;j < items[i].length;j++) {
ItemStack pulled = pullStack(items[i][j]);
if (!pulled.isEmpty()) {
stack = pulled;
break;
}
}
if (stack.isEmpty()) {
for (int j = 0;j < items[i].length;j++) {
boolean br = false;
for (int k = 0;k < player.getInventory().getContainerSize();k++) {
if(ItemStack.isSameItemSameComponents(player.getInventory().getItem(k), items[i][j])) {
stack = player.getInventory().removeItem(k, 1);
br = true;
break;
}
}
if (br)
break;
}
}
if (!stack.isEmpty()) {
craftMatrix.setItem(i, stack);
StoredItemStack st0 = pushStack(new StoredItemStack(st));
if (st0 != null) {
var is = st0.getActualStack();
player.getInventory().add(is);
if (!is.isEmpty())
dropItem(is);
}
}
}
onCraftingMatrixChanged();
}

private ItemStack pullStack(ItemStack itemStack) {
StoredItemStack is = pullStack(new StoredItemStack(itemStack), 1);
if(is == null)return ItemStack.EMPTY;
else return is.getActualStack();
}

@Override
public void updateServer() {
super.updateServer();
Expand All @@ -262,4 +228,8 @@ public void polymorphUpdate(Player playerIn) {
currentRecipe = Optional.empty();
onCraftingMatrixChanged();
}

public void setCraftSlot(int x, int y, ItemStack actualStack) {
craftMatrix.setItem(x + y * 3, actualStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.tom.storagemod.inventory.VanillaMultiblockInventories;
import com.tom.storagemod.platform.PlatformBlockEntity;
import com.tom.storagemod.util.BlockFace;
import com.tom.storagemod.util.InventoryConnectorConfigUtil;
import com.tom.storagemod.util.TickerUtil.TickableServer;

public class InventoryConnectorBlockEntity extends PlatformBlockEntity implements TickableServer, IInventoryConnector, IInventory, IInventoryConnectorReference {
Expand Down Expand Up @@ -103,7 +104,7 @@ private void detectTouchingInventories() {
} else if(state.getBlock() instanceof IInventoryNode) {
interfaces.add(new BlockFace(p, Direction.DOWN));
toCheck.add(p);
} else if(!state.is(StorageTags.INV_CONNECTOR_SKIP) && !onlyTrims && BlockInventoryAccess.hasInventoryAt(level, p, state, d.getOpposite())) {
} else if(InventoryConnectorConfigUtil.canConnect(state) && !onlyTrims && BlockInventoryAccess.hasInventoryAt(level, p, state, d.getOpposite())) {
BlockFilter f = BlockFilter.getFilterAt(level, p);
if (f != null)blockFilters.add(f);
connected.put(p, d.getOpposite());
Expand Down
Loading

0 comments on commit 707aff8

Please sign in to comment.