forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hannibal002:beta' into item-stack-size
- Loading branch information
Showing
5 changed files
with
128 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/at/hannibal2/skyhanni/config/features/stranded/StrandedConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package at.hannibal2.skyhanni.config.features.stranded; | ||
|
||
import at.hannibal2.skyhanni.config.FeatureToggle; | ||
import com.google.gson.annotations.Expose; | ||
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; | ||
import io.github.moulberry.moulconfig.annotations.ConfigOption; | ||
|
||
public class StrandedConfig { | ||
@Expose | ||
@ConfigOption(name = "Highlight Placeable NPCs", desc = "Highlight NPCs that can be placed, but aren't, in the NPC menu.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean highlightPlaceableNpcs = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/at/hannibal2/skyhanni/features/stranded/HighlightPlaceableNpcs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package at.hannibal2.skyhanni.features.stranded | ||
|
||
import at.hannibal2.skyhanni.SkyHanniMod | ||
import at.hannibal2.skyhanni.events.GuiContainerEvent | ||
import at.hannibal2.skyhanni.events.InventoryCloseEvent | ||
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent | ||
import at.hannibal2.skyhanni.utils.InventoryUtils | ||
import at.hannibal2.skyhanni.utils.ItemUtils.getLore | ||
import at.hannibal2.skyhanni.utils.LorenzColor | ||
import at.hannibal2.skyhanni.utils.LorenzUtils | ||
import at.hannibal2.skyhanni.utils.RenderUtils.highlight | ||
import net.minecraftforge.fml.common.eventhandler.EventPriority | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
|
||
class HighlightPlaceableNpcs { | ||
private val config get() = SkyHanniMod.feature.stranded.highlightPlaceableNpcs | ||
private val locationPattern = "§7Location: §f\\[§e\\d+§f, §e\\d+§f, §e\\d+§f]".toPattern() | ||
|
||
private var inInventory = false | ||
private var highlightedItems = emptyList<Int>() | ||
|
||
@SubscribeEvent | ||
fun onInventoryOpen(event: InventoryFullyOpenedEvent) { | ||
inInventory = false | ||
if (!isEnabled()) return | ||
|
||
if (event.inventoryName != "Island NPCs") return | ||
|
||
val highlightedItems = mutableListOf<Int>() | ||
for ((slot, stack) in event.inventoryItems) { | ||
if (isPlaceableNpc(stack.getLore())) { | ||
highlightedItems.add(slot) | ||
} | ||
} | ||
inInventory = true | ||
this.highlightedItems = highlightedItems | ||
} | ||
|
||
@SubscribeEvent | ||
fun onInventoryClose(event: InventoryCloseEvent) { | ||
inInventory = false | ||
highlightedItems = emptyList() | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOW) | ||
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { | ||
if (!isEnabled() || !inInventory) return | ||
for (slot in InventoryUtils.getItemsInOpenChest()) { | ||
if (slot.slotIndex in highlightedItems) { | ||
slot highlight LorenzColor.GREEN | ||
} | ||
} | ||
} | ||
|
||
private fun isPlaceableNpc(lore: List<String>): Boolean { | ||
// Checking if NPC & placeable | ||
if (lore.isEmpty() || !(lore.last() == "§ethis NPC!" || lore.last() == "§eyour location!")) { | ||
return false | ||
} | ||
|
||
// Checking if is already placed | ||
for (line in lore) { | ||
if (locationPattern.matcher(line).matches()) return false | ||
} | ||
return true | ||
} | ||
|
||
private fun isEnabled() = LorenzUtils.inSkyBlock && config | ||
} |