-
Notifications
You must be signed in to change notification settings - Fork 18
various 1.21.3 compatibility fixes #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2274d76
fix adventure features
sylviameows 7b6e823
fix action viewer
sylviameows 58ebf22
re-enabled expression highlighter
sylviameows 6cdd4b9
fix custom chest menu
sylviameows 3f90b14
fix space and newline tags in chat bar
sylviameows 99cb925
fix chest highlighting blinking
sylviameows ee1bf85
fix code palette gui
sylviameows 97613bc
switch to plot tp command for phaser
sylviameows ebe6b3c
remove unused imports
sylviameows 4af078c
fix destroy item mode not saving
sylviameows d499318
add rate limiting
sylviameows 73f6c0b
add clear queue command
sylviameows c29803e
enable build phaser in build mode
sylviameows e0ba265
fix highlighter edgecase
sylviameows 0cfb01f
update dark mode pack format
sylviameows ca4079c
disable access widener
sylviameows 74bf364
fix workflow syntax
sylviameows 061861a
phaser keep velocity
sylviameows f8c15c1
dedupe ratelimiting increase
sylviameows 9d890d6
remove debug log
sylviameows File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| package dev.dfonline.codeclient; | ||
|
|
||
| /** | ||
| * A rate limiter that can be used to limit the rate of execution of a certain operation. | ||
| */ | ||
| public class RateLimiter { | ||
| private final int incrementStep; | ||
| private final int threshold; | ||
| private int count; | ||
|
|
||
| /** | ||
| * Creates a new rate limiter. | ||
| * @param incrementStep The amount to increment the count by each time the operation is executed. | ||
| * @param threshold The maximum count before the operation is rate limited. | ||
| */ | ||
| public RateLimiter(int incrementStep, int threshold) { | ||
| this.incrementStep = incrementStep; | ||
| this.threshold = threshold; | ||
| } | ||
|
|
||
| /** | ||
| * Registers an operation, incrementing the count. | ||
| */ | ||
| public void increment() { | ||
| count += incrementStep; | ||
| } | ||
|
|
||
| /** | ||
| * Decrements the count, should be called once per tick. | ||
| */ | ||
| public void tick() { | ||
| if (count > 0) { | ||
| --count; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the operation is rate limited. | ||
| * @return True if the operation is rate limited, false otherwise. | ||
| */ | ||
| public boolean isRateLimited() { | ||
| return count >= threshold; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
src/main/java/dev/dfonline/codeclient/command/CommandSender.java
This file contains hidden or 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,69 @@ | ||
| package dev.dfonline.codeclient.command; | ||
|
|
||
| import dev.dfonline.codeclient.CodeClient; | ||
| import dev.dfonline.codeclient.RateLimiter; | ||
|
|
||
| import java.util.ArrayDeque; | ||
|
|
||
| /** | ||
| * Queues up commands and sends them to avoid getting kicked for spam. | ||
| */ | ||
| public class CommandSender { | ||
| // Vanilla Minecraft uses 20 increment 200 threshold. | ||
| // We have a lower threshold for extra safety and to account for lag. | ||
| private static final RateLimiter rateLimiter = new RateLimiter(20, 140); | ||
| private static final ArrayDeque<String> commandQueue = new ArrayDeque<>(); | ||
|
|
||
| /* | ||
| public static void queue(String command, int delay, Runnable callback) { | ||
| rateLimiter.increment(); | ||
| for (int i = 0; i < delay; i++) { | ||
| } | ||
| commandQueue.add(command); | ||
| if (callback != null) { | ||
| callback.run(); | ||
| } | ||
| } | ||
|
|
||
| public static void queue(String command, int delay) { | ||
| queue(command, delay, null); | ||
| } | ||
|
|
||
| public static void queue(String command) { | ||
| queue(command, 0, null); | ||
| } | ||
| */ | ||
|
|
||
| public static void queue(String command) { | ||
| // rateLimiter.increment(); | ||
| commandQueue.add(command); | ||
| } | ||
|
|
||
| public static void clearQueue() { | ||
| commandQueue.clear(); | ||
| } | ||
|
|
||
| public static int queueSize() { | ||
| return commandQueue.size(); | ||
| } | ||
|
|
||
|
|
||
| public static void tick() { | ||
| rateLimiter.tick(); | ||
| if (CodeClient.MC.getNetworkHandler() == null) return; | ||
| if (!rateLimiter.isRateLimited() && !commandQueue.isEmpty()) { | ||
| CodeClient.MC.getNetworkHandler().sendCommand(commandQueue.pop()); | ||
| // No need to increment here, since our packet listener will do that for us. (Event#onSendPacket) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Registers a command send. | ||
| * This should be called whenever a command or chat message is sent to the server. | ||
| */ | ||
| public static void registerCommandSend() { | ||
| rateLimiter.increment(); | ||
| } | ||
|
|
||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/dfonline/codeclient/command/impl/CommandClearQueue.java
This file contains hidden or 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,32 @@ | ||
| package dev.dfonline.codeclient.command.impl; | ||
|
|
||
| import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
| import dev.dfonline.codeclient.ChatType; | ||
| import dev.dfonline.codeclient.Utility; | ||
| import dev.dfonline.codeclient.command.Command; | ||
| import dev.dfonline.codeclient.command.CommandSender; | ||
| import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
| import net.minecraft.command.CommandRegistryAccess; | ||
| import net.minecraft.text.Text; | ||
|
|
||
| public class CommandClearQueue extends Command { | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "ccclearqueue"; | ||
| } | ||
|
|
||
| @Override | ||
| public LiteralArgumentBuilder<FabricClientCommandSource> create(LiteralArgumentBuilder<FabricClientCommandSource> cmd, CommandRegistryAccess registryAccess) { | ||
| return cmd.executes(context -> { | ||
| if (CommandSender.queueSize() > 0) { | ||
| CommandSender.clearQueue(); | ||
| Utility.sendMessage(Text.translatable("codeclient.action.clearqueue.success"), ChatType.SUCCESS); | ||
| } else { | ||
| Utility.sendMessage(Text.translatable("codeclient.action.clearqueue.empty"), ChatType.FAIL); | ||
| } | ||
|
|
||
| return 1; | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.