Skip to content

Commit

Permalink
Merge pull request #12 from Alexdoru/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
Alexdoru authored May 28, 2022
2 parents c221b9c + b05dfd8 commit ea61c53
Show file tree
Hide file tree
Showing 29 changed files with 472 additions and 252 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ buildscript {
}
apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.8"
version = "1.9"
group = "fr.alexdoru"
archivesBaseName = "[1.8.9] MegaWallsEnhancements"
archivesBaseName = "[1.8.9]MegaWallsEnhancements"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/alexdoru/fkcountermod/FKCounterMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class FKCounterMod {
* True during the preparation phase of a mega walls game
*/
public static boolean isitPrepPhase = false;
public static boolean isHypixel = false;
public static boolean isMWEnvironement = false;

public static void init() {
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/fr/alexdoru/fkcountermod/events/ScoreboardEvent.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package fr.alexdoru.fkcountermod.events;

import fr.alexdoru.fkcountermod.FKCounterMod;
import fr.alexdoru.fkcountermod.utils.MinecraftUtils;
import fr.alexdoru.fkcountermod.utils.ScoreboardParser;
import net.minecraft.client.Minecraft;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;

public class ScoreboardEvent {

Expand All @@ -29,12 +27,20 @@ public void onTick(TickEvent.ClientTickEvent event) {
return;
}

if (mc.theWorld == null || !FKCounterMod.isHypixel) {
if (mc.theWorld == null) {
FKCounterMod.isInMwGame = false;
FKCounterMod.isMWEnvironement = false;
FKCounterMod.preGameLobby = false;
FKCounterMod.isitPrepPhase = false;
return;
}

Scoreboard scoreboard = mc.theWorld.getScoreboard();
if (scoreboard == null) {
FKCounterMod.isInMwGame = false;
FKCounterMod.isMWEnvironement = false;
FKCounterMod.preGameLobby = false;
FKCounterMod.isitPrepPhase = false;
return;
}

Expand All @@ -48,13 +54,13 @@ public void onTick(TickEvent.ClientTickEvent event) {
FKCounterMod.preGameLobby = mwScoreboardParser.isPreGameLobby();
FKCounterMod.isitPrepPhase = mwScoreboardParser.isitPrepPhase();

if (gameId == null) { // not in a MW game
if (gameId == null) { // not in MW game

if (prevGameId != null) {
MinecraftForge.EVENT_BUS.post(new MwGameEvent(MwGameEvent.EventType.DISCONNECT));
}

} else { // is in a MW game
} else { // is in MW game

if (amountWitherAlive == 1 && prevAmountWitherAlive > 1) {
MinecraftForge.EVENT_BUS.post(new MwGameEvent(MwGameEvent.EventType.THIRD_WITHER_DEATH));
Expand All @@ -78,14 +84,4 @@ public void onTick(TickEvent.ClientTickEvent event) {

}

@SubscribeEvent
public void onConnection(FMLNetworkEvent.ClientConnectedToServerEvent event) {
FKCounterMod.isHypixel = MinecraftUtils.isHypixel();
}

@SubscribeEvent
public void onDisconnection(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
FKCounterMod.isHypixel = false;
}

}
33 changes: 0 additions & 33 deletions src/main/java/fr/alexdoru/fkcountermod/utils/MinecraftUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ public class ScoreboardUtils {
* Item at index 0 is the first line etc
*/
public static List<String> getFormattedSidebarText() {

List<String> lines = new ArrayList<>();

if (mc.theWorld == null || !MinecraftUtils.isHypixel()) {
if (mc.theWorld == null) {
return lines;
}

Scoreboard scoreboard = mc.theWorld.getScoreboard();
if (scoreboard == null) {
return lines;
}

return getFormattedSidebarText(scoreboard);
}

Expand Down Expand Up @@ -126,10 +122,7 @@ public static String getUnformattedSidebarTitle(Scoreboard scoreboard) {
}

public static String getUnformattedSidebarTitle() {
if (mc.theWorld == null || !MinecraftUtils.isHypixel()) {
return null;
}
return getUnformattedSidebarTitle(mc.theWorld.getScoreboard());
return mc.theWorld == null ? null : getUnformattedSidebarTitle(mc.theWorld.getScoreboard());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler;
import fr.alexdoru.megawallsenhancementsmod.events.*;
import fr.alexdoru.megawallsenhancementsmod.gui.guiapi.GuiManager;
import fr.alexdoru.megawallsenhancementsmod.updater.ModUpdater;
import fr.alexdoru.nocheatersmod.NoCheatersMod;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.ClientCommandHandler;
Expand All @@ -23,14 +24,17 @@ public class MegaWallsEnhancementsMod {

public static final String modid = "mwenhancements";
public static final String modName = "MegaWallsEnhancements";
public static final String version = "1.8";
public static final String version = "1.9";
public static final KeyBinding toggleDroppedItemLimit = new KeyBinding("Toggle dropped item limit", 0, "MegaWallsEnhancements");
public static final KeyBinding newNickKey = new KeyBinding("New Random Nick", 0, "MegaWallsEnhancements");
public static File configurationFile;
public static File jarFile;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
configurationFile = event.getSuggestedConfigurationFile();
ConfigHandler.preinit(configurationFile);
jarFile = event.getSourceFile();
}

@EventHandler
Expand All @@ -39,13 +43,14 @@ public void init(FMLInitializationEvent event) {
FKCounterMod.init();

ClientRegistry.registerKeyBinding(toggleDroppedItemLimit);
ClientRegistry.registerKeyBinding(newNickKey);

MinecraftForge.EVENT_BUS.register(new GuiManager());
MinecraftForge.EVENT_BUS.register(new ChatEvents());
MinecraftForge.EVENT_BUS.register(new SquadEvent());
MinecraftForge.EVENT_BUS.register(new KillCounter());
MinecraftForge.EVENT_BUS.register(new LowHPIndicator());
MinecraftForge.EVENT_BUS.register(new UpdateNotifier());
MinecraftForge.EVENT_BUS.register(new ModUpdater());
MinecraftForge.EVENT_BUS.register(new KeybindingsEvent());
MinecraftForge.EVENT_BUS.register(new MWGameStatsEvent());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ public static boolean shouldCancelHotkey(Slot theSlot, int i) {
* iron sword w sharpness
* diamond sword except quantum sword check silk touch
* potions / exept phx/ren splash & squid abs
* bow except if you have enchanted bows on you (pirate bows)
* kit bow except if you have enchanted bows on you (pirate bows)
*/
private static boolean isItemImportant(Slot theSlot, int i) {
if (FKCounterMod.isInMwGame && ConfigHandler.safeInventory) {
/*Targeted inventory for the hotkeying*/
if (theSlot.inventory instanceof InventoryPlayer) {
return false;
}
final ItemStack itemstackInSlot = theSlot.inventory.getStackInSlot(theSlot.slotNumber);
/*If the targeted slot for the hotkey has an item, it won't hotkey the item in hotbar in the inventory in vanilla*/
if (itemstackInSlot != null) {
return false;
}
final EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer;
final ItemStack itemStack = thePlayer.inventory.mainInventory[i];
if (itemStack != null && itemStackHasCustomDisplayName(itemStack)) {
Expand Down Expand Up @@ -104,7 +109,7 @@ private static boolean isItemImportant(Slot theSlot, int i) {
}
if (item == Items.bow) {
if (itemStack.isItemEnchanted()) {
return true;
return !isSpecialPirateBow(itemStack);
}
return !hasAnotherBowThatsEnchanted(thePlayer.inventory.mainInventory);
}
Expand All @@ -116,8 +121,8 @@ private static boolean isItemImportant(Slot theSlot, int i) {
private static boolean itemStackHasCustomDisplayName(ItemStack itemStack) {
final NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("display", 10)) {
NBTTagCompound nbttagcompound = tagCompound.getCompoundTag("display");
return nbttagcompound.hasKey("Name", 8);
NBTTagCompound displayTag = tagCompound.getCompoundTag("display");
return displayTag.hasKey("Name", 8);
}
return false;
}
Expand All @@ -130,6 +135,13 @@ private static boolean isEnchantedWithSilkTouch(ItemStack itemStack) {
return EnchantmentHelper.getEnchantments(itemStack).containsKey(Enchantment.silkTouch.effectId);
}

private static boolean isSpecialPirateBow(ItemStack itemStack) {
final NBTTagCompound tagCompound = itemStack.getTagCompound();
final NBTTagCompound displayTag = tagCompound.getCompoundTag("display");
final String itemName = displayTag.getString("Name");
return itemName != null && (itemName.contains("Matey Coconut Bow") || itemName.contains("Matey Voodoo Bow"));
}

private static boolean hasAnotherBowThatsEnchanted(ItemStack[] mainInventory) {
for (ItemStack itemStack : mainInventory) {
if (itemStack != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.EnumChatFormatting;

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

@SuppressWarnings("unused")
public class GuiPlayerTabOverlayHook {

Expand All @@ -24,6 +27,19 @@ public static void renderFinals(int playersFinals, int x, int y) {
fontRendererObj.drawStringWithShadow(s1, (float) (x - fontRendererObj.getStringWidth(s1) - FK_SCORE_WIDTH), (float) y, 16777215);
}

public static List<String> addPlayerCountinHeader(List<String> listIn) {
if (listIn != null) {
int i = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap().size();
if (i < 2) {
return listIn;
}
final ArrayList<String> list = new ArrayList<>(listIn);
list.add(0, EnumChatFormatting.GREEN + "Players: " + EnumChatFormatting.GOLD + i);
return list;
}
return null;
}

public static EnumChatFormatting getColoredHP(int healthPoints) {
if (ConfigHandler.useColoredScores) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package fr.alexdoru.megawallsenhancementsmod.asm.hooks;

import fr.alexdoru.megawallsenhancementsmod.MegaWallsEnhancementsMod;
import fr.alexdoru.megawallsenhancementsmod.config.ConfigHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import org.lwjgl.input.Keyboard;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SuppressWarnings("unused")
public class GuiScreenBookHook {

private static final Pattern nickSuccessPattern = Pattern.compile("You have finished setting up your nickname!\\s*When you go into a game, you will be nicked as\\s*(?:|\\[(?:MV|VI)P\\+?\\+?\\] )(\\w{2,16})");
private static boolean isOnNickGenerationPage = false;
private static long lastTimeClicked;

private static final Pattern nickSuccessPagePattern = Pattern.compile("You have finished setting up your nickname!\\s*When you go into a game, you will be nicked as\\s*(?:|\\[(?:MV|VI)P\\+?\\+?\\] )(\\w{2,16})");
private static final Pattern nickGenerationPagePattern = Pattern.compile("We've generated a random username for you:\\s*\\w{2,16}");

public static void onBookInit(ItemStack book) {
isOnNickGenerationPage = false;
if (book.hasTagCompound()) {
NBTTagCompound nbttagcompound = book.getTagCompound();
NBTTagList bookPages = nbttagcompound.getTagList("pages", 8);
Expand All @@ -27,18 +35,47 @@ public static void onBookInit(ItemStack book) {
}
for (int i = 0; i < bookTotalPages; i++) {
String pagetext = EnumChatFormatting.getTextWithoutFormattingCodes(IChatComponent.Serializer.jsonToComponent(bookPages.getStringTagAt(i)).getUnformattedText().replace("\n", ""));
final Matcher matcher2 = nickSuccessPattern.matcher(pagetext);
if (matcher2.find()) {
final String newNick = matcher2.group(1);
Matcher matcher = nickSuccessPagePattern.matcher(pagetext);
if (matcher.find()) {
final String newNick = matcher.group(1);
if (newNick != null && !newNick.equals("")) {
ConfigHandler.hypixelNick = newNick;
ConfigHandler.saveConfig();
return;
}
}
matcher = nickGenerationPagePattern.matcher(pagetext);
if (matcher.find()) {
isOnNickGenerationPage = true;
return;
}
}
}
}
}

public static void onKeyTyped(int keycode) {
if (isOnNickGenerationPage && System.currentTimeMillis() - lastTimeClicked > 500 && MegaWallsEnhancementsMod.newNickKey.getKeyCode() != 0 && MegaWallsEnhancementsMod.newNickKey.getKeyCode() == keycode) {
lastTimeClicked = System.currentTimeMillis();
Minecraft.getMinecraft().thePlayer.sendChatMessage("/nick help setrandom");
}
}

public static void renderInstructions(int screenWidth, int y) {
if (isOnNickGenerationPage) {
final int keyCode = MegaWallsEnhancementsMod.newNickKey.getKeyCode();
final String text;
if (keyCode == 0) {
text = EnumChatFormatting.GREEN + "Go to " + EnumChatFormatting.GOLD + "Option -> Controls -> MegaWallsEnhancements" + EnumChatFormatting.GREEN + ", to set the keybind to get a random nick";
} else {
text = EnumChatFormatting.GREEN + "Press " + EnumChatFormatting.GOLD + Keyboard.getKeyName(keyCode) + EnumChatFormatting.GREEN + " to get a new random nick";
}
drawCenteredStringAt(screenWidth / 2, y + 24 + 24, text);
}
}

private static void drawCenteredStringAt(int x, int y, String text) {
Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(text, (float) (x - Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) / 2), (float) y, 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String getTargetClassName() {
public ClassNode transform(ClassNode classNode, InjectionStatus status) {

boolean isPatcherLoaded = true;
int injectionPoints = 5;
int injectionPoints = 6;
status.setInjectionPoints(injectionPoints);

try {
Expand All @@ -34,6 +34,9 @@ public ClassNode transform(ClassNode classNode, InjectionStatus status) {
for (MethodNode methodNode : classNode.methods) {

if (methodNode.name.equals(ASMLoadingPlugin.isObf ? "a" : "renderPlayerlist") && methodNode.desc.equals(ASMLoadingPlugin.isObf ? "(ILauo;Lauk;)V" : "(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V")) {

boolean foundListFormattedStringToWidth = false;

for (AbstractInsnNode insnNode : methodNode.instructions.toArray()) {

if (insnNode.getOpcode() == BIPUSH && insnNode instanceof IntInsnNode && ((IntInsnNode) insnNode).operand == 20) {
Expand Down Expand Up @@ -65,6 +68,15 @@ public ClassNode transform(ClassNode classNode, InjectionStatus status) {
}
}

if (!foundListFormattedStringToWidth && insnNode instanceof MethodInsnNode && insnNode.getOpcode() == INVOKEVIRTUAL &&
((MethodInsnNode) insnNode).owner.equals(ASMLoadingPlugin.isObf ? "avn" : "net/minecraft/client/gui/FontRenderer")
&& ((MethodInsnNode) insnNode).name.equals(ASMLoadingPlugin.isObf ? "c" : "listFormattedStringToWidth")
&& ((MethodInsnNode) insnNode).desc.equals("(Ljava/lang/String;I)Ljava/util/List;")) {
foundListFormattedStringToWidth = true;
methodNode.instructions.insertBefore(insnNode.getNext(), new MethodInsnNode(INVOKESTATIC, "fr/alexdoru/megawallsenhancementsmod/asm/hooks/GuiPlayerTabOverlayHook", "addPlayerCountinHeader", "(Ljava/util/List;)Ljava/util/List;", false));
status.addInjection();
}

}
}

Expand Down
Loading

0 comments on commit ea61c53

Please sign in to comment.