Skip to content

Commit

Permalink
1.0.3: Revamp Config, and fix an issue with TOP.
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Apr 17, 2023
1 parent 9f7934f commit 115f686
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 62 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Please note that JOB10's repo is itself a fork of Raptor's [Storage Drawers Unli

#### Removed all existing drawers / trims

#### Added WAILA Addon
#### Fixed an Issue with TOP, and revamped config
* TOP would display a Taped Drawer, even if the drawer wasn't taped, as long as the {Keep Contents on Break} Storage Drawers Config was turned on.



2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G

mod_version=1.0.2
mod_version=1.0.3

mcversion=1.12.2
forge_version=1.12.2-14.23.5.2832
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/io/github/nomiceu/GTDConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@

@Config(modid = GTDrawers.MODID)
public class GTDConfig {

@Name("force load")
@Comment({"A list of mod ids whose drawers should",
"always be created, even if the mod is not present."})
@Name("Fix TOP Displaying Taped Drawers")
@Comment("Fix a bug where TOP would display a taped drawer if the drawer contained items, if the [Keep Contents on Break] storage drawer config was enabled.")
@RequiresMcRestart
public static String[] forcedMods = new String[0];

@Name("force all")
@Comment("Set this to true to force all available mods to load.")
public static boolean force_all = false;

@Name("disable")
@Comment({"A list of mod ids whose drawers should",
"never be created, even if the mod is loaded."})
@RequiresMcRestart
public static String[] disabledMods = new String[0];

public static boolean fixTOPTaped = true;
}
6 changes: 6 additions & 0 deletions src/main/java/io/github/nomiceu/GTDrawers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;

import io.github.nomiceu.integration.TOP.TOPCompat;
import net.minecraftforge.fml.common.Loader;
import org.apache.logging.log4j.Logger;

import io.github.nomiceu.proxy.CommonProxy;
Expand Down Expand Up @@ -50,6 +52,10 @@ public void preInit(FMLPreInitializationEvent event) {
@EventHandler
public void init(FMLInitializationEvent event) {
proxy.init(event);
if (Loader.isModLoaded("theoneprobe")) {
logger.info("Detected The One Probe. Enabling custom handlers.");
TOPCompat.registerProviders();
}
}

@EventHandler
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/github/nomiceu/integration/TOP/TOPCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.nomiceu.integration.TOP;

import io.github.nomiceu.integration.TOP.provider.DrawerLogoProvider;
import mcjty.theoneprobe.TheOneProbe;
import mcjty.theoneprobe.api.ITheOneProbe;

public class TOPCompat {
public static void registerProviders() {
ITheOneProbe TOP = TheOneProbe.theOneProbeImp;
TOP.registerBlockDisplayOverride(new DrawerLogoProvider());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.nomiceu.integration.TOP.provider;

import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
import io.github.nomiceu.GTDConfig;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import mcjty.theoneprobe.config.Config;

import java.util.Objects;

import static com.jaquadro.minecraft.storagedrawers.StorageDrawers.config;
import static mcjty.theoneprobe.api.TextStyleClass.MODNAME;

public class DrawerLogoProvider implements IBlockDisplayOverride {
@Override
public boolean overrideStandardInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer entityPlayer, World world, IBlockState blockState, IProbeHitData probeHitData) {
Block block = blockState.getBlock();
if (!(block instanceof BlockDrawers) || !GTDConfig.fixTOPTaped)
return false;

String modid = Tools.getModName(block);

TileEntityDrawers tile = (TileEntityDrawers) Objects.requireNonNull(world.getTileEntity(probeHitData.getPos()));

if (!config.cache.keepContentsOnBreak || tile.isSealed())
return false;

ItemStack pickBlock = probeHitData.getPickBlock();

if (pickBlock == null || pickBlock.isEmpty())
return false;

if (pickBlock.hasTagCompound() && pickBlock.getTagCompound() != null) {
if (pickBlock.getTagCompound().hasKey("tile")){
NBTTagCompound compound = pickBlock.getTagCompound();
compound.removeTag("tile");
pickBlock.setTagCompound(compound);
}
}

if (Tools.show(mode, Config.getRealConfig().getShowModName()))
probeInfo.horizontal()
.item(pickBlock)
.vertical()
.itemLabel(pickBlock)
.text(MODNAME + modid);
else
probeInfo.horizontal(probeInfo.defaultLayoutStyle()
.alignment(ElementAlignment.ALIGN_CENTER))
.item(pickBlock);

return true;
}
}
47 changes: 3 additions & 44 deletions src/main/java/io/github/nomiceu/type/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.github.nomiceu.GTDConfig;
import net.minecraftforge.fml.common.ModContainer;
import org.apache.commons.lang3.tuple.Pair;

import net.minecraftforge.fml.common.Loader;
Expand All @@ -19,7 +19,6 @@ public class Mod implements StreamableIterable<DrawerMaterial> {
static final ArrayList<Mod> internal_modlist = new ArrayList<>();

public final String modid;
private String[] other_modids, disabled_modids;
private String modname;
private final Map<String, DrawerMaterial> materials;

Expand All @@ -39,8 +38,6 @@ private static String[] withoutFirstElement(String[] array) {

public Mod(String modid, String[] other_modids, String[] disabled_modids, DrawerMaterial.Builder... materialsIn) {
this.modid = modid;
this.other_modids = other_modids;
this.disabled_modids = disabled_modids;
this.materials = Collections.unmodifiableMap(Arrays.stream(materialsIn)
.map(builder -> builder.build(this))
.filter(Optional::isPresent)
Expand All @@ -67,7 +64,7 @@ public Stream<DrawerMaterial> parallelStream() {
}

public String getModName() {
return modname == null? modname = Loader.instance().getModList().stream().filter(container -> container.getModId().equals(modid)).map(container -> container.getName()).findFirst().orElse(modid + " [not loaded]")
return modname == null? modname = Loader.instance().getModList().stream().filter(container -> container.getModId().equals(modid)).map(ModContainer::getName).findFirst().orElse(modid + " [not loaded]")
: modname;
}

Expand All @@ -76,45 +73,7 @@ public DrawerMaterial getDefaultMaterial() {
}

public boolean isEnabled() {
if(areAnyIncompatibleModsLoaded())
return false;

if(GTDConfig.force_all && !contains(GTDConfig.disabledMods, modid)) {
if(other_modids.length != 0) {
for(String modid : other_modids) {
if(contains(GTDConfig.disabledMods, modid))
return false;
}
}
return true;
}

if(Loader.isModLoaded(modid) && !contains(GTDConfig.disabledMods, modid) || contains(GTDConfig.forcedMods, modid))
return true;
if(other_modids.length == 0)
return false;
for(String modid : other_modids) {
if(Loader.isModLoaded(modid) && !contains(GTDConfig.disabledMods, modid) || contains(GTDConfig.forcedMods, modid))
return true;
}
return false;
}

public boolean areAnyIncompatibleModsLoaded() {
if(disabled_modids.length == 0) return false;
for(String modid : disabled_modids) {
if(Loader.isModLoaded(modid))
return true;
}
return false;
}

private static boolean contains(String[] array, String value) {
for(String element : array) {
if(value.equals(element))
return true;
}
return false;
return true;
}

public Iterator<DrawerMaterial> iterator() {
Expand Down

0 comments on commit 115f686

Please sign in to comment.