Skip to content

Commit

Permalink
Re-add controller support with midnightcontrols. Also adds config opt…
Browse files Browse the repository at this point in the history
…ion to enable/disable smallinv.

Includes patch to midnightcontrols to ignore slots that are disabled
  • Loading branch information
kyrptonaught committed May 23, 2022
1 parent f5c8c07 commit 6c38dfd
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 64 deletions.
23 changes: 22 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ repositories {
maven { url 'https://aperlambda.github.io/maven' }
maven { url 'https://maven.terraformersmc.com/' }
maven { url = "https://maven.kyrptonaught.dev" }

maven {
name 'Gegy'
url 'https://maven.gegy.dev'
}
maven {
name 'CottonMC'
url 'https://server.bbkr.space/artifactory/libs-snapshot'
}
maven { url 'https://maven.kosmx.dev' }
maven { url 'https://maven.shedaniel.me/' }
maven { url 'https://jitpack.io' }
maven { url "https://api.modrinth.com/maven" }
maven { url 'https://maven.quiltmc.org/repository/release'}
}

loom {
Expand All @@ -31,12 +45,19 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

//modImplementation "dev.lambdaurora:lambdacontrols:1.7.1+1.17"
optionalDependency('eu.midnightdust:midnightcontrols:1.0.0-1.18')

modImplementation('net.kyrptonaught:kyrptconfig:1.4.4-1.18')

modImplementation('net.kyrptonaught:kyrptconfig:1.4.4-1.18')
include('net.kyrptonaught:kyrptconfig:1.4.4-1.18')
}

def optionalDependency(String dep) {
dependencies.modImplementation (dep) {
exclude module: "RoughlyEnoughItems-runtime-fabric"
}
}

processResources {
inputs.property "version", project.version

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx4G

minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3:v2
loader_version=0.14.5
loader_version=0.14.6

#Fabric api
fabric_version=0.51.1+1.18.2
fabric_version=0.53.0+1.18.2

# Mod Properties
mod_version=0.0.7-1.18
mod_version=0.0.8-1.18
maven_group=net.kyrptonaught
archives_base_name=lemclienthelper

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.kyrptonaught.kyrptconfig.config.ConfigManager;
import net.kyrptonaught.lemclienthelper.ResourcePreloader.ResourcePreloader;
import net.kyrptonaught.lemclienthelper.SmallInv.SmallInvInit;
import net.kyrptonaught.lemclienthelper.TakeEverything.LambdControlsCompat;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
Expand All @@ -19,10 +21,12 @@ public class LEMClientHelperMod implements ClientModInitializer {
public void onInitializeClient() {
takeEverythingKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(MOD_ID + ".key.takeeverything", InputUtil.Type.MOUSE, GLFW.GLFW_MOUSE_BUTTON_3, MOD_ID + ".key.category.lemclienthelper"));
ResourcePreloader.init();
configManager.load();
// if (FabricLoader.getInstance().isModLoaded("lambdacontrols"))
//LambdControlsCompat.register();
SmallInvInit.init();

// if (FabricLoader.getInstance().isModLoaded("lambdacontrols"))
if (FabricLoader.getInstance().isModLoaded("midnightcontrols"))
LambdControlsCompat.register();
configManager.load();
}

public static boolean isKeybindPressed(int pressedKeyCode, boolean isMouse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.util.ProgressListener;

import java.io.File;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -23,9 +22,6 @@ enum PACKCOMPATIBILITY {
public String hash;
public File downloadedFile;
public PACKCOMPATIBILITY packCompatibility = PACKCOMPATIBILITY.BOTH;

public transient HttpURLConnection MIXINISBEINGDUMB;

public transient Progress progressListener = new Progress(this);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.kyrptonaught.lemclienthelper.ResourcePreloader;

import blue.endless.jankson.Jankson;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.hash.Hashing;
import net.kyrptonaught.lemclienthelper.LEMClientHelperMod;
Expand All @@ -12,11 +13,14 @@
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -48,6 +52,16 @@ public static void getPackList() {
}
}

public static void deletePacks() {
try {
ArrayList<File> list = Lists.newArrayList(FileUtils.listFiles(new File(MinecraftClient.getInstance().runDirectory, "server-resource-packs"), TrueFileFilter.TRUE, null));
for (File file : list) {
FileUtils.deleteQuietly(file);
}
} catch (Exception ignored) {
}
}

public static void downloadPacks() {
downloadsComplete = false;
startTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.kyrptonaught.lemclienthelper.SmallInv;

import net.kyrptonaught.kyrptconfig.config.AbstractConfigFile;

public class SmallInvConfig implements AbstractConfigFile {

public boolean enabled = true;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import java.util.HashMap;

public class SmallInvInit {

public static String MOD_ID = "smallinv";
public static HashMap<Integer, Pair<Integer, Integer>> SMALLINVSLOTS = new HashMap<>();

public static KeyBinding closeSmallInvKey;

public static void init() {
LEMClientHelperMod.configManager.registerFile(MOD_ID, new SmallInvConfig());
closeSmallInvKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(LEMClientHelperMod.MOD_ID + ".key.closesmallinv", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_I, LEMClientHelperMod.MOD_ID + ".key.category.lemclienthelper"));

registerSmallSlot(5, 55, 9);
Expand All @@ -35,8 +38,15 @@ public static void init() {
registerSmallSlot(44, 152, 99);
}

public static SmallInvConfig getConfig() {
return (SmallInvConfig) LEMClientHelperMod.configManager.getConfig(MOD_ID);
}

public static boolean isSmallInv(PlayerEntity player) {
//if (true) return true;
if (!getConfig().enabled) return false;

//give @p knowledge_book{display:{Name:'{"text":" "}'},SmallInv:1,CustomModelData:1}
for (ItemStack itemStack : player.getInventory().main) {
if (itemStack.hasNbt() && itemStack.getNbt().contains("SmallInv") && itemStack.getNbt().getInt("SmallInv") == 1)
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package net.kyrptonaught.lemclienthelper.TakeEverything;
/*
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.compat.CompatHandler;
import dev.lambdaurora.lambdacontrols.client.compat.LambdaControlsCompat;
import dev.lambdaurora.lambdacontrols.client.controller.ButtonBinding;
import dev.lambdaurora.lambdacontrols.client.controller.PressAction;

import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import eu.midnightdust.midnightcontrols.client.compat.CompatHandler;
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
import eu.midnightdust.midnightcontrols.client.controller.PressAction;
import net.kyrptonaught.lemclienthelper.LEMClientHelperMod;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;



public class LambdControlsCompat implements CompatHandler {

public static void register() {
LambdaControlsCompat.registerCompatHandler(new LambdControlsCompat());
MidnightControlsCompat.registerCompatHandler(new LambdControlsCompat());
}

private static final PressAction TAKE_EVERYTHING = (client, button, value, action) -> {
Expand All @@ -26,8 +28,8 @@ public static void register() {
};

@Override
public void handle(@NotNull LambdaControlsClient mod) {
new ButtonBinding.Builder(new Identifier(LEMClientHelperMod.MOD_ID, "takeeverything"))
public void handle(@NotNull MidnightControlsClient mod) {
new ButtonBinding.Builder(LEMClientHelperMod.MOD_ID+".takeeverything")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB)
.onlyInInventory()
.action(TAKE_EVERYTHING)
Expand All @@ -36,6 +38,4 @@ public void handle(@NotNull LambdaControlsClient mod) {
//.linkKeybind(LEBClientHelperMod.takeEverythingKey)
.register();
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.kyrptonaught.lemclienthelper.ResourcePreloader.AllPacks;
import net.kyrptonaught.lemclienthelper.ResourcePreloader.ResourcePreloader;
import net.kyrptonaught.lemclienthelper.ResourcePreloader.ResourcePreloaderConfig;
import net.kyrptonaught.lemclienthelper.SmallInv.SmallInvInit;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -28,31 +29,39 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
LEMClientHelperMod.configManager.save();
});

ConfigSection displaySection = new ConfigSection(configScreen, new TranslatableText("key.lemclienthelper.resourcepreloader"));
ConfigSection rplSection = new ConfigSection(configScreen, new TranslatableText("key.lemclienthelper.resourcepreloader"));

displaySection.addConfigItem(new TextItem(new TranslatableText("key.lemclienthelper.downloadurl"), config.URL, ResourcePreloaderConfig.DEFAULT_URL).setMaxLength(1024).setSaveConsumer(val -> config.URL = val));
displaySection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.allowOptifine"), config.allowOptifine, false).setSaveConsumer(val -> config.allowOptifine = val));
displaySection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.multiDownload"), config.multiDownload, true).setSaveConsumer(val -> config.multiDownload = val));
displaySection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.toastcomplete"), config.toastComplete, true).setSaveConsumer(val -> config.toastComplete = val));
rplSection.addConfigItem(new TextItem(new TranslatableText("key.lemclienthelper.downloadurl"), config.URL, ResourcePreloaderConfig.DEFAULT_URL).setMaxLength(1024).setSaveConsumer(val -> config.URL = val));
rplSection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.allowOptifine"), config.allowOptifine, false).setSaveConsumer(val -> config.allowOptifine = val));
rplSection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.multiDownload"), config.multiDownload, true).setSaveConsumer(val -> config.multiDownload = val));
rplSection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.toastcomplete"), config.toastComplete, true).setSaveConsumer(val -> config.toastComplete = val));

rplSection.addConfigItem(new ButtonItem(new TranslatableText("key.lemclienthelper.deletePacks")).setClickEvent(() -> {
configScreen.save();
ResourcePreloader.deletePacks();
}));

SubItem<?> sub = new SubItem<>(new TranslatableText("key.lemclienthelper.packdownloads"), true);

displaySection.addConfigItem(new ButtonItem(new TranslatableText("key.lemclienthelper.previewList")).setClickEvent(() -> {
rplSection.addConfigItem(new ButtonItem(new TranslatableText("key.lemclienthelper.previewList")).setClickEvent(() -> {
configScreen.save();
ResourcePreloader.getPackList();
addPacksToSub(sub);
}));

displaySection.addConfigItem(new ButtonItem(new TranslatableText("key.lemclienthelper.startdownload")).setClickEvent(() -> {
rplSection.addConfigItem(new ButtonItem(new TranslatableText("key.lemclienthelper.startdownload")).setClickEvent(() -> {
configScreen.save();
ResourcePreloader.getPackList();
ResourcePreloader.downloadPacks();
addPacksToSub(sub);
}));

displaySection.addConfigItem(sub);
rplSection.addConfigItem(sub);
addPacksToSub(sub);

ConfigSection smallInvSection = new ConfigSection(configScreen, new TranslatableText("key.lemclienthelper.smallinv"));
smallInvSection.addConfigItem(new BooleanItem(new TranslatableText("key.lemclienthelper.smallinv.enabled"), SmallInvInit.getConfig().enabled, true).setSaveConsumer(val -> SmallInvInit.getConfig().enabled = val));

return configScreen;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.kyrptonaught.lemclienthelper.mixin.SmallInv;

import eu.midnightdust.midnightcontrols.client.controller.InputHandlers;
import net.minecraft.screen.slot.Slot;
import org.aperlambda.lambdacommon.utils.Pair;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Pseudo
@Mixin(InputHandlers.class)
public class MidnightControlsMixin {

@Inject(method = "lambda$handleInventorySlotPad$5", at = @At(value = "HEAD"), cancellable = true)
private static void skipDisabledSlots(int guiLeft, int guiTop, double mouseX, double mouseY, Slot mouseSlot, int direction, Pair<Slot, Double> entry, CallbackInfoReturnable<Boolean> cir) {
if (!entry.key.isEnabled()) cir.setReturnValue(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package net.kyrptonaught.lemclienthelper.mixin.SmallInv;

import net.kyrptonaught.lemclienthelper.SmallInv.MovableSlot;
import net.kyrptonaught.lemclienthelper.SmallInv.SmallInvInit;
import net.kyrptonaught.lemclienthelper.SmallInv.SmallInvPlayerInv;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
Expand Down
Loading

0 comments on commit 6c38dfd

Please sign in to comment.