generated from FabricMC/fabric-example-mod
-
-
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 pull request #18 from cabbagegod/a1.3+1.18.2
A1.3+1.18.2
- Loading branch information
Showing
17 changed files
with
265 additions
and
23 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
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
86 changes: 86 additions & 0 deletions
86
src/main/java/com/cabbagegod/cabbagescape/client/LevelUpManager.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,86 @@ | ||
package com.cabbagegod.cabbagescape.client; | ||
|
||
import com.cabbagegod.cabbagescape.data.DataHandler; | ||
import com.cabbagegod.cabbagescape.data.Skill; | ||
import com.cabbagegod.cabbagescape.util.ScreenshotUtil; | ||
import com.cabbagegod.cabbagescape.util.ThreadingUtil; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.text.LiteralText; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LevelUpManager { | ||
private static String lastLevelUpMessage = ""; | ||
private static List<Skill> skills; | ||
|
||
//These are used for checking if the player has received a level up | ||
private static String lastSkill; | ||
private static int lastLevel; | ||
|
||
//Called from ChatHudMixin every time a new chat message has been received by the client | ||
public static void receiveMessage(String message){ | ||
if(skills == null) | ||
populateSkills(); | ||
|
||
String lowerMessage = message.toLowerCase(); | ||
|
||
//Check if the received message is a "level up" notification | ||
//Second check ensures it's not coming from a player typing the message.. | ||
if(lowerMessage.contains("level is now") && !lowerMessage.contains("[")){ | ||
Skill currentSkill = checkStringForSkill(lowerMessage); | ||
if(currentSkill != null){ | ||
int currentLevel = Integer.parseInt(lowerMessage.replaceAll("[^0-9]", "")); | ||
|
||
//Make sure the message is not for the same level up as the last | ||
if(!currentSkill.name.equals(lastSkill) || lastLevel != currentLevel){ | ||
lastSkill = currentSkill.name; | ||
lastLevel = currentLevel; | ||
|
||
CabbageScapeClient.takeScreenshotAfterDelayOnMainThread(300); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void populateSkills(){ | ||
if(skills != null) | ||
return; | ||
|
||
skills = new ArrayList<>(); | ||
|
||
skills.add(new Skill("attack")); | ||
skills.add(new Skill("strength")); | ||
skills.add(new Skill("defence")); | ||
skills.add(new Skill("ranged")); | ||
skills.add(new Skill("prayer")); | ||
skills.add(new Skill("magic")); | ||
skills.add(new Skill("runecrafting")); | ||
skills.add(new Skill("construction")); | ||
skills.add(new Skill("hitpoints")); | ||
skills.add(new Skill("agility")); | ||
skills.add(new Skill("herblore")); | ||
skills.add(new Skill("thieving")); | ||
skills.add(new Skill("crafting")); | ||
skills.add(new Skill("fletching")); | ||
skills.add(new Skill("slayer")); | ||
skills.add(new Skill("hunter")); | ||
skills.add(new Skill("mining")); | ||
skills.add(new Skill("smithing")); | ||
skills.add(new Skill("fishing")); | ||
skills.add(new Skill("cooking")); | ||
skills.add(new Skill("firemaking")); | ||
skills.add(new Skill("woodcutting")); | ||
skills.add(new Skill("farming")); | ||
} | ||
|
||
private static Skill checkStringForSkill(String string){ | ||
for(Skill skill : skills){ | ||
if(string.contains(skill.name)){ | ||
return skill; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/cabbagegod/cabbagescape/data/DelayedScreenshot.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,11 @@ | ||
package com.cabbagegod.cabbagescape.data; | ||
|
||
public class DelayedScreenshot { | ||
public int msDelay; | ||
public long startTime; | ||
|
||
public DelayedScreenshot(int msDelay, long startTime){ | ||
this.msDelay = msDelay; | ||
this.startTime = startTime; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.cabbagegod.cabbagescape.data; | ||
|
||
public class Skill { | ||
public String name; | ||
|
||
public Skill(String name){ | ||
this.name = name; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/cabbagegod/cabbagescape/mixin/ChatHudMixin.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,21 @@ | ||
package com.cabbagegod.cabbagescape.mixin; | ||
|
||
import com.cabbagegod.cabbagescape.client.LevelUpManager; | ||
import net.minecraft.client.gui.hud.ChatHud; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
//Used to read chat messages | ||
//If any other systems are going to use this then the message should be fed into a central system that | ||
//other systems can read from instead of going to differently classes directly. | ||
|
||
@Mixin(ChatHud.class) | ||
public class ChatHudMixin { | ||
@Inject(at = @At("RETURN"), method = "addMessage(Lnet/minecraft/text/Text;)V") | ||
public void addMessage(Text message, CallbackInfo ci){ | ||
LevelUpManager.receiveMessage(message.getString()); | ||
} | ||
} |
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
Oops, something went wrong.