Skip to content

Commit

Permalink
fixes #64,
Browse files Browse the repository at this point in the history
  • Loading branch information
blackd committed Nov 18, 2021
1 parent 7f4a45f commit 889eda6
Show file tree
Hide file tree
Showing 51 changed files with 1,276 additions and 228 deletions.
8 changes: 5 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<!-- latest begin -->

### 1.1.5
- fixed move all when key binding is set to "ctrl + alt + q"
- the hotbar now shows the locked slots.
- new setting (enabled by default) to disable drop for locked slots containing non-stackable items.
prevents accidental drops of gear.
- fixed "move all" when key binding is set to "ctrl + alt + q"
- some changes under the hood
- added updates check. The check is done once you enter a word/connect ot a server and message is displayed if there is new version available.
- added analytics. What data is collected? Once a session we collect information about the version of the mod and what features of the mod are used. We do not store any personal information. Your IP is not stored. The data will not be sold or transferred or shared with anyone.
- both of the above can be disabled in the mod Settings.


<!-- latest end -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class ConfigInteger(defaultValue: Int,
get() = value
}

open class ConfigBoolean(final override val defaultValue: Boolean) :
ConfigOptionBase(), IConfigOptionPrimitive<Boolean>, IConfigOptionToggleable {
open class ConfigBoolean(final override val defaultValue: Boolean): ConfigOptionBase(), IConfigOptionPrimitive<Boolean>, IConfigOptionToggleable {
override var value = defaultValue
override fun toggleNext() = run { value = !value }
override fun togglePrevious() = run { value = !value }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.anti_ad.mc.common.input

import org.anti_ad.mc.common.IInputHandler
import org.anti_ad.mc.common.Log
import org.anti_ad.mc.common.gui.debug.DebugInfos
import org.anti_ad.mc.common.vanilla.glue.VanillaUtil

Expand All @@ -18,6 +19,10 @@ object GlobalInputHandler {
var lastAction = -1 // only GLFW_PRESS or GLFW_RELEASE
private set

fun isWaitingForRelease(key: Int): Boolean {
return pressedKeys.contains(key)
}

fun isActivated(keyCodes: List<Int>,
settings: KeybindSettings): Boolean {
if (keyCodes.isEmpty()) return false
Expand All @@ -43,14 +48,18 @@ object GlobalInputHandler {

private fun onKey(key: Int,
action: Int): Boolean { // action: only GLFW_PRESS or GLFW_RELEASE

val isPress = action == GLFW_PRESS
if (isPress == pressedKeys.contains(key)) // (PRESS && contain) || (RELEASE && !contain)
if (isPress == pressedKeys.contains(key)) { // (PRESS && contain) || (RELEASE && !contain)
return false // should err / cancelled by other mod
}

previousPressedKeys = pressedKeys.toSet()
if (isPress)
if (isPress) {
pressedKeys.add(key)
else
} else {
pressedKeys.remove(key)
}
lastKey = key
lastAction = action
return onInput()
Expand All @@ -61,10 +70,8 @@ object GlobalInputHandler {
handleAssignKeybind()
return true
}
if (registeredCancellable.any {
it.onInput(lastKey,
lastAction)
}) {
if (registeredCancellable.any { it.onInput(lastKey,
lastAction) }) {
return true
}
registered.forEach {
Expand All @@ -87,9 +94,7 @@ object GlobalInputHandler {
private var ignoreLeftClick = false // fix forge version while compatible with fabric version

private fun handleAssignKeybind() {
val pressedKeys: List<Int> = currentAssigningKeybind
?.run { settings.modifierKey.handleKeys(pressedKeys.toList()) }
?: pressedKeys.toList()
val pressedKeys: List<Int> = currentAssigningKeybind?.run { settings.modifierKey.handleKeys(pressedKeys.toList()) } ?: pressedKeys.toList()
if (lastAction == GLFW_PRESS) {
if (lastKey == KeyCodes.MOUSE_BUTTON_1 && ignoreLeftClick) { // GLFW_MOUSE_BUTTON_1 - 100
return
Expand Down
39 changes: 30 additions & 9 deletions common/src/main/java/org/anti_ad/mc/common/input/Keybinds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.anti_ad.mc.common.input.KeybindSettings.ModifierKey.NORMAL

class MainKeybind(defaultStorageString: String,
override val defaultSettings: KeybindSettings) : IKeybind {

override val defaultKeyCodes = IKeybind.getKeyCodes(defaultStorageString)
override var keyCodes = defaultKeyCodes
override var settings = defaultSettings
Expand Down Expand Up @@ -67,16 +68,24 @@ interface IKeybind : IConfigElementObject {
override val isModified
get() = isKeyCodesModified || isSettingsModified

fun resetKeyCodesToDefault() = run { keyCodes = defaultKeyCodes }
fun resetSettingsToDefault() = run { settings = defaultSettings }
fun resetKeyCodesToDefault() {
keyCodes = defaultKeyCodes
}

fun resetSettingsToDefault() {
settings = defaultSettings
}

override fun resetToDefault() {
resetKeyCodesToDefault()
resetSettingsToDefault()
}

fun KeybindSettings.toConfigElement() = ConfigKeybindSettings(defaultSettings,
this)

fun KeybindSettings.toJsonElement() = toConfigElement().toJsonElement()

fun KeybindSettings.fromJsonElement(element: JsonElement): KeybindSettings {
return toConfigElement().apply { fromJsonElement(element) }.settings
}
Expand All @@ -89,25 +98,37 @@ interface IKeybind : IConfigElementObject {
this["settings"] = settings.toJsonElement()
}
})

override fun fromJsonObject(obj: JsonObject) {
try {
obj["settings"]
?.let { settings = settings.fromJsonElement(it) }
obj["keys"]
?.let { keyCodes = getKeyCodes(it.jsonPrimitive.content) }
obj["settings"]?.let {
settings = settings.fromJsonElement(it)
}
obj["keys"]?.let {
keyCodes = getKeyCodes(it.jsonPrimitive.content)
}
} catch (e: Exception) {
Log.warn("Failed to set config value for 'keys' from the JSON element '${obj["keys"]}'")
}
}


companion object {

fun getStorageString(keyCodes: List<Int>) = keyCodes.joinToString(",") { KeyCodes.getName(it) }

fun getDisplayText(keyCodes: List<Int>) = keyCodes.joinToString(" + ") { KeyCodes.getFriendlyName(it) }

fun getDisplayTextModifier(keyCodes: List<Int>) = keyCodes.joinToString(" + ") { KeyCodes.getModifierName(it) }

fun getKeyCodes(storageString: String): List<Int> =
storageString.split(",")
.map { KeyCodes.getKeyCode(it.trim()) }
.filter { it != -1 }.distinct()
storageString
.split(",")
.map {
KeyCodes.getKeyCode(it.trim())
}
.filter {
it != -1
}.distinct()
}
}
22 changes: 15 additions & 7 deletions common/src/main/java/org/anti_ad/mc/common/moreinfo/InfoManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.anti_ad.mc.common.moreinfo
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToJsonElement
import org.anti_ad.mc.common.Log
import org.anti_ad.mc.common.extensions.orDefault
import java.net.URL
import java.util.concurrent.*

Expand All @@ -17,15 +16,20 @@ object InfoManager {
var modName = "name-missing"
var loader: String = "loader-missing"

val defaultRequest: Map<String, String> = mapOf("domain" to "ipn-stats.anti-ad.org",
private val defaultRequest: Map<String, String> = mapOf("domain" to "ipn-stats.anti-ad.org",
"name" to "pageview")
val session: MutableMap<String, String> = mutableMapOf()
val target = URL("https://p.anti-ad.org/api/event")
private val session: MutableMap<String, String> = mutableMapOf()
private val target = URL("https://p.anti-ad.org/api/event")

val versionUrl = URL("https://github.com/blackd/Inventory-Profiles/releases/latest")
private val versionUrl = URL("https://ipn.anti-ad.org/ipn/versionCheckV2")

var isEnabled: () -> Boolean = { true }

private val isBeta by lazy { version.contains("BETA") }
private val currentVer by lazy { SemVer.parse(if (isBeta) version.substringBefore("-") else { version }) }
private val mcVersionClean by lazy { mcVersion.split(".").joinToString(separator = "") }


private val executor = Executors.newFixedThreadPool(2)


Expand Down Expand Up @@ -79,6 +83,7 @@ object InfoManager {

requestMethod = "POST"
setRequestProperty("Content-Type", "application/json; utf-8")
setRequestProperty("User-Agent", "Minecraft/$mcVersionClean IPN/${currentVer.major}${currentVer.minor}${currentVer.patch}")
setRequestProperty("Content-Length", bodyBytes.size.toString())
doOutput = true

Expand Down Expand Up @@ -108,9 +113,12 @@ object InfoManager {
with(versionUrl.openConnection() as HttpsURLConnection) {
val isBeta = version.contains("BETA")
val currentVer = SemVer.parse(if (isBeta) version.substringBefore("-") else { version })
setRequestProperty("User-Agent", "Minecraft/$mcVersion; $loader; IPN/$currentVer;" + if (isBeta) " Beta" else "")

instanceFollowRedirects = false
if (responseCode == 302) {
val latestVer = SemVer.parse(getHeaderField("location").orDefault { "" }.substringAfterLast("/", version).substringAfter("v"))
val xIpn = getHeaderField("X-IPN")
if (responseCode == 302 && xIpn != null) {
val latestVer = SemVer.parse(xIpn)
if (latestVer > latestVer || (isBeta && latestVer >= currentVer) ) {
function(latestVer, currentVer, isBeta)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,33 @@ fun rDrawCenteredSprite(sprite: Sprite,
location.y)

fun rDrawCenteredSprite(sprite: Sprite,
tIndex: Int,
location: Point) = rDrawCenteredSprite(sprite,
tIndex,
location.x,
location.y)


fun rDrawCenteredSprite(sprite: Sprite,
tIndex: Int,
x: Int,
y: Int) {
val (w, h) = sprite.size
__glue_rDrawSprite(sprite,
0,
tIndex,
x - w / 2,
y - h / 2)
}

fun rDrawCenteredSprite(sprite: Sprite,
x: Int,
y: Int) {
rDrawCenteredSprite(sprite,
0,
x,
y)
}


class IdentifierHolder(var id: Any) {
constructor(ns: String, name: String) : this(__glue_make_Identifier(ns, name))
Expand Down
6 changes: 4 additions & 2 deletions common/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ object ModSettings : ConfigDeclaration {
val LOCK_SLOTS_CONFIG_SWITCH_TYPE /**/ by enum(SwitchType.HOLD)
val SHOW_LOCKED_SLOTS_BACKGROUND /**/ by bool(true)
val SHOW_LOCKED_SLOTS_FOREGROUND /**/ by bool(true)
val LOCKED_SLOTS_FOREGROUND_STYLE /**/ by int(1,
val ALSO_SHOW_LOCKED_SLOTS_IN_HOTBAR /**/ by bool(true)
val LOCKED_SLOTS_FOREGROUND_STYLE /**/ by int(2,
1,
6)
val LOCKED_SLOTS_DISABLE_QUICK_MOVE_THROW /**/ by bool(false)
val LOCKED_SLOTS_DISABLE_THROW_FOR_NON_STACKABLE /**/ by bool(true)
val LOCKED_SLOTS_ALLOW_PICKUP_INTO_EMPTY /**/ by bool(false)
val LOCKED_SLOTS_DELAY_KEEPER_REINIT_TICKS /**/ by int(50,
20,
Expand All @@ -82,7 +84,7 @@ object ModSettings : ConfigDeclaration {

.CATEGORY("$category.privacy")
val ENABLE_UPDATES_CHECK /**/ by bool(true)
val ENABLE_ANALYTICS /**/ by bool(true)
val ENABLE_ANALYTICS /**/ by bool(false)

.CATEGORY("$category.advanced_options")
val ADD_INTERVAL_BETWEEN_CLICKS /**/ by bool(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@
"inventoryprofiles.config.name.lock_slots_config_switch_type": "Config Switch Type",
"inventoryprofiles.config.name.show_locked_slots_background": "Show Locked Slots Background",
"inventoryprofiles.config.name.show_locked_slots_foreground": "Show Locked Slots Foreground",
"inventoryprofiles.config.name.also_show_locked_slots_in_hotbar": "Also Show Locked Slots in Hotbar",
"inventoryprofiles.config.name.locked_slots_foreground_style": "Locked Slots Foreground Style",
"inventoryprofiles.config.name.locked_slots_disable_quick_move_throw": "Disable Shift+Click, Ctrl+Q and Q For Locked Slots",
"inventoryprofiles.config.name.locked_slots_disable_quick_move_throw": "Disable Shift+Click and Ctrl+Q and Q",
"inventoryprofiles.config.name.locked_slots_disable_throw_for_non_stackable": "Disable (Q) Drop For Non-Stackable Locked Slots In Game",
"inventoryprofiles.config.name.locked_slots_allow_pickup_into_empty": "Enable Picking Items into Empty Locked Slots",
"inventoryprofiles.config.name.locked_slots_delay_keeper_reinit_ticks": "Maximum Ticks to Wait on Dimension Change",
"inventoryprofiles.config.description.enable_lock_slots": "Locked slots are ignored for: sort, move all, clean cursor, continuous crafting supplies storage, auto refill supplies storage (auto refill monitoring slots are not affected). \nNotice:\nSorting in columns/rows only works if the shape of remaining non-locked slots is rectangular.",
Expand All @@ -76,6 +78,7 @@
"inventoryprofiles.config.description.lock_slots_config_switch_type": "Set config switch type to toggle or hold",
"inventoryprofiles.config.description.show_locked_slots_background": "Draw locked slots background\n\nYou can create your own texture and put it in\nresourcepacks/§o[pack_name]§r/assets/inventoryprofilesnext/textures/gui/overlay.png",
"inventoryprofiles.config.description.show_locked_slots_foreground": "Draw locked slots foreground\n\nYou can create your own texture and put it in\nresourcepacks/§o[pack_name]§r/assets/inventoryprofilesnext/textures/gui/overlay.png",
"inventoryprofiles.config.description.also_show_locked_slots_in_hotbar": "When enabled locked slots are also rendered in the HUD Hotbar",
"inventoryprofiles.config.description.locked_slots_foreground_style": "Select foreground style from preset\n\nYou can create your own texture and put it in\nresourcepacks/§o[pack_name]§r/assets/inventoryprofilesnext/textures/gui/overlay.png",
"inventoryprofiles.config.description.locked_slots_disable_quick_move_throw": "Locked slots will be immune to:\n - Shift+Click\n - Ctrl+Q\n - Swipe Shift+Click\n - Swipe Ctrl+Q",
"inventoryprofiles.config.description.locked_slots_allow_pickup_into_empty": "Should it be possible to pick items from the ground into EMPTY locked slots.\nStackable items will still be picked into locked sots of the same item that have room.\nNOTE: See next setting description for more information!",
Expand All @@ -89,8 +92,8 @@
"inventoryprofiles.config.name.tool_damage_threshold": "Damage Threshold",
"inventoryprofiles.config.name.threshold_unit": "Threshold Units",
"inventoryprofiles.config.name.auto_refill_wait_tick": "Number of Ticks to Wait Before Auto Refill",
"inventoryprofiles.config.description.enable_updates_check": "We can check for updates and display a message. The check is made by reading the information off github.com",
"inventoryprofiles.config.description.enable_analytics": "Enable Analytics.\nOnly information about the version of the mod and which features are used is collected.\nNO Personal information is sent. Your IP address is not stored.\nNone of the collected information will be shared, sold or transferred to anyone!",
"inventoryprofiles.config.description.enable_updates_check": "Display message if a new version of the mod is available. To do the check we send to our servers ONLY the following information:\n\tMinecraft Version, Fabric or Forge, Inventory Profiles Next version.\nYour IP address is not saved!",
"inventoryprofiles.config.description.enable_analytics": "Enable Analytics.\nOnly information about the mod and which features are used is collected.\nNO Personal information is sent. Your IP address is not stored.\nNone of the collected information will be shared, sold or transferred to anyone!",
"inventoryprofiles.config.description.enable_auto_refill": "Refill the active item when the stack runs out.",
"inventoryprofiles.config.description.disable_for_drop_item": "Disable \"Auto Refill\" for dropped items",
"inventoryprofiles.config.description.refill_armor": "Refill armor slots if items are about to break",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions description/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ This mod will:
<tbody>
<tr>
<td></td>
<td><a href="https://www.patreon.com/mirinimi"> <img src="https://nc.anti-ad.org/cgi-bin/test.png" alt="Patreon Logo"/> </a> </td>
<td>
<td style="vertical-align: middle;"><a href="https://www.patreon.com/mirinimi"> <img src="https://nc.anti-ad.org/cgi-bin/test.png" alt="Patreon Logo"/> </a> </td>
<td style="vertical-align: middle;">
<iframe class="center" src="https://github.com/sponsors/blackd/button" height="35" width="116"></iframe>
</td>
</tr>
Expand Down
Loading

0 comments on commit 889eda6

Please sign in to comment.