Skip to content

Commit

Permalink
1.0.1: Waila Plugin (thanks to framed compacting drawers), and change…
Browse files Browse the repository at this point in the history
… locations of dependencies (lib -> gradle)
  • Loading branch information
IntegerLimit committed Apr 4, 2023
1 parent 183ba66 commit e8f4be9
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 2 deletions.
18 changes: 17 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,26 @@ minecraft {
mappings = forge_mappings
makeObfSourceJar = false

replaceIn "SDUnlimited.java"
replaceIn "GTDrawers.java"
replace '${version}', project.version
}

repositories {
maven {
url "https://cursemaven.com"
}
maven {
name = "hwyla"
url = "https://github.com/TehNut/temporary-maven-thing/raw/master/maven"
}
}

dependencies {
deobfCompile "curse.maven:storage-drawers-223852:2952606"
deobfCompile "curse.maven:chameleon-230497:2450900"
deobfCompile "mcp.mobius.waila:Hwyla:${hwyla_version}_${mcversion}"
}

processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G

mod_version=1.0.0
mod_version=1.0.1

mcversion=1.12.2
forge_version=1.12.2-14.23.5.2832
forge_mappings=stable_39
hwyla_version=1.8.26-B41
Binary file removed libs/Chameleon-1.12.2-4.1.3-dev.jar
Binary file not shown.
Binary file removed libs/StorageDrawers-1.12.2-5.3.7-deobf.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.nomiceu.integration;

import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.minecraftforge.fml.common.versioning.InvalidVersionSpecificationException;
import net.minecraftforge.fml.common.versioning.VersionRange;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public interface IIntegrationPlugin {

void init();

default boolean versionCheck() {
String pattern = versionPattern();
if(pattern == null)
return true;

List<ModContainer> modList = Loader.instance().getModList();

for(ModContainer mod : modList) {
if(mod.getModId().equals(getModID())) {
try {
VersionRange validVersions = VersionRange.createFromVersionSpec(pattern);
ArtifactVersion version = new DefaultArtifactVersion(mod.getVersion());
return validVersions.containsVersion(version);
} catch(InvalidVersionSpecificationException e) {
return false;
}
}
}

return false;
}

@Nullable
default String versionPattern() {
return null;
}

@Nonnull
String getModID();

void postInit();

}
65 changes: 65 additions & 0 deletions src/main/java/io/github/nomiceu/integration/waila/WailaPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.github.nomiceu.integration.waila;

import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
import com.jaquadro.minecraft.storagedrawers.integration.Waila;
import io.github.nomiceu.integration.IIntegrationPlugin;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.api.impl.ConfigHandler;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.event.FMLInterModComms;

import javax.annotation.Nonnull;
import java.util.List;

public class WailaPlugin implements IIntegrationPlugin {

@Nonnull
@Override
public String getModID() {
return "waila";
}

@Override
public void init() {
FMLInterModComms.sendMessage("waila", "register", "eutros.framedcompactdrawers.integration.waila.WailaPlugin.register");
}

@Override
public void postInit() {
}

@SuppressWarnings("unused")
public static void register(IWailaRegistrar registrar) {
ConfigHandler configHandler = ConfigHandler.instance();

Waila.WailaDrawer provider = new OverwrittenWailaDrawer();

registrar.registerBodyProvider(provider, BlockDrawers.class);
registrar.registerStackProvider(provider, BlockDrawers.class);

configHandler.addConfig(StorageDrawers.MOD_NAME, "display.content", I18n.format("storageDrawers.waila.config.displayContents"), true);
configHandler.addConfig(StorageDrawers.MOD_NAME, "display.stacklimit", I18n.format("storageDrawers.waila.config.displayStackLimit"), true);
configHandler.addConfig(StorageDrawers.MOD_NAME, "display.status", I18n.format("storageDrawers.waila.config.displayStatus"), true);
}

public static class OverwrittenWailaDrawer extends Waila.WailaDrawer {

@Override
@Nonnull
public List<String> getWailaBody(@Nonnull ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
TileEntity te = accessor.getTileEntity();
if(!(te instanceof TileEntityDrawers))
return currenttip;

return super.getWailaBody(itemStack, currenttip, accessor, config);
}

}

}

0 comments on commit e8f4be9

Please sign in to comment.