Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Feature: Auto-refill (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordyrat authored Sep 12, 2024
2 parents fe3afb1 + a4faa85 commit f0113c7
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/com/ratons/Ratons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.ratons
import at.hannibal2.skyhanni.deps.moulconfig.managed.ManagedConfig
import at.hannibal2.skyhanni.events.SecondPassedEvent
import com.ratons.commands.Commands
import com.ratons.config.Features
import com.ratons.features.misc.ExampleFeature
import com.ratons.config.features.Features
import com.ratons.features.instances.PearlRefill
import net.minecraft.client.Minecraft
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Mod
Expand All @@ -29,7 +29,7 @@ class Ratons {
this,

// features
ExampleFeature,
PearlRefill,

).loadModules()

Expand Down
20 changes: 0 additions & 20 deletions src/main/kotlin/com/ratons/config/ExampleCategory.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.ratons.config;
package com.ratons.config.features;

import at.hannibal2.skyhanni.deps.moulconfig.Config;
import at.hannibal2.skyhanni.deps.moulconfig.annotations.Category;
import com.ratons.Ratons;
import com.google.gson.annotations.Expose;
import com.ratons.config.features.instances.InstancesConfig;

public class Features extends Config {

Expand All @@ -23,7 +24,7 @@ public void saveNow() {
}

@Expose
@Category(name = "Example", desc = "")
public ExampleCategory exampleCategory = new ExampleCategory();
@Category(name = "Instances", desc = "Features for instanced content.")
public InstancesConfig instancesConfig = new InstancesConfig();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ratons.config.features.instances;

import at.hannibal2.skyhanni.deps.moulconfig.annotations.ConfigEditorBoolean;
import at.hannibal2.skyhanni.deps.moulconfig.annotations.ConfigOption;
import com.google.gson.annotations.Expose;

public class AutoRefillConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "Automatically refill items at the start of an instance (Required for below options).")
@ConfigEditorBoolean
public boolean enabled = false;

@Expose
@ConfigOption(name = "Refill Peals", desc = "Enables auto refill for Ender Pearls.")
@ConfigEditorBoolean
public boolean refillPearls = false;

@Expose
@ConfigOption(name = "Refill Decoys", desc = "Enables auto refill for Decoys on F4/M4.")
@ConfigEditorBoolean
public boolean refillDecoys = false;

@Expose
@ConfigOption(name = "Refill Inflatable Jerrys", desc = "Enables auto refill for Inflatable Jerrys on M7.")
@ConfigEditorBoolean
public boolean refillJerrys = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ratons.config.features.instances;

import at.hannibal2.skyhanni.deps.moulconfig.annotations.Accordion;
import at.hannibal2.skyhanni.deps.moulconfig.annotations.ConfigOption;
import com.google.gson.annotations.Expose;

public class InstancesConfig {

@ConfigOption(name = "Auto Refill", desc = "")
@Accordion
@Expose
public AutoRefillConfig autoRefill = new AutoRefillConfig();

}
58 changes: 58 additions & 0 deletions src/main/kotlin/com/ratons/features/instances/AutoRefill.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.ratons.features.instances

import at.hannibal2.skyhanni.api.GetFromSackAPI
import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
import at.hannibal2.skyhanni.events.DungeonStartEvent
import at.hannibal2.skyhanni.events.KuudraEnterEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.dungeon.DungeonFloor
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import com.ratons.Ratons
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

@Suppress("SkyHanniModuleInspection")
object PearlRefill {

private val config get() = Ratons.feature.instancesConfig.autoRefill

init {
Refillables.entries
}

@SubscribeEvent
fun onDungeonStart(event: DungeonStartEvent) {
newInstance()
}

@SubscribeEvent
fun onKuudraStart(event: KuudraEnterEvent) {
val enter = SimpleTimeMark.now()
while (enter.passedSince() < 10.seconds) return
newInstance()
}

private fun newInstance() {
if (!config.enabled) return
for (it in Refillables.entries) {
if (!config.refillPearls && it.internalName == "ENDER_PEARL") return
if (it.internalName == "DUNGEON_DECOY" && (!config.refillDecoys || DungeonAPI.getCurrentBoss() != DungeonFloor.F4)) return
if (it.internalName == "INFLATABLE_JERRY" && (!config.refillJerrys || DungeonAPI.dungeonFloor!! != "M7")) return

val amount = it.internalName.asInternalName().getAmountInInventory()
val difference = it.stackSize - amount

if (it.internalName.asInternalName().getAmountInSacks() < difference) {
ChatUtils.chat("You do not have enough items to refill ${it.displayName}(s).")
return
}
if (difference > 0) {
GetFromSackAPI.getFromSack(it.internalName.asInternalName(), difference)
}
}

}
}
11 changes: 11 additions & 0 deletions src/main/kotlin/com/ratons/features/instances/Refillables.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ratons.features.instances

enum class Refillables(
val internalName: String,
val displayName: String,
val stackSize: Int,
) {
ENDER_PEARL("ENDER_PEARL", "§fEnder Pearl", 16),
DECOY("DUNGEON_DECOY", "§aDecoy", 64),
INFLATABLE_JERRY("INFLATABLE_JERRY", "§fInflatable Jerry", 64),
}
19 changes: 0 additions & 19 deletions src/main/kotlin/com/ratons/features/misc/ExampleFeature.kt

This file was deleted.

0 comments on commit f0113c7

Please sign in to comment.