Skip to content

Commit

Permalink
1.7.0
Browse files Browse the repository at this point in the history
Add config option to blacklist certain blocks/mods (#507)
Rewritten JEI/REI/EMI recipe integrations (#466)
Added polymorph support on 1.20.1 Forge
  • Loading branch information
tom5454 committed Jan 16, 2025
1 parent 9b76446 commit c52379a
Show file tree
Hide file tree
Showing 30 changed files with 539 additions and 268 deletions.
14 changes: 11 additions & 3 deletions Toms-Storage-120/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.architectury.dev/" }
maven { url "https://maven.terraformersmc.com/releases/"}
maven {
url 'https://www.cursemaven.com'
content {
includeGroup "curse.maven"
}
}
}

dependencies {
Expand Down Expand Up @@ -179,11 +185,13 @@ dependencies {

compileOnly fg.deobf("dev.emi:emi-forge:1.0.21+1.20.1:api")
runtimeOnly fg.deobf("dev.emi:emi-forge:1.0.21+1.20.1")

implementation fg.deobf("curse.maven:polymorph-388800:5995253")

if(useLib) {
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-api-forge:12.0.624")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-default-plugin-forge:12.0.624")
implementation fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:12.0.624")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-api-forge:12.1.785")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-default-plugin-forge:12.1.785")
implementation fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:12.1.785")
implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:11.0.99")
implementation fg.deobf("dev.architectury:architectury-forge:9.0.8")
}
Expand Down
2 changes: 1 addition & 1 deletion Toms-Storage-120/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=1.6.9
mod_version=1.7.0
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

public class Config {
public static final List<String> defaultMultiblocks = Arrays.asList("");
public static final List<String> defaultBlockedMods = Arrays.asList("");
public static final List<String> defaultBlockedBlocks = Arrays.asList("");
private static final Config INSTANCE = new Config();

public boolean onlyTrims;
Expand All @@ -35,6 +37,8 @@ public class Config {
public int wirelessTermBeaconLvl, wirelessTermBeaconLvlDim;
public int invLinkBeaconLvl, invLinkBeaconLvlDim;
public int invDupScanSize;
private Set<String> blockedMods = new HashSet<>();
private Set<Block> blockedBlocks = new HashSet<>();

public static Config get() {
return INSTANCE;
Expand Down Expand Up @@ -104,6 +108,8 @@ private Server(ForgeConfigSpec.Builder builder) {

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

public Common(ForgeConfigSpec.Builder builder) {
builder.comment("IMPORTANT NOTICE:",
Expand All @@ -117,6 +123,14 @@ public Common(ForgeConfigSpec.Builder builder) {
multiblockInvs = builder.comment("List of multiblock inventory blocks").
translation("tomsstorage.config.multiblock_inv").
defineList("multiblockInv", defaultMultiblocks, s -> true);

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

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

Expand Down Expand Up @@ -149,7 +163,12 @@ private void load(ModConfig modConfig) {
invLinkBeaconLvlDim = SERVER.invLinkBeaconLvlDim.get();
invDupScanSize = SERVER.invDupScanSize.get();
} else if(modConfig.getType() == Type.COMMON) {
multiblockInvs = COMMON.multiblockInvs.get().stream().map(ResourceLocation::new).map(ForgeRegistries.BLOCKS::getValue).
multiblockInvs = COMMON.multiblockInvs.get().stream().map(ResourceLocation::tryParse).filter(e -> e != null).map(ForgeRegistries.BLOCKS::getValue).
filter(e -> e != null && e != Blocks.AIR).collect(Collectors.toSet());

blockedMods = new HashSet<>(COMMON.blockedMods.get());

blockedBlocks = COMMON.blockedBlocks.get().stream().map(ResourceLocation::tryParse).filter(e -> e != null).map(ForgeRegistries.BLOCKS::getValue).
filter(e -> e != null && e != Blocks.AIR).collect(Collectors.toSet());
}
}
Expand All @@ -165,4 +184,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 @@ -6,6 +6,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
Expand All @@ -15,6 +16,8 @@

import com.tom.storagemod.network.NetworkHandler;
import com.tom.storagemod.platform.Platform;
import com.tom.storagemod.polymorph.PolymorphHelper;
import com.tom.storagemod.polymorph.PolymorphTerminalWidget;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(StorageMod.modid)
Expand All @@ -24,6 +27,8 @@ public class StorageMod {
// Directly reference a log4j logger.
public static final Logger LOGGER = LogManager.getLogger();

public static boolean polymorph;

public StorageMod() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
Expand All @@ -38,6 +43,8 @@ public StorageMod() {
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);

polymorph = ModList.get().isLoaded("polymorph");

Content.init();

Platform.register();
Expand All @@ -46,9 +53,11 @@ public StorageMod() {
private void setup(final FMLCommonSetupEvent event) {
LOGGER.info("Tom's Storage Setup starting");
NetworkHandler.init();
if (polymorph)PolymorphHelper.init();
}

private void doClientStuff(final FMLClientSetupEvent event) {
StorageModClient.clientSetup();
if (polymorph)PolymorphTerminalWidget.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,24 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.state.BlockState;

import com.tom.storagemod.Content;
import com.tom.storagemod.StorageMod;
import com.tom.storagemod.gui.CraftingTerminalMenu;
import com.tom.storagemod.platform.PlatformRecipe;
import com.tom.storagemod.polymorph.PolymorphHelper;
import com.tom.storagemod.util.CraftingMatrix;
import com.tom.storagemod.util.StoredItemStack;

public class CraftingTerminalBlockEntity extends StorageTerminalBlockEntity {
private AbstractContainerMenu craftingContainer = new AbstractContainerMenu(MenuType.CRAFTING, 0) {
@Override
public boolean stillValid(Player player) {
return false;
}

@Override
public void slotsChanged(Container inventory) {
if (level != null && !level.isClientSide) {
onCraftingMatrixChanged();
}
}

@Override
public ItemStack quickMoveStack(Player p_38941_, int p_38942_) {
return ItemStack.EMPTY;
}
};
private PlatformRecipe currentRecipe;
private final CraftingContainer craftMatrix = new CraftingMatrix(3, 3, () -> {
if (level != null && !level.isClientSide) {
Expand Down Expand Up @@ -177,7 +159,7 @@ public void registerCrafting(CraftingTerminalMenu containerCraftingTerminal) {
protected void onCraftingMatrixChanged() {
if(refillingGrid)return;
if (currentRecipe == null || !currentRecipe.matches(craftMatrix, level)) {
currentRecipe = PlatformRecipe.of(level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftMatrix, level).orElse(null));
currentRecipe = getRecipe();
}

if (currentRecipe == null) {
Expand All @@ -194,56 +176,29 @@ protected void onCraftingMatrixChanged() {
}
}

public void clear() {
for (int i = 0; i < craftMatrix.getContainerSize(); i++) {
ItemStack st = craftMatrix.removeItemNoUpdate(i);
if(!st.isEmpty()) {
pushOrDrop(st);
}
private PlatformRecipe getRecipe() {
if (StorageMod.polymorph) {
return PlatformRecipe.of(PolymorphHelper.getRecipe(this, RecipeType.CRAFTING, craftMatrix, level).orElse(null));
}
onCraftingMatrixChanged();
return PlatformRecipe.of(level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftMatrix, level).orElse(null));
}

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.isSameItemSameTags(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);
public void clear(Player player) {
for (int i = 0; i < craftMatrix.getContainerSize(); i++) {
ItemStack st = craftMatrix.removeItemNoUpdate(i);
if(!st.isEmpty()) {
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 @@ -253,4 +208,13 @@ public void updateServer() {
public boolean canCraft() {
return craftingCooldown + craftResult.getItem(0).getCount() <= craftResult.getItem(0).getMaxStackSize();
}

public void polymorphUpdate() {
currentRecipe = null;
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.block.ITrim;
import com.tom.storagemod.util.IProxy;
import com.tom.storagemod.util.InfoHandler;
import com.tom.storagemod.util.InventoryConnectorConfigUtil;
import com.tom.storagemod.util.MultiItemHandler;
import com.tom.storagemod.util.Priority;
import com.tom.storagemod.util.TickerUtil.TickableServer;
Expand Down Expand Up @@ -84,6 +85,8 @@ public void updateServer() {
if(state.getBlock() instanceof ITrim) {
toCheck.add(p);
} else {
if (!InventoryConnectorConfigUtil.canConnect(state.getBlock()))
continue;
BlockEntity te = level.getBlockEntity(p);
if (te instanceof InventoryConnectorBlockEntity || te instanceof InventoryProxyBlockEntity || te instanceof AbstractInventoryCableConnectorBlockEntity) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ public StoredItemStack pullStack(StoredItemStack stack, long max) {
return null;
}

public StoredItemStack pullStackFuzzy(StoredItemStack stack, long max) {
if(stack != null && itemHandler != null && max > 0) {
ItemStack st = stack.getStack();
StoredItemStack ret = null;
for (int i = itemHandler.getSlots() - 1; i >= 0; i--) {
ItemStack s = itemHandler.getStackInSlot(i);
if(ItemStack.isSameItem(s, st) && (ItemStack.isSameItemSameTags(s, st) || !s.isEnchanted())) {
ItemStack pulled = itemHandler.extractItem(i, (int) max, false);
if(!pulled.isEmpty()) {
if(ret == null)ret = new StoredItemStack(pulled);
else ret.grow(pulled.getCount());
max -= pulled.getCount();
if(max < 1)break;
}
}
}
return ret;
}
return null;
}

public StoredItemStack pushStack(StoredItemStack stack) {
if(stack != null && itemHandler != null) {
ItemStack is = ItemHandlerHelper.insertItemStacked(itemHandler, stack.getActualStack(), false);
Expand All @@ -107,10 +128,14 @@ public void pushOrDrop(ItemStack st) {
if(st.isEmpty())return;
StoredItemStack st0 = pushStack(new StoredItemStack(st));
if(st0 != null) {
Containers.dropItemStack(level, worldPosition.getX() + .5f, worldPosition.getY() + .5f, worldPosition.getZ() + .5f, st0.getActualStack());
dropItem(st0.getActualStack());
}
}

public void dropItem(ItemStack stack) {
Containers.dropItemStack(level, worldPosition.getX() + .5f, worldPosition.getY() + .5f, worldPosition.getZ() + .5f, stack);
}

@Override
public void updateServer() {
if(updateItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.BlockHitResult;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.crafting.IShapedRecipe;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand Down Expand Up @@ -93,4 +95,10 @@ public static <T> T checkExtraSlots(Player player, Predicate<ItemStack> is, T de
}
return def;
}

public static int getRecipeWidth(Recipe<?> recipe) {
if (recipe instanceof IShapedRecipe sr)
return sr.getRecipeWidth();
return -1;
}
}
Loading

0 comments on commit c52379a

Please sign in to comment.