From 644c0da5966666e1447e011a0f7e14287cbb4611 Mon Sep 17 00:00:00 2001 From: sisby-folk Date: Mon, 2 Dec 2024 16:06:38 +1100 Subject: [PATCH] Selected highlight & click, keybind, better toast, remember shard --- gradle.properties | 2 +- .../scatteredshards/block/ShardBlock.java | 1 - .../client/ScatteredShardsClient.java | 25 ++++-- .../client/ShardCollectedToast.java | 77 ++++++++++++++++++ .../scatteredshards/client/ShardToast.java | 57 ------------- .../client/command/ClientShardCommand.java | 14 ++-- .../screen/ShardCreatorGuiDescription.java | 23 +++--- .../screen/ShardTabletGuiDescription.java | 27 +++++- .../client/screen/widget/WMiniShard.java | 19 +++-- .../client/screen/widget/WShardPanel.java | 9 +- .../client/screen/widget/WShardSetPanel.java | 17 ---- .../scatteredshards/command/BlockCommand.java | 3 +- .../scatteredshards/command/ShardCommand.java | 4 - .../networking/S2CUpdateShard.java | 4 +- .../assets/scattered_shards/lang/en_us.json | 47 ++++++----- .../gui/shards/mini_outline_slight.png | Bin 0 -> 221 bytes 16 files changed, 186 insertions(+), 143 deletions(-) create mode 100644 src/main/java/net/modfest/scatteredshards/client/ShardCollectedToast.java delete mode 100644 src/main/java/net/modfest/scatteredshards/client/ShardToast.java create mode 100644 src/main/resources/assets/scattered_shards/textures/gui/shards/mini_outline_slight.png diff --git a/gradle.properties b/gradle.properties index 9b2c11b..f8f3911 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ authors=Falkreon, acikek contributors=Trudle, Tomate0613, afamiliarquiet, FoundationGames, TheEpicBlock, hama license=MIT # Mod Version -baseVersion=1.7.2 +baseVersion=1.8.0 # Branch Metadata branch=1.21 tagBranch=1.21 diff --git a/src/main/java/net/modfest/scatteredshards/block/ShardBlock.java b/src/main/java/net/modfest/scatteredshards/block/ShardBlock.java index 7e508e5..9018842 100644 --- a/src/main/java/net/modfest/scatteredshards/block/ShardBlock.java +++ b/src/main/java/net/modfest/scatteredshards/block/ShardBlock.java @@ -102,7 +102,6 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player if (tryCollect(world, player, be)) { return ActionResult.SUCCESS; } - player.sendMessage(Text.translatable("block.scattered_shards.shard_block.pickup_fail"), true); return ActionResult.FAIL; } diff --git a/src/main/java/net/modfest/scatteredshards/client/ScatteredShardsClient.java b/src/main/java/net/modfest/scatteredshards/client/ScatteredShardsClient.java index 9b94cf2..2b68b98 100644 --- a/src/main/java/net/modfest/scatteredshards/client/ScatteredShardsClient.java +++ b/src/main/java/net/modfest/scatteredshards/client/ScatteredShardsClient.java @@ -1,7 +1,10 @@ package net.modfest.scatteredshards.client; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.Toast; @@ -19,7 +22,11 @@ import net.modfest.scatteredshards.networking.ScatteredShardsNetworking; public class ScatteredShardsClient implements ClientModInitializer { - public static final String SHARD_MODIFY_TOAST_KEY = "toast.scattered_shards.shard_mod"; + public static final KeyBinding VIEW_COLLECTION = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.scattered_shards.collection", + InputUtil.GLFW_KEY_J, + "key.categories.scattered_shards" + )); @Override public void onInitializeClient() { @@ -27,9 +34,14 @@ public void onInitializeClient() { ScatteredShardsNetworking.registerClient(); ScatteredShardsContent.registerClient(); ScatteredShardsAPI.initClient(); + ClientTickEvents.END_CLIENT_TICK.register(c -> { + if (VIEW_COLLECTION.wasPressed()) { + openShardTablet(); + } + }); } - public static void triggerShardCollectAnimation(Identifier shardId) { + public static void onShardCollected(Identifier shardId) { var library = ScatteredShardsAPI.getClientLibrary(); var collection = ScatteredShardsAPI.getClientCollection(); @@ -39,6 +51,9 @@ public static void triggerShardCollectAnimation(Identifier shardId) { return; } + ShardTabletGuiDescription.INITIAL_SHARD = shardId; + ShardTabletGuiDescription.INITIAL_SCROLL_POSITION = -1; + collection.add(shardId); ScatteredShards.LOGGER.info("Collected shard '{}'!", shardId.toString()); @@ -47,15 +62,15 @@ public static void triggerShardCollectAnimation(Identifier shardId) { .flatMap(ShardType::collectSound) .ifPresent((sound) -> MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(sound, 1.0F, 0.8F))); - Toast toast = new ShardToast(shard); + Toast toast = new ShardCollectedToast(shard); MinecraftClient.getInstance().getToastManager().add(toast); } public static void triggerShardModificationToast(Identifier shardId, boolean success) { var toast = new SystemToast( SystemToast.Type.PERIODIC_NOTIFICATION, - Text.translatable(SHARD_MODIFY_TOAST_KEY + ".title"), - Text.stringifiedTranslatable(SHARD_MODIFY_TOAST_KEY + "." + (success ? "success" : "fail"), shardId) + Text.translatable("toast.scattered_shards.shard_mod.title"), + Text.stringifiedTranslatable(success ? "toast.scattered_shards.shard_mod.success" : "toast.scattered_shards.shard_mod.success.fail", shardId) ); MinecraftClient.getInstance().getToastManager().add(toast); } diff --git a/src/main/java/net/modfest/scatteredshards/client/ShardCollectedToast.java b/src/main/java/net/modfest/scatteredshards/client/ShardCollectedToast.java new file mode 100644 index 0000000..72023dd --- /dev/null +++ b/src/main/java/net/modfest/scatteredshards/client/ShardCollectedToast.java @@ -0,0 +1,77 @@ +package net.modfest.scatteredshards.client; + +import com.mojang.datafixers.util.Either; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.toast.Toast; +import net.minecraft.client.toast.ToastManager; +import net.minecraft.item.ItemStack; +import net.minecraft.text.OrderedText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; +import net.modfest.scatteredshards.api.ScatteredShardsAPI; +import net.modfest.scatteredshards.api.shard.Shard; +import net.modfest.scatteredshards.api.shard.ShardType; +import net.modfest.scatteredshards.util.ModMetaUtil; + +import java.util.ArrayList; +import java.util.List; + +public class ShardCollectedToast implements Toast { + public static final int TITLE_COLOR = 0xFF_FFFF00; + public static final Text TITLE = Text.translatable("toast.scattered_shards.collected"); + public static final Text HINT = Text.translatable("toast.scattered_shards.collected.prompt", Text.keybind(ScatteredShardsClient.VIEW_COLLECTION.getTranslationKey()).formatted(Formatting.GOLD).formatted(Formatting.BOLD)); + private static final Identifier TEXTURE = Identifier.ofVanilla("toast/advancement"); + public static final int DURATION = 5000; + + Either icon; + List descLines; + List hintLines; + private final int height; + + public ShardCollectedToast(Shard shard) { + this.icon = shard.icon(); + this.descLines = wrap(List.of(shard.name().copy().withColor(ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING).textColor()))); + this.hintLines = wrap(List.of(HINT)); + this.height = 32 + Math.max(0, Math.max(this.descLines.size(), this.hintLines.size()) - 1) * 11; + icon.ifRight(ModMetaUtil::touchIconTexture); + } + + @Override + public Visibility draw(DrawContext graphics, ToastManager manager, long startTime) { + graphics.drawGuiTexture(TEXTURE, 0, 0, this.getWidth(), this.getHeight()); + TextRenderer textRenderer = manager.getClient().textRenderer; + + graphics.drawText( + textRenderer, + TITLE, 32, 7, TITLE_COLOR, + false + ); + + double time = DURATION * manager.getNotificationDisplayTimeMultiplier(); + + List body = startTime >= (time / 2) && !hintLines.isEmpty() ? hintLines : descLines; + + for (int i = 0; i < body.size(); i++) { + graphics.drawText(textRenderer, body.get(i), 32, 18 + i * 11, 0xFF_FFFFFF, false); + } + + icon.ifLeft(it -> graphics.drawItemWithoutEntity(it, 8, 8)); + icon.ifRight(it -> ScreenDrawing.texturedRect(graphics, 8, 8, 16, 16, it, 0xFF_FFFFFF)); + return startTime >= time ? Toast.Visibility.HIDE : Toast.Visibility.SHOW; + } + + private List wrap(List messages) { + List list = new ArrayList<>(); + messages.forEach(text -> list.addAll(MinecraftClient.getInstance().textRenderer.wrapLines(text, getWidth() - 40))); + return list; + } + + @Override + public int getHeight() { + return height; + } +} diff --git a/src/main/java/net/modfest/scatteredshards/client/ShardToast.java b/src/main/java/net/modfest/scatteredshards/client/ShardToast.java deleted file mode 100644 index ef4da9a..0000000 --- a/src/main/java/net/modfest/scatteredshards/client/ShardToast.java +++ /dev/null @@ -1,57 +0,0 @@ -package net.modfest.scatteredshards.client; - -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.toast.Toast; -import net.minecraft.client.toast.ToastManager; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.modfest.scatteredshards.api.ScatteredShardsAPI; -import net.modfest.scatteredshards.api.shard.Shard; -import net.modfest.scatteredshards.api.shard.ShardType; - -import java.util.List; - -public class ShardToast implements Toast { - public static final int YELLOW = 0xFF_FFFF00; - public static final int WHITE = 0xFF_FFFFFF; - public static final Text COLLECTED_TEXT = Text.translatable("scattered_shards.toast.collect"); - - private static final Identifier TEXTURE = Identifier.ofVanilla("toast/advancement"); - - public static final int DURATION = 5000; - private final Shard shard; - - public ShardToast(Shard shard) { - this.shard = shard; - } - - @Override - public Visibility draw(DrawContext graphics, ToastManager manager, long startTime) { - graphics.drawGuiTexture(TEXTURE, 0, 0, this.getWidth(), this.getHeight()); - TextRenderer textRenderer = manager.getClient().textRenderer; - - if (shard == null) return Toast.Visibility.HIDE; - ShardType shardType = ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING); - - List lines = manager.getClient().textRenderer.wrapLines(shard.name(), 125); // 160 is the total toast width so this is reasonable - if (lines.size() == 1) { - graphics.drawText(textRenderer, COLLECTED_TEXT, 30, 7, YELLOW, false); - graphics.drawText(textRenderer, shard.name(), 30, 18, shardType.textColor(), false); - } else { - int y = this.getHeight() / 2 - lines.size() * 9 / 2; - - for (OrderedText orderedText : lines) { - graphics.drawText(manager.getClient().textRenderer, orderedText, 30, y, shardType.textColor(), false); - y += 9; - } - } - - shard.icon().ifLeft(it -> graphics.drawItemWithoutEntity(it, 8, 8)); - - shard.icon().ifRight(it -> ScreenDrawing.texturedRect(graphics, 8, 8, 16, 16, it, WHITE)); - return (double) startTime >= DURATION * manager.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW; - } -} diff --git a/src/main/java/net/modfest/scatteredshards/client/command/ClientShardCommand.java b/src/main/java/net/modfest/scatteredshards/client/command/ClientShardCommand.java index ef6c8c5..4312d5f 100644 --- a/src/main/java/net/modfest/scatteredshards/client/command/ClientShardCommand.java +++ b/src/main/java/net/modfest/scatteredshards/client/command/ClientShardCommand.java @@ -27,14 +27,12 @@ public class ClientShardCommand { - private static DynamicCommandExceptionType createInvalidException(String item) { - return new DynamicCommandExceptionType( - obj -> Text.stringifiedTranslatable("error.scattered_shards.invalid_" + item, obj) - ); - } - - private static final DynamicCommandExceptionType INVALID_SET_ID = createInvalidException("set_id"); - private static final DynamicCommandExceptionType INVALID_SHARD_ID = createInvalidException("shard_id"); + private static final DynamicCommandExceptionType INVALID_SET_ID = new DynamicCommandExceptionType( + obj -> Text.stringifiedTranslatable("error.scattered_shards.invalid_set_id", obj) + ); + private static final DynamicCommandExceptionType INVALID_SHARD_ID = new DynamicCommandExceptionType( + obj -> Text.stringifiedTranslatable("error.scattered_shards.invalid_shard_id", obj) + ); public static int view(CommandContext context) throws CommandSyntaxException { Identifier id = context.getArgument("set_id", Identifier.class); diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java b/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java index 6d3177e..637801b 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/ShardCreatorGuiDescription.java @@ -36,18 +36,17 @@ import java.util.Objects; public class ShardCreatorGuiDescription extends LightweightGuiDescription { - public static final String BASE_KEY = "gui.scattered_shards.creator."; - public static final Text TITLE_TEXT = Text.translatable(BASE_KEY + "title"); - public static final Text NAME_TEXT = Text.translatable(BASE_KEY + "field.name"); - public static final Text LORE_TEXT = Text.translatable(BASE_KEY + "field.lore"); - public static final Text HINT_TEXT = Text.translatable(BASE_KEY + "field.hint"); - public static final Text TEXTURE_TEXT = Text.translatable(BASE_KEY + "field.texture"); - public static final Text ICON_TEXTURE_TEXT = Text.translatable(BASE_KEY + "icon.texture"); - public static final Text ICON_ITEM_TEXT = Text.translatable(BASE_KEY + "icon.item"); - public static final Text ITEM_TEXT = Text.translatable(BASE_KEY + "field.item.id"); - public static final Text NBT_TEXT = Text.translatable(BASE_KEY + "field.item.nbt"); - public static final Text USE_MOD_ICON_TEXT = Text.translatable(BASE_KEY + "toggle.mod_icon"); - public static final Text SAVE_TEXT = Text.translatable(BASE_KEY + "button.save"); + public static final Text TITLE_TEXT = Text.translatable("gui.scattered_shards.creator.title"); + public static final Text NAME_TEXT = Text.translatable("gui.scattered_shards.creator.field.name"); + public static final Text LORE_TEXT = Text.translatable("gui.scattered_shards.creator.field.lore"); + public static final Text HINT_TEXT = Text.translatable("gui.scattered_shards.creator.field.hint"); + public static final Text TEXTURE_TEXT = Text.translatable("gui.scattered_shards.creator.field.texture"); + public static final Text ICON_TEXTURE_TEXT = Text.translatable("gui.scattered_shards.creator.icon.texture"); + public static final Text ICON_ITEM_TEXT = Text.translatable("gui.scattered_shards.creator.icon.item"); + public static final Text ITEM_TEXT = Text.translatable("gui.scattered_shards.creator.field.item.id"); + public static final Text NBT_TEXT = Text.translatable("gui.scattered_shards.creator.field.item.nbt"); + public static final Text USE_MOD_ICON_TEXT = Text.translatable("gui.scattered_shards.creator.toggle.mod_icon"); + public static final Text SAVE_TEXT = Text.translatable("gui.scattered_shards.creator.button.save"); private static final Gson GSON = new Gson(); diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/ShardTabletGuiDescription.java b/src/main/java/net/modfest/scatteredshards/client/screen/ShardTabletGuiDescription.java index 8088a53..a46b303 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/ShardTabletGuiDescription.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/ShardTabletGuiDescription.java @@ -15,6 +15,7 @@ import net.modfest.scatteredshards.api.ShardCollection; import net.modfest.scatteredshards.api.ShardLibrary; import net.modfest.scatteredshards.api.shard.Shard; +import net.modfest.scatteredshards.api.shard.ShardType; import net.modfest.scatteredshards.client.ScatteredShardsClient; import net.modfest.scatteredshards.client.screen.widget.WLeftRightPanel; import net.modfest.scatteredshards.client.screen.widget.WShardPanel; @@ -28,6 +29,9 @@ import java.util.List; public class ShardTabletGuiDescription extends LightweightGuiDescription { + public static int INITIAL_SCROLL_POSITION = 0; + public static Identifier INITIAL_SHARD = ShardType.MISSING_ID; + protected final ShardCollection collection; protected final ShardLibrary library; @@ -39,8 +43,7 @@ public ShardTabletGuiDescription(ShardCollection collection, ShardLibrary librar this.collection = collection; this.library = library; - shardPanel.setShard(Shard.MISSING_SHARD); - shardPanel.setHidden(true); + shardPanel.setShard(library.shards().get(INITIAL_SHARD).orElse(Shard.MISSING_SHARD)); List ids = new ArrayList<>(this.library.shardSets().keySet()); ids.sort(Comparator.comparing(Identifier::getNamespace)); @@ -84,6 +87,17 @@ public ShardTabletGuiDescription(ShardCollection collection, ShardLibrary librar this.setRootPanel(root); root.validate(this); + + if (shardPanel.getShard() == Shard.MISSING_SHARD && INITIAL_SCROLL_POSITION >= 0) { // Only reload scrolling without a selected shard + shardSelector.getScrollBar().setValue(INITIAL_SCROLL_POSITION); + } else if (shardPanel.getShard() != Shard.MISSING_SHARD) { // Try scroll to relevant shard set + for (int i = 0; i < ids.size(); i++) { + if (library.shardSets().get(ids.get(i)).contains(INITIAL_SHARD)) { + shardSelector.getScrollBar().setValue(i - 3); // 7 rows on screen, so center by -3 + break; + } + } + } } private int getLayoutWidth(WPanelWithInsets panel) { @@ -111,5 +125,14 @@ public static class Screen extends CottonClientScreen { public Screen(ShardCollection collection, ShardLibrary library) { super(new ShardTabletGuiDescription(collection, library)); } + + @Override + public void close() { + if (description instanceof ShardTabletGuiDescription desc) { // Silly, but description has no onClose. + INITIAL_SCROLL_POSITION = desc.shardSelector.getScrollBar().getValue(); + INITIAL_SHARD = desc.library.shards().get(desc.shardPanel.getShard()).orElse(ShardType.MISSING_ID); + } + super.close(); + } } } diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WMiniShard.java b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WMiniShard.java index 7bdc411..30bc8db 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WMiniShard.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WMiniShard.java @@ -7,7 +7,10 @@ import io.github.cottonmc.cotton.gui.widget.data.InputResult; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; @@ -17,12 +20,14 @@ import net.modfest.scatteredshards.api.shard.ShardIconOffsets; import net.modfest.scatteredshards.api.shard.ShardType; import net.modfest.scatteredshards.client.ScatteredShardsClient; +import net.modfest.scatteredshards.client.screen.ShardTabletGuiDescription; import net.modfest.scatteredshards.util.ModMetaUtil; import java.util.function.Consumer; public class WMiniShard extends WWidget { private static final Identifier MINI_OUTLINE = ScatteredShards.id("textures/gui/shards/mini_outline.png"); + private static final Identifier MINI_OUTLINE_SLIGHT = ScatteredShards.id("textures/gui/shards/mini_outline_slight.png"); protected Shard shard = null; protected ShardType shardType = null; @@ -77,8 +82,14 @@ public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { ScreenDrawing.texturedRect(context, x - 2, y - 2, 16, 20, MINI_OUTLINE, 0, 0, 1, 1, 0xFF_FFFFFF); renderTooltip(context, x, y, mouseX, mouseY); + } else if ( // Awful bullshit write real code later + MinecraftClient.getInstance().currentScreen instanceof ShardTabletGuiDescription.Screen stgds + && stgds.getDescription().getRootPanel() instanceof WLeftRightPanel wlrp + && wlrp.rightPanel instanceof WShardPanel wsp + && wsp.getShard() == shard + ) { + ScreenDrawing.texturedRect(context, x - 2, y - 2, 16, 20, MINI_OUTLINE_SLIGHT, 0, 0, 1, 1, 0xFF_FFFFFF); } - } @Override @@ -101,6 +112,7 @@ public void addTooltip(TooltipBuilder tooltip) { @Override public InputResult onClick(int x, int y, int button) { if (button == 0) { + MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK.value(), 1.0f, 0.25f)); shardConsumer.accept(shard); return InputResult.PROCESSED; } else { @@ -117,9 +129,4 @@ public int getWidth() { public int getHeight() { return 16; } - - @Override - public boolean canResize() { - return false; - } } diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardPanel.java b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardPanel.java index b297c00..e0e0822 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardPanel.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardPanel.java @@ -112,9 +112,12 @@ public WShardPanel setHint(Supplier text, IntSupplier color) { } public WShardPanel setShard(Shard shard) { + if (this.shard == shard) { + return setShard(Shard.MISSING_SHARD); + } shard.icon().ifRight(ModMetaUtil::touchIconTexture); this.shard = shard; - this.isHidden = false; + this.isHidden = shard == Shard.MISSING_SHARD; setType(shard.shardTypeId(), ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING)); icon.setIcon(shard::icon); @@ -214,10 +217,6 @@ public void addPainters() { }); } - public WShardPanel(Shard shard) { - setShard(shard); - } - public Shard getShard() { return shard; } diff --git a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java index 592067e..86e2a49 100644 --- a/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java +++ b/src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardSetPanel.java @@ -18,7 +18,6 @@ public class WShardSetPanel extends WPanelWithInsets { private static final int MINI_SHARD_WIDTH = 12; - //private static final int MINI_SHARD_HALFWIDTH = MINI_SHARD_WIDTH / 2; private static final int MINI_SHARD_HEIGHT = 16; protected Consumer shardConsumer = (it) -> { @@ -97,20 +96,4 @@ public void setShardSet(Identifier setId, ShardLibrary library, ShardCollection if (host != null) this.validate(host); } - - /* - //TODO: Replace with json / ShardType field - private static int shardPriority(String path) { - return switch(path) { - case "scattered_shards_visitor" -> 0; - case "scattered_shards_challenge" -> 1; - case "scattered_shards_secret" -> 2; - default -> Integer.MAX_VALUE; - }; - } - - private static int shardComparator(Identifier a, Identifier b) { - - return Integer.compare(shardPriority(a.getPath()), shardPriority(b.getPath())); - }*/ } diff --git a/src/main/java/net/modfest/scatteredshards/command/BlockCommand.java b/src/main/java/net/modfest/scatteredshards/command/BlockCommand.java index d726929..40bdb11 100644 --- a/src/main/java/net/modfest/scatteredshards/command/BlockCommand.java +++ b/src/main/java/net/modfest/scatteredshards/command/BlockCommand.java @@ -13,7 +13,6 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.modfest.scatteredshards.ScatteredShards; -import net.modfest.scatteredshards.ScatteredShardsContent; import net.modfest.scatteredshards.api.ScatteredShardsAPI; import net.modfest.scatteredshards.api.ShardLibrary; import net.modfest.scatteredshards.block.ShardBlock; @@ -32,7 +31,7 @@ public static int blockCommand(CommandContext ctx, boolean ItemStack stack = ShardBlock.createShardBlock(library, shardId, canInteract, glowSize, glowStrength); - if (!player.giveItemStack(stack)) throw ShardCommand.NO_ROOM_FOR_ITEM.create(ScatteredShardsContent.SHARD_BLOCK_ITEM.getName()); + player.getInventory().offerOrDrop(stack); ctx.getSource().sendFeedback(() -> Text.stringifiedTranslatable("commands.scattered_shards.shard.block", shardId), false); return Command.SINGLE_SUCCESS; diff --git a/src/main/java/net/modfest/scatteredshards/command/ShardCommand.java b/src/main/java/net/modfest/scatteredshards/command/ShardCommand.java index 563412d..d707852 100644 --- a/src/main/java/net/modfest/scatteredshards/command/ShardCommand.java +++ b/src/main/java/net/modfest/scatteredshards/command/ShardCommand.java @@ -10,10 +10,6 @@ public class ShardCommand { it -> Text.stringifiedTranslatable("error.scattered_shards.invalid_shard_id", it) ); - public static final DynamicCommandExceptionType NO_ROOM_FOR_ITEM = new DynamicCommandExceptionType( - it -> Text.translatable("error.scattered_shards.no_inventory_room", it) - ); - public static final DynamicCommandExceptionType INVALID_SHARD_TYPE = new DynamicCommandExceptionType( it -> Text.translatable("error.scattered_shards.invalid_shard_type", it) ); diff --git a/src/main/java/net/modfest/scatteredshards/networking/S2CUpdateShard.java b/src/main/java/net/modfest/scatteredshards/networking/S2CUpdateShard.java index 7a37ced..1146f55 100644 --- a/src/main/java/net/modfest/scatteredshards/networking/S2CUpdateShard.java +++ b/src/main/java/net/modfest/scatteredshards/networking/S2CUpdateShard.java @@ -28,7 +28,7 @@ public static void receive(S2CUpdateShard payload, ClientPlayNetworking.Context context.client().execute(() -> { switch (payload.mode()) { case COLLECT -> { - ScatteredShardsClient.triggerShardCollectAnimation(payload.shardId()); + ScatteredShardsClient.onShardCollected(payload.shardId()); ScatteredShardsAPI.getClientCollection().add(payload.shardId()); } case UNCOLLECT -> ScatteredShardsAPI.getClientCollection().remove(payload.shardId()); @@ -54,4 +54,4 @@ public enum Mode { public static final PacketCodec PACKET_CODEC = PacketCodecs.INTEGER.xmap(val -> Mode.values()[val], Mode::ordinal).cast(); } -} \ No newline at end of file +} diff --git a/src/main/resources/assets/scattered_shards/lang/en_us.json b/src/main/resources/assets/scattered_shards/lang/en_us.json index bb250bf..357c5e7 100644 --- a/src/main/resources/assets/scattered_shards/lang/en_us.json +++ b/src/main/resources/assets/scattered_shards/lang/en_us.json @@ -1,13 +1,8 @@ { - "error.scattered_shards.invalid_set_id": "Unknown shard set '%s'", - "error.scattered_shards.invalid_mod_id": "Unknown mod ID '%s'", - "error.scattered_shards.invalid_shard_type": "Unknown shard type '%s'", - "error.scattered_shards.invalid_shard_id": "Unknown shard '%s'", - "error.scattered_shards.no_inventory_room": "There's no inventory room for this %s", - "error.scattered_shards.shard_not_in_collection": "Shard '%s' was not in your collection", - "shard_type.scattered_shards.missing.description": "Missing Shard", - "scattered_shards.toast.collect": "Shard Collected!", - "argument.scattered_shards.shard.invalid": "Unknown shard '%s'", + "block.scattered_shards.shard_block": "Shard", + + "item.scattered_shards.shard_tablet": "Shard Tablet", + "commands.scattered_shards.shard.collect": "Collected shard '%s'", "commands.scattered_shards.shard.award": "Awarded shard '%s' to %s players", "commands.scattered_shards.shard.award.none": "Tried to award shard '%s' but no players are eligible", @@ -17,6 +12,27 @@ "commands.scattered_shards.shard.library.delete": "Deleted shard '%s' from the library", "commands.scattered_shards.shard.library.delete.all": "Deleted %s shards from the library", "commands.scattered_shards.shard.library.migrate": "Migrated shard %s to %s", + + "error.scattered_shards.invalid_set_id": "Unknown shard set '%s'", + "error.scattered_shards.invalid_shard_type": "Unknown shard type '%s'", + "error.scattered_shards.invalid_shard_id": "Unknown shard '%s'", + + "shard_type.scattered_shards.visitor.description": "Visitor Shard", + "shard_type.scattered_shards.challenge.description": "Challenge Shard", + "shard_type.scattered_shards.secret.description": "Secret Shard", + + "key.scattered_shards.collection": "View Shard Collection", + + "key.categories.scattered_shards": "Scattered Shards", + + "menu.scattered_shards.collection": "Shard Collection", + + "toast.scattered_shards.collected": "Shard Collected!", + "toast.scattered_shards.collected.prompt": "Press [%s] to view", + "toast.scattered_shards.shard_mod.title": "Shard Modification", + "toast.scattered_shards.shard_mod.success": "Successfully modified '%s'", + "toast.scattered_shards.shard_mod.fail": "Failed to modify '%s'", + "gui.scattered_shards.creator.title": "Shard Creator", "gui.scattered_shards.creator.field.name": "Name...", "gui.scattered_shards.creator.field.lore": "Lore...", @@ -31,16 +47,5 @@ "gui.scattered_shards.tablet.click_on_a_shard": "Click on a Shard to the left", "gui.scattered_shards.tablet.tooltip.global_collection": "%s of players have this shard", "gui.scattered_shards.tablet.label.progress.started": "%s Started", - "gui.scattered_shards.tablet.label.progress.total": "%s Total", - "menu.scattered_shards.collection": "Shard Collection", - "toast.scattered_shards.shard_mod.title": "Shard Modification", - "toast.scattered_shards.shard_mod.success": "Successfully modified '%s'", - "toast.scattered_shards.shard_mod.fail": "Failed to modify '%s'", - "block.scattered_shards.shard_block": "Shard", - "block.scattered_shards.shard_block.pickup_fail": "Shard already collected!", - "item.scattered_shards.shard_tablet": "Shard Tablet", - - "shard_type.scattered_shards.visitor.description": "Visitor Shard", - "shard_type.scattered_shards.challenge.description": "Challenge Shard", - "shard_type.scattered_shards.secret.description": "Secret Shard" + "gui.scattered_shards.tablet.label.progress.total": "%s Total" } diff --git a/src/main/resources/assets/scattered_shards/textures/gui/shards/mini_outline_slight.png b/src/main/resources/assets/scattered_shards/textures/gui/shards/mini_outline_slight.png new file mode 100644 index 0000000000000000000000000000000000000000..7c04cd653dd2e593d24ea019792fb1ebe37c4c08 GIT binary patch literal 221 zcmV<303!d1P)RTcw_O~U+HV#M{fF;Z}&UJq` zvpM&-EHD8#pa&A)nSm!TeF#ZPl16?+(ijQf7k3KTV?304%IPHy9!5GLkbuRh#IshN zp>?3Ct)Pa+f$g6aY@Yw~6RelCv09*uDJx~ZW|+dBO2-+PE?Fq{MLiEbuC&g~9=ZPu X^{7b`<1CTf00000NkvXXu0mjfhZ$E{ literal 0 HcmV?d00001