Skip to content

Commit

Permalink
convert to vigilance & add modcore
Browse files Browse the repository at this point in the history
  • Loading branch information
asbyth committed Mar 26, 2020
1 parent 4f0b203 commit cf3d9f0
Show file tree
Hide file tree
Showing 12 changed files with 856 additions and 455 deletions.
19 changes: 12 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ buildscript {
name = "forge"
url = "https://files.minecraftforge.net/maven"
}

flatDir dirs: 'libs'
}
dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT"
Expand All @@ -20,20 +22,15 @@ archivesBaseName = modBaseName
sourceCompatibility = targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'

configurations {
embed
compile.extendsFrom(embed)
}

minecraft {
version = project.forgeVersion
runDir = "run"
mappings = project.mcpVersion
makeObfSourceJar = false
}

repositories {
mavenCentral()
dependencies {
provided files("libs/modcore.jar")
}

processResources {
Expand All @@ -54,3 +51,11 @@ processResources {
exclude "mcmod.info"
}
}

jar {
manifest {
attributes "FMLCorePlugin": "club.sk1er.modcore.FMLLoadingPlugin",
"ModSide": "CLIENT",
"FMLCorePluginContainsFMLMod": "Yes, yes it does"
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modGroup=club.sk1er
modVersion=1.0
modVersion=1.1
modBaseName=LobbySounds
forgeVersion=1.8.9-11.15.1.2318-1.8.9
mcpVersion=stable_22
Binary file added libs/modcore.jar
Binary file not shown.
244 changes: 124 additions & 120 deletions src/main/java/club/sk1er/lobbysounds/LobbySounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,168 +2,172 @@

import club.sk1er.lobbysounds.command.LobbySoundsCommand;
import club.sk1er.lobbysounds.config.Sounds;
import club.sk1er.modcore.ModCoreInstaller;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.io.File;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

@Mod(modid = "lobby_sounds", name = "Lobby Sounds", version = "1.0")
public class LobbySounds {

private static String COMPASS_NAME = EnumChatFormatting.GREEN + "Game Menu " + EnumChatFormatting.GRAY +
"(Right Click)";
private static String COMPASS_LORE = EnumChatFormatting.DARK_PURPLE.toString() + EnumChatFormatting.ITALIC.toString() + EnumChatFormatting.GRAY +
"Right Click to bring up the Game Menu!";
private static final String COMPASS_NAME =
EnumChatFormatting.GREEN + "Game Menu " + EnumChatFormatting.GRAY +
"(Right Click)";
private static final String COMPASS_LORE =
EnumChatFormatting.DARK_PURPLE.toString() + EnumChatFormatting.ITALIC.toString()
+ EnumChatFormatting.GRAY +
"Right Click to bring up the Game Menu!";

private boolean inHypixelLobby;
private boolean onHypixel;
private boolean inHypixelLobby;
private boolean onHypixel;

private File configFile;
private Sounds sounds;

@Mod.Instance("lobby_sounds")
public static LobbySounds instance;
@Instance("lobby_sounds")
public static LobbySounds instance;

@Mod.EventHandler
public void preinit(FMLPreInitializationEvent event) {
configFile = event.getSuggestedConfigurationFile();
Sounds.loadConfig();
Runtime.getRuntime().addShutdownHook(new Thread(Sounds::saveConfig));
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
ModCoreInstaller.initializeModCore(Minecraft.getMinecraft().mcDataDir);

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new LobbySoundsCommand());
MinecraftForge.EVENT_BUS.register(this);
runLobbyCheckerTimer();
}
sounds = new Sounds();
sounds.preload();

@SubscribeEvent
public void soundPlay(PlaySoundEvent event) {
final String soundName = event.name;
ClientCommandHandler.instance.registerCommand(new LobbySoundsCommand());
MinecraftForge.EVENT_BUS.register(this);
runLobbyCheckerTimer();
}

if (onHypixel && inHypixelLobby) {
if (soundName.startsWith("mob.slime") && Sounds.DISABLE_SLIME_SOUNDS) {
setNullResult(event);
}
@SubscribeEvent
public void soundPlay(PlaySoundEvent event) {
String soundName = event.name;

if (soundName.startsWith("mob.enderdragon") && Sounds.DISABLE_DRAGON_SOUNDS) {
setNullResult(event);
}
if (onHypixel && inHypixelLobby) {
if (soundName.startsWith("mob.slime") && Sounds.DISABLE_SLIME_SOUNDS) {
setNullResult(event);
}

if ((soundName.startsWith("mob.wither") || soundName.startsWith("mob.skeleton")) && Sounds.DISABLE_WITHER_SOUNDS) {
setNullResult(event);
}
if (soundName.startsWith("mob.enderdragon") && Sounds.DISABLE_DRAGON_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("random.orb") && Sounds.DISABLE_EXPERIENCE_SOUNDS) {
setNullResult(event);
}
if ((soundName.startsWith("mob.wither") || soundName.startsWith("mob.skeleton"))
&& Sounds.DISABLE_WITHER_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("random.pop") && Sounds.DISABLE_ITEM_PICKUP_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("random.orb") && Sounds.DISABLE_EXPERIENCE_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("game.tnt.primed") && Sounds.DISABLE_TNT_PRIME_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("random.pop") && Sounds.DISABLE_ITEM_PICKUP_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("random.explode") && Sounds.DISABLE_EXPLOSION_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("game.tnt.primed") && Sounds.DISABLE_TNT_PRIME_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("mob.chicken.plop") && Sounds.DISABLE_DELIVERY_MAN_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("random.explode") && Sounds.DISABLE_EXPLOSION_SOUNDS) {
setNullResult(event);
}

if ((soundName.startsWith("note.") || soundName.equals("random.click") ) && Sounds.DISABLE_NOTE_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("mob.chicken.plop") && Sounds.DISABLE_DELIVERY_MAN_SOUNDS) {
setNullResult(event);
}

if (soundName.startsWith("fireworks") && Sounds.DISABLE_FIREWORKS_SOUNDS) {
setNullResult(event);
}
if ((soundName.startsWith("note.") || soundName.equals("random.click"))
&& Sounds.DISABLE_NOTE_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("random.levelup") && Sounds.DISABLE_LEVELUP_SOUNDS) {
setNullResult(event);
}
if (soundName.startsWith("fireworks") && Sounds.DISABLE_FIREWORKS_SOUNDS) {
setNullResult(event);
}

if (soundName.startsWith("step.") && Sounds.DISABLE_STEP_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("random.levelup") && Sounds.DISABLE_LEVELUP_SOUNDS) {
setNullResult(event);
}

if (soundName.startsWith("mob.bat") && Sounds.DISABLE_BAT_SOUNDS) {
setNullResult(event);
}
if (soundName.startsWith("step.") && Sounds.DISABLE_STEP_SOUNDS) {
setNullResult(event);
}

if (soundName.equals("fire.fire") && Sounds.DISABLE_FIRE_SOUNDS) {
setNullResult(event);
}
if (soundName.startsWith("mob.bat") && Sounds.DISABLE_BAT_SOUNDS) {
setNullResult(event);
}

if (soundName.startsWith("mob.endermen") && Sounds.DISABLE_ENDERMEN_SOUNDS) {
setNullResult(event);
}
if (soundName.equals("fire.fire") && Sounds.DISABLE_FIRE_SOUNDS) {
setNullResult(event);
}

if (event.result != null) {
System.out.println(event.name);
}
}
}
if (soundName.startsWith("mob.endermen") && Sounds.DISABLE_ENDERMEN_SOUNDS) {
setNullResult(event);
}

private void setNullResult(PlaySoundEvent event) {
event.result = null;
if (soundName.startsWith("random.bow") && Sounds.DISABLE_ARROW_SOUNDS) {
setNullResult(event);
}
}

// lobby checker taken from LobbyGlow by biscut
private void runLobbyCheckerTimer() {
Minecraft mc = Minecraft.getMinecraft();
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
checkForItem(mc);
checkIp(mc);
}
}, 1000, 1000);
}

private void setNullResult(PlaySoundEvent event) {
event.result = null;
}

// lobby checker taken from LobbyGlow by biscut
private void runLobbyCheckerTimer() {
Minecraft mc = Minecraft.getMinecraft();
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
checkForItem(mc);
checkIp(mc);
}
}, 1000, 1000);
}

private void checkIp(Minecraft mc) {
if (mc.getCurrentServerData() != null) {
String ip = mc.getCurrentServerData().serverIP.toLowerCase();
if (ip.equals("hypixel.net") || ip.endsWith(".hypixel.net") || ip.contains(".hypixel.net:")
|| ip.startsWith("hypixel.net:")) {
onHypixel = true;
return;
}
}

private void checkIp(Minecraft mc) {
if (mc.getCurrentServerData() != null) {
String ip = mc.getCurrentServerData().serverIP.toLowerCase();
if (ip.equals("hypixel.net") || ip.endsWith(".hypixel.net") || ip.contains(".hypixel.net:") || ip.startsWith("hypixel.net:")) {
onHypixel = true;
return;
}
}
onHypixel = false;
}

onHypixel = false;
}
private void checkForItem(Minecraft mc) {
if (mc != null && mc.thePlayer != null && mc.thePlayer.inventory != null) {
ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(0);

private void checkForItem(Minecraft mc) {
if (mc != null && mc.thePlayer != null && mc.thePlayer.inventory != null) {
ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(0);

if (itemStack != null && itemStack.hasDisplayName() && itemStack.getDisplayName().equals(COMPASS_NAME)) {
List<String> tooltip = itemStack.getTooltip(mc.thePlayer, false);
if (tooltip.get(1).equals(COMPASS_LORE)) {
inHypixelLobby = true;
return;
}
}
if (itemStack != null && itemStack.hasDisplayName() && itemStack.getDisplayName()
.equals(COMPASS_NAME)) {
List<String> tooltip = itemStack.getTooltip(mc.thePlayer, false);
if (tooltip.get(1).equals(COMPASS_LORE)) {
inHypixelLobby = true;
return;
}

inHypixelLobby = false;
}
}

public File getConfigFile() {
return configFile;
}
inHypixelLobby = false;
}

public Sounds getSounds() {
return sounds;
}
}
Loading

0 comments on commit cf3d9f0

Please sign in to comment.