-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/main/java/net/uku3lig/ukulib/config/screen/ColorSelectScreen.java
- Loading branch information
Showing
8 changed files
with
237 additions
and
16 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
33 changes: 33 additions & 0 deletions
33
src/main/java/net/uku3lig/ukulib/config/impl/StringInputScreen.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,33 @@ | ||
package net.uku3lig.ukulib.config.impl; | ||
|
||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.text.Text; | ||
import net.uku3lig.ukulib.config.ConfigManager; | ||
import net.uku3lig.ukulib.config.screen.TextInputScreen; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Basic implementation of {@link TextInputScreen} used to input a {@link String} of any type. | ||
*/ | ||
public class StringInputScreen extends TextInputScreen<String> { | ||
/** | ||
* Creates an input screen. | ||
* | ||
* @param parent The parent screen | ||
* @param title The title of the screen | ||
* @param label The label to be shown above the text input field | ||
* @param callback The action to be performed when the value is changed | ||
* @param last The last known value | ||
* @param manager The config manager, used to save the config | ||
*/ | ||
public StringInputScreen(Screen parent, Text title, Text label, Consumer<String> callback, String last, ConfigManager<?> manager) { | ||
super(parent, title, label, callback, last, manager); | ||
} | ||
|
||
@Override | ||
protected Optional<String> convert(String value) { | ||
return Optional.ofNullable(value); | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
src/main/java/net/uku3lig/ukulib/utils/PlayerArgumentType.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,77 @@ | ||
package net.uku3lig.ukulib.utils; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.text.Text; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* An argument type which represents players. Can only be used in client commands. | ||
*/ | ||
public class PlayerArgumentType implements ArgumentType<PlayerArgumentType.PlayerSelector> { | ||
/** | ||
* The exception thrown when the selected player is not found. | ||
*/ | ||
public static final SimpleCommandExceptionType PLAYER_NOT_FOUND_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("name.entity.notfound.player")); | ||
|
||
/** | ||
* Returns a new instance. | ||
* @return The instance | ||
*/ | ||
public static PlayerArgumentType player() { | ||
return new PlayerArgumentType(); | ||
} | ||
|
||
/** | ||
* Gets the player passed to the command. | ||
* @param name The name of the argument | ||
* @param context The command context | ||
* @return The player entity | ||
* @throws CommandSyntaxException if the player is not found | ||
*/ | ||
public static PlayerEntity getPlayer(String name, CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException { | ||
PlayerSelector selector = context.getArgument(name, PlayerSelector.class); | ||
|
||
return context.getSource().getWorld().getPlayers().stream() | ||
.filter(p -> p.getEntityName().equalsIgnoreCase(selector.name) || p.getUuidAsString().equalsIgnoreCase(selector.name)) | ||
.findFirst() | ||
.orElseThrow(PLAYER_NOT_FOUND_EXCEPTION::create); | ||
} | ||
|
||
@Override | ||
public PlayerSelector parse(StringReader reader) throws CommandSyntaxException { | ||
return new PlayerSelector(reader.readString()); | ||
} | ||
|
||
@Override | ||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) { | ||
if (context.getSource() instanceof FabricClientCommandSource source) { | ||
return CommandSource.suggestMatching(source.getWorld().getPlayers().stream().map(PlayerEntity::getEntityName), builder); | ||
} else { | ||
return CommandSource.suggestMatching(Collections.emptyList(), builder); | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<String> getExamples() { | ||
return Collections.singleton("uku3lig"); | ||
} | ||
|
||
/** | ||
* Simple record used to store the player name for later use | ||
* @param name The player's name or {@link java.util.UUID} | ||
*/ | ||
public record PlayerSelector(String name) { | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/net/uku3lig/ukulib/utils/SilentButtonWidget.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 net.uku3lig.ukulib.utils; | ||
|
||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.sound.SoundManager; | ||
import net.minecraft.text.Text; | ||
|
||
/** | ||
* A button that doesn't make noise. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class SilentButtonWidget extends ButtonWidget { | ||
/** | ||
* Creates a new silent button | ||
* @param x The x position of the button | ||
* @param y The y position of the button | ||
* @param width The width of the button | ||
* @param height The height of the button | ||
* @param message The text of the button | ||
* @param onPress The action to be done when the button is pressed | ||
* @param tooltipSupplier The tooltip supplier | ||
*/ | ||
protected SilentButtonWidget(int x, int y, int width, int height, Text message, PressAction onPress, TooltipSupplier tooltipSupplier) { | ||
super(x, y, width, height, message, onPress, tooltipSupplier); | ||
} | ||
|
||
/** | ||
* Creates a new silent button | ||
* @param x The x position of the button | ||
* @param y The y position of the button | ||
* @param width The width of the button | ||
* @param height The height of the button | ||
* @param message The text of the button | ||
* @param onPress The action to be done when the button is pressed | ||
*/ | ||
public SilentButtonWidget(int x, int y, int width, int height, Text message, PressAction onPress) { | ||
this(x, y, width, height, message, onPress, EMPTY); | ||
} | ||
|
||
@Override | ||
public void playDownSound(SoundManager soundManager) { | ||
// don't play anything | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"ukulib.position": "位置", | ||
"ukulib.position.topLeft": "左上角", | ||
"ukulib.position.topRight": "右上角", | ||
"ukulib.position.bottomLeft": "左下角", | ||
"ukulib.position.bottomRight": "右下角", | ||
"ukulib.position.middle": "在经验栏上方", | ||
"ukulib.position.desc": "点击屏幕上的某个地方来改变元素的位置。", | ||
"ukulib.position.desc.move": "按§e方向键§r来精确调整元素的位置。" | ||
} |