-
-
Notifications
You must be signed in to change notification settings - Fork 84
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 #162 from kevinthegreat1/livid-color
Livid color
- Loading branch information
Showing
8 changed files
with
164 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
43 changes: 43 additions & 0 deletions
43
src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/LividColor.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,43 @@ | ||
package me.xmrvizzy.skyblocker.skyblock.dungeon; | ||
|
||
import me.xmrvizzy.skyblocker.SkyblockerMod; | ||
import me.xmrvizzy.skyblocker.config.SkyblockerConfig; | ||
import me.xmrvizzy.skyblocker.utils.Utils; | ||
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class LividColor { | ||
private static int tenTicks = 0; | ||
|
||
public static void init() { | ||
ClientReceiveMessageEvents.ALLOW_GAME.register((message, overlay) -> { | ||
if (SkyblockerConfig.get().locations.dungeons.lividColor.enableLividColor && message.getString().equals("[BOSS] Livid: I respect you for making it to here, but I'll be your undoing.")) { | ||
tenTicks = 8; | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
public static void update() { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
if (tenTicks != 0) { | ||
if (SkyblockerConfig.get().locations.dungeons.lividColor.enableLividColor && Utils.isInDungeons() && client.world != null) { | ||
if (tenTicks == 1) { | ||
SkyblockerMod.getInstance().messageScheduler.sendMessageAfterCooldown(SkyblockerConfig.get().locations.dungeons.lividColor.lividColorText.replace("[color]", "red")); | ||
tenTicks = 0; | ||
return; | ||
} | ||
String key = client.world.getBlockState(new BlockPos(5, 110, 42)).getBlock().getTranslationKey(); | ||
if (key.startsWith("block.minecraft.") && key.endsWith("wool") && !key.endsWith("red_wool")) { | ||
SkyblockerMod.getInstance().messageScheduler.sendMessageAfterCooldown(SkyblockerConfig.get().locations.dungeons.lividColor.lividColorText.replace("[color]", key.substring(16, key.length() - 5))); | ||
tenTicks = 0; | ||
return; | ||
} | ||
tenTicks--; | ||
} else { | ||
tenTicks = 0; | ||
} | ||
} | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/main/java/me/xmrvizzy/skyblocker/utils/MessageScheduler.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,63 @@ | ||
package me.xmrvizzy.skyblocker.utils; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
|
||
/** | ||
* A scheduler for sending chat messages or commands. Use the instance in {@link me.xmrvizzy.skyblocker.SkyblockerMod#messageScheduler SkyblockerMod.messageScheduler}. Do not instantiate this class. | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public class MessageScheduler extends Scheduler { | ||
/** | ||
* The minimum delay that the server will accept between chat messages. | ||
*/ | ||
private static final int MIN_DELAY = 200; | ||
/** | ||
* The timestamp of the last message send, | ||
*/ | ||
private long lastMessage = 0; | ||
|
||
/** | ||
* Sends a chat message or command after the minimum cooldown. Prefer this method to send messages or commands to the server. | ||
* | ||
* @param message the message to send | ||
*/ | ||
public void sendMessageAfterCooldown(String message) { | ||
if (lastMessage + MIN_DELAY < System.currentTimeMillis()) { | ||
sendMessage(message); | ||
lastMessage = System.currentTimeMillis(); | ||
} else { | ||
queueMessage(message, 0); | ||
} | ||
} | ||
|
||
private void sendMessage(String message) { | ||
if (MinecraftClient.getInstance().player != null) { | ||
MinecraftClient.getInstance().inGameHud.getChatHud().addToMessageHistory(message); | ||
if (message.startsWith("/")) { | ||
MinecraftClient.getInstance().player.networkHandler.sendCommand(message.substring(1)); | ||
} else { | ||
MinecraftClient.getInstance().player.networkHandler.sendChatMessage(message); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Queues a chat message or command to send in {@code delay} ticks. Use this method to send messages or commands a set time in the future. The minimum cooldown is still respected. | ||
* | ||
* @param message the message to send | ||
* @param delay the delay before sending the message in ticks | ||
*/ | ||
public void queueMessage(String message, int delay) { | ||
schedule(() -> sendMessage(message), delay); | ||
} | ||
|
||
@Override | ||
protected boolean runTask(Runnable task) { | ||
if (lastMessage + MIN_DELAY < System.currentTimeMillis()) { | ||
task.run(); | ||
lastMessage = System.currentTimeMillis(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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