-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
should remove an edge case, where the overlay wouldn't turn off at all anymore.
- Loading branch information
1 parent
5fecd28
commit b04c46a
Showing
4 changed files
with
85 additions
and
54 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
68 changes: 68 additions & 0 deletions
68
common/src/main/java/dev/schmarrn/lighty/overlaystate/SMACH.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,68 @@ | ||
package dev.schmarrn.lighty.overlaystate; | ||
|
||
import dev.schmarrn.lighty.config.Config; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.item.Item; | ||
|
||
public class SMACH { | ||
private static State state = State.OFF; | ||
|
||
public static void updateCompute(Minecraft client) { | ||
if (!Config.SHOULD_AUTO_ON.getValue()) { | ||
if (state == State.AUTO || state == State.OVERRIDE) { | ||
// if auto_on is disabled, but we somehow got stuck inside of one of the auto_on states, reset to OFF | ||
state = State.OFF; | ||
} | ||
return; | ||
} | ||
// check whether we are holding an item defined as a valid auto_on item | ||
boolean holdsItem = false; | ||
var activationItems = Config.AUTO_ON_ITEM_LIST.getValue(); | ||
|
||
for (var rl : activationItems) { | ||
Item activationItem = BuiltInRegistries.ITEM.get(rl); | ||
Item mainHandItem = client.player.getMainHandItem().getItem(); | ||
Item offHandItem = client.player.getOffhandItem().getItem(); | ||
|
||
// if we hold the activation item in our hands, set auto enabled to true. | ||
// if we don't, set it to false and if we aren't enabled, return early. | ||
if (mainHandItem == activationItem || offHandItem == activationItem) { | ||
holdsItem = true; | ||
break; | ||
} | ||
} | ||
|
||
// update state: | ||
switch (state) { | ||
case OFF -> { | ||
if (holdsItem) { | ||
state = State.AUTO; | ||
} | ||
} | ||
case ON -> { | ||
// we stay in on, because auto_on should never override on state | ||
} | ||
case AUTO, OVERRIDE -> { | ||
// in both cases AUTO and OVERRIDE, if we let go of the item, we reset to state OFF | ||
if (!holdsItem) { | ||
state = State.OFF; | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
public static void toggle() { | ||
switch (state) { | ||
case OFF -> state = State.ON; | ||
case ON -> state = State.OFF; | ||
case AUTO -> state = State.OVERRIDE; | ||
case OVERRIDE -> state = State.AUTO; | ||
} | ||
} | ||
|
||
public static State getState() { | ||
return state; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
common/src/main/java/dev/schmarrn/lighty/overlaystate/State.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,8 @@ | ||
package dev.schmarrn.lighty.overlaystate; | ||
|
||
public enum State { | ||
OFF, | ||
ON, | ||
AUTO, | ||
OVERRIDE | ||
} |