Skip to content

Commit

Permalink
Merge pull request #18 from cabbagegod/a1.3+1.18.2
Browse files Browse the repository at this point in the history
A1.3+1.18.2
  • Loading branch information
cabbagegod authored Jun 7, 2022
2 parents 6b33534 + e9db76f commit 3f5eb9b
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* Build Mode Toggle keybinding
* Gound Items (/grounditems)
* Clue Helper
* *Beta* Potion Timers
* Custom settings menu (find it in the [Esc] menu!)

Planned:
* Potion Timers
* HP Notifier
* Better Custom UI
* Expansion of ground items functionality
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.13.3

# Mod Properties
mod_version = pre-a1.1.1+1.18.2
mod_version = a1.3+1.18.2
maven_group = com.example
archives_base_name = cabbagescape

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,41 @@
import com.cabbagegod.cabbagescape.client.potiontimers.PotionTimerManager;
import com.cabbagegod.cabbagescape.commands.Commands;
import com.cabbagegod.cabbagescape.data.DataHandler;
import com.cabbagegod.cabbagescape.data.DelayedScreenshot;
import com.cabbagegod.cabbagescape.data.Settings;
import com.cabbagegod.cabbagescape.notifications.NotificationManager;
import com.cabbagegod.cabbagescape.ui.UpdateScreen;
import com.cabbagegod.cabbagescape.util.FileUtil;
import com.cabbagegod.cabbagescape.util.ScreenshotUtil;
import com.cabbagegod.cabbagescape.util.ThreadingUtil;
import com.google.gson.Gson;
import jdk.jshell.spi.ExecutionControl;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gl.SimpleFramebuffer;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.util.ScreenshotRecorder;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.LiteralText;
import org.lwjgl.glfw.GLFW;

import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class CabbageScapeClient implements ClientModInitializer {
public static String settingsDir = "settings";
public static String version = "pre-a1.1.1+1.18.2";
public static String version = "a1.3+1.18.2";
public static Settings settings;

public static NotificationManager notificationManager;
Expand All @@ -43,6 +61,8 @@ public void onInitializeClient() {

notificationManager = new NotificationManager(settings.notificationSettings);



Commands.register();
setupEvents();
EventRegisterer.register();
Expand Down Expand Up @@ -78,6 +98,8 @@ public static void saveSettings(){
//In the future these should probably get moved into their own classes
private void setupEvents(){
ClientTickEvents.END_CLIENT_TICK.register(client -> {
delayedScreenshotQueue();

if(client.world != null) {
checkKeyPress(client);
}
Expand All @@ -102,7 +124,35 @@ private void checkKeyPress(MinecraftClient client){
client.player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
}
if(debugKey.wasPressed()){
//
NativeImage image = ScreenshotRecorder.takeScreenshot(client.getFramebuffer());
try {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss");;
String currentDate = dateFormat.format(LocalDateTime.now());

String screenshotDir = FileUtil.directoryPath + "screenshots/";
FileUtil.CreateNewDirecotryIfNotExists(screenshotDir);
image.writeTo(new File(screenshotDir + currentDate + ".png"));
} catch (IOException exception) {
exception.printStackTrace();
}
}
}

//Allows you to take a screenshot from another thread and or with a delay
public static void takeScreenshotAfterDelayOnMainThread(int msDelay){
screenshotQueue.add(new DelayedScreenshot(msDelay, System.currentTimeMillis()));
}

static List<DelayedScreenshot> screenshotQueue = new ArrayList<>();
private void delayedScreenshotQueue(){
for (int i = screenshotQueue.size() - 1; i >= 0; i--) {
DelayedScreenshot currentDelay = screenshotQueue.get(i);

if(currentDelay.startTime + currentDelay.msDelay < System.currentTimeMillis()){
ScreenshotUtil.saveScreenshot();

screenshotQueue.remove(i);
}
}
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public void register(){
//Blame bandit for this
for(ItemLore lore : itemLores){
for(ItemExtra extra : lore.getExtra()){
//Checks if there is no clue id, like in the test server (thanks zombie :P)
if(extra.getExtra() == null)
break;

for(ItemExtra__1 extra2 : extra.getExtra()) {
try {
clueId = Integer.parseInt(extra2.getText().replaceAll("[\\D]", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ private static void CheckArmorStands(MinecraftClient client){

//If the user's list of tags contains the name of the item that the armor stand is holding
if(settings.groundItemSettings.searchTags.contains(Formatting.strip(itemStack.getName().getString().toLowerCase()))){
DisplayGroundItem(itemPos, settings.groundItemSettings.volume);
DisplayGroundItem(itemPos, settings.groundItemSettings.volume, false);
} else {
boolean playSound = true;
for(String tag : settings.groundItemSettings.containsTags){
if(Objects.requireNonNull(Formatting.strip(itemStack.getName().getString().toLowerCase())).contains(tag)){
DisplayGroundItem(itemPos, settings.groundItemSettings.volume);
DisplayGroundItem(itemPos, settings.groundItemSettings.volume, playSound);
playSound = false;
break;
}
}
Expand All @@ -93,15 +95,16 @@ private static void CheckArmorStands(MinecraftClient client){
}
}

private static void DisplayGroundItem(BlockPos itemPos, float volume){
private static void DisplayGroundItem(BlockPos itemPos, float volume, boolean playSound){
GroundItemSettings settings = CabbageScapeClient.settings.groundItemSettings;

//Get the center of the block that the item is on
Vector3f itemPosCenter = new Vector3f(itemPos.getX() + .5f, itemPos.getY(), itemPos.getZ() + .5f);

assert MinecraftClient.getInstance().player != null;

MinecraftClient.getInstance().player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, volume, 1);
if(playSound)
MinecraftClient.getInstance().player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, volume, 1);

if(settings.spiralEnabled) {
ParticleUtil.CreateSpiralParticle(itemPosCenter, new Color((int) settings.itemRed, (int) settings.itemGreen, (int) settings.itemBlue), (int) settings.particleCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void register(){
float volume = FloatArgumentType.getFloat(context, "num");

CabbageScapeClient.settings.groundItemSettings.volume = volume;
CabbageScapeClient.saveSettings();

return 1;
})))
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/com/cabbagegod/cabbagescape/data/DataHandler.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.cabbagegod.cabbagescape.data;

import org.apache.commons.lang3.StringUtils;
import com.cabbagegod.cabbagescape.util.FileUtil;

import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;

public class DataHandler {
public static void WriteStringToFile(String data, String fileName){
FileUtil.CreateDefaultDirectoryIfNotExists();
String directoryPath = FileUtil.directoryPath;

try {
FileWriter myWriter = new FileWriter(fileName + ".txt");
FileWriter myWriter = new FileWriter(directoryPath + fileName + ".txt");
myWriter.write(data);
myWriter.close();
System.out.println("Successfully wrote to the file.");
Expand All @@ -22,18 +27,14 @@ public static void WriteStringToFile(String data, String fileName){
}

public static String ReadStringFromFile(String fileName){
FileUtil.CreateDefaultDirectoryIfNotExists();
String directoryPath = FileUtil.directoryPath;

String text = "";
try {
File myObj = new File(fileName + ".txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
text += data;
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
text = Files.readString(Paths.get(directoryPath + fileName + ".txt"));
} catch (IOException exception) {
exception.printStackTrace();
}
return text;
}
Expand Down
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;
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/cabbagegod/cabbagescape/data/Settings.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.cabbagegod.cabbagescape.data;

import com.cabbagegod.cabbagescape.client.CabbageScapeClient;

import java.util.ArrayList;
import java.util.List;

public class Settings {
public String lastVersion = "";
public String lastVersion = CabbageScapeClient.version;
public GroundItemSettings groundItemSettings = new GroundItemSettings();
public NotificationSettings notificationSettings = new NotificationSettings();

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/cabbagegod/cabbagescape/data/Skill.java
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 src/main/java/com/cabbagegod/cabbagescape/mixin/ChatHudMixin.java
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {

//The color picker texture
int x = width / 2 + 132 + 32;
int y = 40;
int y = 56;
drawTexture(matrices, x,y,0,0,32,32);

drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 5, 16777215);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.fabricmc.loader.language.LanguageAdapter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonListWidget;
Expand Down Expand Up @@ -37,6 +38,10 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
//this.client.setScreen(new OptionsScreen(this, this.client.options));
MinecraftClient.getInstance().setScreen(new GroundItemsScreen(this, this.client.options, CabbageScapeClient.settings));
}));
addDrawableChild(new ButtonWidget(this.width / 2 - 102, this.height / 4 + 96 + 16, 204, 20, new LiteralText("Done"), button -> {
MinecraftClient.getInstance().setScreen(new GameMenuScreen(true));
}));


super.render(matrices, mouseX, mouseY, delta);
}
Expand Down
Loading

0 comments on commit 3f5eb9b

Please sign in to comment.