From 1dd168acd06c9563ba5c5eed6a910d63f39bf210 Mon Sep 17 00:00:00 2001 From: ENORMOUZ Date: Sat, 7 Oct 2023 20:19:09 +0800 Subject: [PATCH 1/4] Add support for Lootrun Update --- build.gradle | 24 ++++--- gradle.properties | 4 ++ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 19 ++++++ .../lootrunstatistics/LootrunStatistics.java | 2 +- .../listeners/ChestOpenListener.java | 66 ++++++++++++++++--- 6 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 gradle.properties create mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle index 9be050a..f3d5f9d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,18 +2,19 @@ buildscript { repositories { maven { url = 'https://maven.minecraftforge.net/' } mavenCentral() - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:3.+' + gradlePluginPortal() } } -apply plugin: 'net.minecraftforge.gradle' -// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -apply plugin: 'eclipse' -apply plugin: 'maven-publish' +plugins { + id "java" + id "idea" + id "maven-publish" + id "net.minecraftforge.gradle" version "5.1.+" + id "com.github.johnrengelman.shadow" version "7.1.0" +} -version = '1.1.1' +version = '1.1.2' group = 'net.mcplayhd.lootrunstatistics' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'lootrunstatistics' @@ -37,6 +38,8 @@ minecraft { client { workingDirectory project.file('run') + property("devauth.configDir", project.file(".devauth").absolutePath) + // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' @@ -55,6 +58,11 @@ minecraft { } } +repositories { + maven { url = "https://maven.minecraftforge.net" } + maven { url = "https://files.minecraftforge.net/maven" } +} + dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..784899a --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +# Sets default memory used for gradle commands. Can be overridden by user or command line properties. +# This is required to provide enough memory for the Minecraft decompilation process. +org.gradle.jvmargs=-Xmx3G +org.gradle.daemon=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 949819d..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..fce6223 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,19 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + maven { url = "https://maven.minecraftforge.net/" } + maven { url = "https://files.minecraftforge.net/maven" } + } + resolutionStrategy { + eachPlugin { + switch (requested.id.id) { + case "net.minecraftforge.gradle": + useModule("net.minecraftforge.gradle:ForgeGradle:${requested.version}") + break + } + } + } +} + +rootProject.name = "LootrunStatistics" \ No newline at end of file diff --git a/src/main/java/net/mcplayhd/lootrunstatistics/LootrunStatistics.java b/src/main/java/net/mcplayhd/lootrunstatistics/LootrunStatistics.java index ff7c1be..4009a81 100644 --- a/src/main/java/net/mcplayhd/lootrunstatistics/LootrunStatistics.java +++ b/src/main/java/net/mcplayhd/lootrunstatistics/LootrunStatistics.java @@ -32,7 +32,7 @@ public class LootrunStatistics { public static final String MODID = "lootrunstatistics"; public static final String NAME = "Lootrun Statistics"; // version needs to be updated here, in resources/version.txt and in build.gradle - public static final String VERSION = "1.1.1"; + public static final String VERSION = "1.1.2"; private static Logger logger; diff --git a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java index 41e3d3e..49e2de6 100644 --- a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java +++ b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java @@ -14,6 +14,8 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.monster.EntitySlime; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerChest; @@ -22,11 +24,14 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.event.entity.living.LivingAttackEvent; +import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.awt.*; +import java.awt.datatransfer.StringSelection; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -51,7 +56,7 @@ private Loc getLastChestLocation() { private EntityPlayerSP getPlayer() { return Minecraft.getMinecraft().player; } - + /* @SubscribeEvent(priority = EventPriority.LOWEST) public void openChest(PlayerInteractEvent.RightClickBlock e) { if (e.isCanceled()) return; @@ -66,6 +71,31 @@ public void openChest(PlayerInteractEvent.RightClickBlock e) { chestLocation = pos.toImmutable(); getLogger().info("Clicked chest at " + chestLocation.getX() + "," + chestLocation.getY() + "," + chestLocation.getZ() + "."); } + */ + + @SubscribeEvent + public void onRightClick(PlayerInteractEvent.EntityInteract event) { + Entity entity = event.getTarget(); + if (entity instanceof EntitySlime) { + BlockPos pos = entity.getPosition(); + chestConsidered = false; + foundItemsUntilSlot = -1; + lastItemArrived = -1; + chestLocation = pos.toImmutable(); + } + } + + @SubscribeEvent + public void onLeftClick(AttackEntityEvent event) { + Entity entity = event.getTarget(); + if (entity instanceof EntitySlime) { + BlockPos pos = entity.getPosition(); + chestConsidered = false; + foundItemsUntilSlot = -1; + lastItemArrived = -1; + chestLocation = pos.toImmutable(); + } + } /* Credits to https://github.com/albarv340/chestcountmod for using the InitGuiEvent to change the title of the chest @@ -81,7 +111,8 @@ public void onGuiOpen(GuiScreenEvent.InitGuiEvent event) { if (!(openContainer instanceof ContainerChest)) return; InventoryBasic lowerInventory = (InventoryBasic) ((ContainerChest) openContainer).getLowerChestInventory(); String containerName = Objects.requireNonNull(TextFormatting.getTextWithoutFormattingCodes(lowerInventory.getName())); - if (containerName.startsWith("Loot Chest") && !containerName.contains("\u00a77\u00a7r") && !chestConsidered) { + + if (containerName.startsWith("Loot Chest") && !containerName.contains("§7§r") && !chestConsidered) { // this is a loot chest, and we did not yet change its name. getChestCountData().addChest(); int totalChests = getChestCountData().getTotalChests(); @@ -90,9 +121,9 @@ public void onGuiOpen(GuiScreenEvent.InitGuiEvent event) { // "\u00a77\u00a7r" is our identifier. // It won't show because it just sets the color and resets it immediately. if (getConfiguration().displayTotalChestCountInChest()) { - lowerInventory.setCustomName(lowerInventory.getName() + "\u00a77\u00a7r" + " #" + getFormatted(totalChests)); + lowerInventory.setCustomName(lowerInventory.getName() + "§7§r" + " #" + getFormatted(totalChests)); } else { - lowerInventory.setCustomName(lowerInventory.getName() + "\u00a77\u00a7r"); + lowerInventory.setCustomName(lowerInventory.getName() + "§7§r"); } } } catch (Throwable throwable) { @@ -150,15 +181,34 @@ public void guiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { if (foundItemsUntilSlot == -1) { // this is the first time we saw an item in this chest getChests().registerOpened(loc); - containerName = containerName.substring("Loot Chest ".length()); - String[] sp = containerName.split(" "); + String[] sp = lowerInventory.getName().substring("Loot Chest ".length()).split(" "); String roman = sp[0]; - int tier = FormatterHelper.convertRomanToArabic(roman); + int tier = 1; + System.out.println(roman); + StringSelection stringSelection = new StringSelection(roman); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); + switch (roman) { + case "§7[§f✫§8✫✫✫§7]§7§r": + System.out.println("type of chest: 1"); + tier = 1; + break; + case "§e[§6✫✫§8✫✫§e]§7§r": + System.out.println("type of chest: 2"); + tier = 2; + break; + case "§5[§d✫✫✫§8✫§5]§7§r": + System.out.println("type of chest: 3"); + tier = 3; + break; + case "§3[§b✫✫✫✫§3]§7§r": + System.out.println("type of chest: 4"); + tier = 4; + break; + } getChests().setTier(loc, tier); } boolean dryDataUpdated = false; // we can now check every slot up until the slot we found the last item in - getLogger().info("Checking from slot " + (foundItemsUntilSlot + 1) + " up to and including slot " + (newFoundItemsUntilSlot)); for (int slot = foundItemsUntilSlot + 1; slot <= newFoundItemsUntilSlot; slot++) { try { // I intentionally cause exceptions because it's more convenient to develop ItemStack itemStack = lowerInventory.getStackInSlot(slot); From 453afa6ec53ab7cf2af4f28c32e11446e5728211 Mon Sep 17 00:00:00 2001 From: ENORMOUZ Date: Sat, 7 Oct 2023 20:20:27 +0800 Subject: [PATCH 2/4] Remove test prints --- .../lootrunstatistics/listeners/ChestOpenListener.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java index 49e2de6..5d6ebb5 100644 --- a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java +++ b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java @@ -189,19 +189,15 @@ public void guiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); switch (roman) { case "§7[§f✫§8✫✫✫§7]§7§r": - System.out.println("type of chest: 1"); tier = 1; break; case "§e[§6✫✫§8✫✫§e]§7§r": - System.out.println("type of chest: 2"); tier = 2; break; case "§5[§d✫✫✫§8✫§5]§7§r": - System.out.println("type of chest: 3"); tier = 3; break; case "§3[§b✫✫✫✫§3]§7§r": - System.out.println("type of chest: 4"); tier = 4; break; } From 8f93877ea12d81fbd79bfbe78f0fd50c755a484a Mon Sep 17 00:00:00 2001 From: ENORMOUZ Date: Sat, 7 Oct 2023 20:32:23 +0800 Subject: [PATCH 3/4] Added challenge support --- .../listeners/ChestOpenListener.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java index 5d6ebb5..9c62cad 100644 --- a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java +++ b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java @@ -112,7 +112,7 @@ public void onGuiOpen(GuiScreenEvent.InitGuiEvent event) { InventoryBasic lowerInventory = (InventoryBasic) ((ContainerChest) openContainer).getLowerChestInventory(); String containerName = Objects.requireNonNull(TextFormatting.getTextWithoutFormattingCodes(lowerInventory.getName())); - if (containerName.startsWith("Loot Chest") && !containerName.contains("§7§r") && !chestConsidered) { + if ((containerName.startsWith("Loot Chest") || containerName.startsWith("Objective Rewards") || containerName.startsWith("Challenge Rewards")) && !containerName.contains("§7§r") && !chestConsidered) { // this is a loot chest, and we did not yet change its name. getChestCountData().addChest(); int totalChests = getChestCountData().getTotalChests(); @@ -141,7 +141,7 @@ public void guiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { if (!(openContainer instanceof ContainerChest)) return; InventoryBasic lowerInventory = (InventoryBasic) ((ContainerChest) openContainer).getLowerChestInventory(); String containerName = Objects.requireNonNull(TextFormatting.getTextWithoutFormattingCodes(lowerInventory.getName())); - if (!containerName.startsWith("Loot Chest")) return; + if (!containerName.startsWith("Loot Chest") && !containerName.startsWith("Objective Rewards") && !containerName.startsWith("Challenge Rewards")) return; if (getConfiguration().displayDryCountInChest()) { // Credits to https://github.com/albarv340/chestcountmod GlStateManager.pushMatrix(); @@ -181,27 +181,26 @@ public void guiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { if (foundItemsUntilSlot == -1) { // this is the first time we saw an item in this chest getChests().registerOpened(loc); - String[] sp = lowerInventory.getName().substring("Loot Chest ".length()).split(" "); - String roman = sp[0]; - int tier = 1; - System.out.println(roman); - StringSelection stringSelection = new StringSelection(roman); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); - switch (roman) { - case "§7[§f✫§8✫✫✫§7]§7§r": - tier = 1; - break; - case "§e[§6✫✫§8✫✫§e]§7§r": - tier = 2; - break; - case "§5[§d✫✫✫§8✫§5]§7§r": - tier = 3; - break; - case "§3[§b✫✫✫✫§3]§7§r": - tier = 4; - break; + if (containerName.startsWith("Loot Chest")) { + String[] sp = lowerInventory.getName().substring("Loot Chest ".length()).split(" "); + String roman = sp[0]; + int tier = 1; + switch (roman) { + case "§7[§f✫§8✫✫✫§7]§7§r": + tier = 1; + break; + case "§e[§6✫✫§8✫✫§e]§7§r": + tier = 2; + break; + case "§5[§d✫✫✫§8✫§5]§7§r": + tier = 3; + break; + case "§3[§b✫✫✫✫§3]§7§r": + tier = 4; + break; + } + getChests().setTier(loc, tier); } - getChests().setTier(loc, tier); } boolean dryDataUpdated = false; // we can now check every slot up until the slot we found the last item in From 860ee2e253ad33d6a28994c3a928b30131cfa150 Mon Sep 17 00:00:00 2001 From: ENORMOUZ Date: Sun, 8 Oct 2023 00:44:51 +0800 Subject: [PATCH 4/4] Fix emerald block --- .../lootrunstatistics/listeners/ChestOpenListener.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java index 9c62cad..a0cb2c4 100644 --- a/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java +++ b/src/main/java/net/mcplayhd/lootrunstatistics/listeners/ChestOpenListener.java @@ -278,6 +278,11 @@ public void guiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { getChests().addEmeralds(loc, emeralds); getDryData().addEmeralds(emeralds); dryDataUpdated = true; + } else if (displayName.equals("Emerald Block")) { + int emeralds = itemStack.getCount() * 64; + getChests().addEmeralds(loc, emeralds); + getDryData().addEmeralds(emeralds); + dryDataUpdated = true; } else if (displayName.contains("Earth Powder") || displayName.contains("Thunder Powder") || displayName.contains("Fire Powder")