From 81ae4cb58ce72e61bb247b206eeac4073cb5032f Mon Sep 17 00:00:00 2001 From: marcus8448 Date: Fri, 12 Jan 2024 22:40:47 -0800 Subject: [PATCH] feat: expose fluid rendering api standardize tooltips redstone activation -> redstone mode (shorter) improve localization of numbers --- build.gradle.kts | 14 +++-- .../machinelib/api/block/MachineBlock.java | 6 +- .../api/block/entity/MachineBlockEntity.java | 28 ++++----- .../entity/MachinePlaceholderBlockEntity.java | 52 ----------------- .../machinelib/api/config/Config.java | 2 - .../machinelib/api/machine/MachineState.java | 4 +- .../configuration/MachineConfiguration.java | 12 ++-- ...stoneActivation.java => RedstoneMode.java} | 28 ++++----- .../machinelib/api/util/StorageHelper.java | 26 +++++++++ .../client/api/screen/MachineScreen.java | 41 +++++++------ .../client/api/util/DisplayUtil.java | 58 +++++++++++++------ .../{impl => api}/util/GraphicsUtil.java | 2 +- .../machinelib/impl/Constant.java | 28 ++++----- .../impl/config/MachineLibConfig.java | 8 --- .../machine/MachineConfigurationImpl.java | 16 ++--- .../impl/machine/MachineStateImpl.java | 4 +- .../machinelib/impl/menu/TankImpl.java | 21 +------ .../sync/MachineConfigurationSyncHandler.java | 20 +++---- .../impl/network/MachineLibC2SPackets.java | 6 +- .../assets/machinelib/lang/en_us.json | 30 ++++++---- 20 files changed, 194 insertions(+), 212 deletions(-) delete mode 100644 src/main/java/dev/galacticraft/machinelib/api/client/block/entity/MachinePlaceholderBlockEntity.java rename src/main/java/dev/galacticraft/machinelib/api/machine/configuration/{RedstoneActivation.java => RedstoneMode.java} (81%) rename src/main/java/dev/galacticraft/machinelib/client/{impl => api}/util/GraphicsUtil.java (98%) diff --git a/build.gradle.kts b/build.gradle.kts index 28db1b05..5411e911 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,7 +43,7 @@ val fabric = project.property("fabric.version").toString() plugins { java `maven-publish` - id("fabric-loom") version("1.4-SNAPSHOT") + id("fabric-loom") version("1.5-SNAPSHOT") id("org.cadixdev.licenser") version("0.6.1") id("org.ajoberstar.grgit") version("5.2.1") } @@ -108,13 +108,13 @@ loom { getByName("client") { name("Minecraft Client") source(sourceSets.getByName("testmod")) - vmArgs("-ea", "-Dfabric-api.gametest", "-Dfabric-api.gametest.report-file=${project.layout.buildDirectory}/junit.xml") + property("fabric-api.gametest") } register("gametest") { name("GameTest Server") server() source(sourceSets.getByName("testmod")) - vmArgs("-ea", "-Dfabric-api.gametest", "-Dfabric-api.gametest.report-file=${project.layout.buildDirectory}/junit.xml") + property("fabric-api.gametest") } } } @@ -134,11 +134,13 @@ repositories { dependencies { minecraft("com.mojang:minecraft:$minecraft") - mappings(loom.layered { - officialMojangMappings() - if (!parchment.isEmpty()) { + mappings(if (parchment.isNotEmpty()) { + loom.layered { + officialMojangMappings() parchment("org.parchmentmc.data:parchment-$minecraft:$parchment@zip") } + } else { + loom.officialMojangMappings() }) modImplementation("net.fabricmc:fabric-loader:$loader") testImplementation("net.fabricmc:fabric-loader-junit:$loader") diff --git a/src/main/java/dev/galacticraft/machinelib/api/block/MachineBlock.java b/src/main/java/dev/galacticraft/machinelib/api/block/MachineBlock.java index d385a7b7..9bd6757c 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/block/MachineBlock.java +++ b/src/main/java/dev/galacticraft/machinelib/api/block/MachineBlock.java @@ -25,7 +25,7 @@ import com.mojang.authlib.GameProfile; import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; import dev.galacticraft.machinelib.api.machine.configuration.AccessLevel; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.machine.configuration.SecuritySettings; import dev.galacticraft.machinelib.api.storage.MachineItemStorage; import dev.galacticraft.machinelib.api.storage.slot.ItemResourceSlot; @@ -231,8 +231,8 @@ public void appendHoverText(ItemStack stack, BlockGetter view, List t } } - if (nbt.contains(Constant.Nbt.REDSTONE_ACTIVATION, Tag.TAG_BYTE)) { - tooltip.add(Component.translatable(Constant.TranslationKey.REDSTONE_ACTIVATION, RedstoneActivation.readTag((ByteTag) Objects.requireNonNull(nbt.get(Constant.Nbt.REDSTONE_ACTIVATION))).getName()).setStyle(Constant.Text.DARK_RED_STYLE)); + if (nbt.contains(Constant.Nbt.REDSTONE_MODE, Tag.TAG_BYTE)) { + tooltip.add(Component.translatable(Constant.TranslationKey.REDSTONE_MODE, RedstoneMode.readTag((ByteTag) Objects.requireNonNull(nbt.get(Constant.Nbt.REDSTONE_MODE))).getName()).setStyle(Constant.Text.DARK_RED_STYLE)); } } } diff --git a/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java b/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java index a74f57e0..5966983e 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java +++ b/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java @@ -29,7 +29,7 @@ import dev.galacticraft.machinelib.api.machine.MachineType; import dev.galacticraft.machinelib.api.machine.configuration.MachineConfiguration; import dev.galacticraft.machinelib.api.machine.configuration.MachineIOConfig; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.machine.configuration.SecuritySettings; import dev.galacticraft.machinelib.api.menu.MachineMenu; import dev.galacticraft.machinelib.api.misc.AdjacentBlockApiCache; @@ -106,7 +106,7 @@ public abstract class MachineBlockEntity extends BlockEntity implements Extended /** * The configuration for this machine. - * This is used to store the {@link #getRedstoneActivation() redstone activation}, {@link #getIOConfig() I/O configuration}, + * This is used to store the {@link #getRedstoneMode() redstone mode}, {@link #getIOConfig() I/O configuration}, * and {@link #getSecurity() security} settings for this machine. * * @see MachineConfiguration @@ -284,14 +284,14 @@ public long getEnergyItemExtractionRate() { } /** - * Sets the redstone activation mode of this machine. + * Sets the redstone mode mode of this machine. * - * @param redstone the redstone activation mode to use. - * @see #getRedstoneActivation() + * @param redstone the redstone mode mode to use. + * @see #getRedstoneMode() */ @Contract(mutates = "this") - public void setRedstone(@NotNull RedstoneActivation redstone) { - this.configuration.setRedstoneActivation(redstone); + public void setRedstone(@NotNull RedstoneMode redstone) { + this.configuration.setRedstoneMode(redstone); } /** @@ -344,12 +344,12 @@ public void setRedstone(@NotNull RedstoneActivation redstone) { * Dictates how this machine should react to redstone. * * @return how the machine reacts when it interacts with redstone. - * @see RedstoneActivation - * @see #setRedstone(RedstoneActivation) + * @see RedstoneMode + * @see #setRedstone(RedstoneMode) */ @Contract(pure = true) - public final @NotNull RedstoneActivation getRedstoneActivation() { - return this.configuration.getRedstoneActivation(); + public final @NotNull RedstoneMode getRedstoneMode() { + return this.configuration.getRedstoneMode(); } /** @@ -396,11 +396,11 @@ public boolean areDropsDisabled() { * Returns whether the current machine is enabled. * * @return whether the current machine is enabled. - * @see RedstoneActivation - * @see #getRedstoneActivation() + * @see RedstoneMode + * @see #getRedstoneMode() */ public boolean isDisabled() { - return !this.getRedstoneActivation().isActive(this.state.isPowered()); + return !this.getRedstoneMode().isActive(this.state.isPowered()); } /** diff --git a/src/main/java/dev/galacticraft/machinelib/api/client/block/entity/MachinePlaceholderBlockEntity.java b/src/main/java/dev/galacticraft/machinelib/api/client/block/entity/MachinePlaceholderBlockEntity.java deleted file mode 100644 index f082a4e3..00000000 --- a/src/main/java/dev/galacticraft/machinelib/api/client/block/entity/MachinePlaceholderBlockEntity.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021-2024 Team Galacticraft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package dev.galacticraft.machinelib.api.client.block.entity; - -import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; -import dev.galacticraft.machinelib.api.machine.MachineType; -import dev.galacticraft.machinelib.api.menu.MachineMenu; -import net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity; -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class MachinePlaceholderBlockEntity extends BlockEntity implements RenderDataBlockEntity { - public MachinePlaceholderBlockEntity(@NotNull MachineType> type, BlockPos pos, BlockState blockState) { - super(type.getBlockEntityType(), pos, blockState); - } - - @Nullable - @Override - public Packet getUpdatePacket() { - return null; - } - - @Override - public @Nullable Object getRenderData() { - return super.getRenderData(); - } -} diff --git a/src/main/java/dev/galacticraft/machinelib/api/config/Config.java b/src/main/java/dev/galacticraft/machinelib/api/config/Config.java index 97cb0f57..f8b3c942 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/config/Config.java +++ b/src/main/java/dev/galacticraft/machinelib/api/config/Config.java @@ -36,8 +36,6 @@ static Config create() { long bucketBreakpoint(); - long megaGjBreakpoint(); - void copyFrom(Config config); @ApiStatus.Internal diff --git a/src/main/java/dev/galacticraft/machinelib/api/machine/MachineState.java b/src/main/java/dev/galacticraft/machinelib/api/machine/MachineState.java index b4fccabc..6c98794b 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/machine/MachineState.java +++ b/src/main/java/dev/galacticraft/machinelib/api/machine/MachineState.java @@ -22,7 +22,7 @@ package dev.galacticraft.machinelib.api.machine; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.menu.sync.MenuSynchronizable; import dev.galacticraft.machinelib.api.misc.Deserializable; import dev.galacticraft.machinelib.impl.machine.MachineStateImpl; @@ -57,7 +57,7 @@ public interface MachineState extends MenuSynchronizable, Deserializable, MenuS @NotNull SecuritySettings getSecurity(); /** - * Returns the redstone activation of the machine. + * Returns the redstone mode of the machine. * - * @return The redstone activation of the machine. + * @return The redstone mode of the machine. */ @Contract(pure = true) - @NotNull RedstoneActivation getRedstoneActivation(); + @NotNull RedstoneMode getRedstoneMode(); /** - * Sets the redstone activation of the machine. + * Sets the redstone mode of the machine. * - * @param redstone The redstone activation of the machine. + * @param redstone The redstone mode of the machine. */ @Contract(mutates = "this") - void setRedstoneActivation(@NotNull RedstoneActivation redstone); + void setRedstoneMode(@NotNull RedstoneMode redstone); } diff --git a/src/main/java/dev/galacticraft/machinelib/api/machine/configuration/RedstoneActivation.java b/src/main/java/dev/galacticraft/machinelib/api/machine/configuration/RedstoneMode.java similarity index 81% rename from src/main/java/dev/galacticraft/machinelib/api/machine/configuration/RedstoneActivation.java rename to src/main/java/dev/galacticraft/machinelib/api/machine/configuration/RedstoneMode.java index 68dbc36d..26b573ff 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/machine/configuration/RedstoneActivation.java +++ b/src/main/java/dev/galacticraft/machinelib/api/machine/configuration/RedstoneMode.java @@ -33,7 +33,7 @@ /** * Dictates how a machine behaves when it interacts with redstone. */ -public enum RedstoneActivation implements StringRepresentable { +public enum RedstoneMode implements StringRepresentable { /** * Ignores redstone entirely (always running). */ @@ -49,20 +49,20 @@ public enum RedstoneActivation implements StringRepresentable { */ HIGH(Component.translatable(Constant.TranslationKey.HIGH_REDSTONE).setStyle(Constant.Text.RED_STYLE)); - public static final RedstoneActivation[] VALUES = RedstoneActivation.values(); + public static final RedstoneMode[] VALUES = RedstoneMode.values(); /** - * The text of the redstone activation state. + * The text of the redstone mode state. */ private final @NotNull Component name; /** - * Constructs a redstone activation type with the given text. + * Constructs a redstone mode type with the given text. * * @param name the name of the interaction. */ @Contract(pure = true) - RedstoneActivation(@NotNull Component name) { + RedstoneMode(@NotNull Component name) { this.name = name; } @@ -75,30 +75,30 @@ public boolean isActive(boolean powered) { } /** - * Deserializes an activation state from NBT. + * Deserializes an redstone mode from NBT. * * @param tag the NBT. - * @return the activation state. + * @return the redstone mode. * @see #createTag() */ - public static @NotNull RedstoneActivation readTag(@NotNull ByteTag tag) { + public static @NotNull RedstoneMode readTag(@NotNull ByteTag tag) { return VALUES[tag.getAsByte()]; } /** - * Deserializes an activation state from a packet. + * Deserializes an redstone mode from a packet. * @param buf the buffer to read from - * @return the activation state + * @return the redstone mode * @see #writePacket(FriendlyByteBuf) */ - public static @NotNull RedstoneActivation readPacket(@NotNull FriendlyByteBuf buf) { + public static @NotNull RedstoneMode readPacket(@NotNull FriendlyByteBuf buf) { return VALUES[buf.readByte()]; } /** - * Returns the name of the redstone activation state. + * Returns the name of the redstone mode state. * - * @return The text of the redstone activation state. + * @return The text of the redstone mode state. */ @Contract(pure = true) public @NotNull Component getName() { @@ -117,7 +117,7 @@ public boolean isActive(boolean powered) { /** * Serializes this state as a NBT. - * @return this activation state as a tag. + * @return this redstone mode as a tag. * @see #readTag(ByteTag) */ public @NotNull ByteTag createTag() { diff --git a/src/main/java/dev/galacticraft/machinelib/api/util/StorageHelper.java b/src/main/java/dev/galacticraft/machinelib/api/util/StorageHelper.java index 03dee5c4..59dca654 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/util/StorageHelper.java +++ b/src/main/java/dev/galacticraft/machinelib/api/util/StorageHelper.java @@ -44,6 +44,30 @@ private StorageHelper() { throw new UnsupportedOperationException("Utility class cannot be instantiated"); } + public static , S extends Storage> long calculateCapacity(Variant variant, @NotNull S storage, @Nullable TransactionContext context) { + if (variant.isBlank()) return 0; + + long capacity = 0; + for (StorageView view : storage) { + if (variant.equals(view.getResource())) { + capacity += view.getCapacity(); + } + } + return capacity; + } + + public static , S extends Storage> long calculateAmount(Variant variant, @NotNull S storage, @Nullable TransactionContext context) { + if (variant.isBlank()) return 0; + + long amount = 0; + for (StorageView view : storage) { + if (variant.equals(view.getResource())) { + amount += view.getAmount(); + } + } + return amount; + } + public static , S extends Storage> long move(Variant variant, @Nullable StorageAccess from, @Nullable S to, long maxAmount, @Nullable TransactionContext context) { if (from == null || to == null || variant.isBlank() || maxAmount == 0) return 0; StoragePreconditions.notNegative(maxAmount); @@ -193,4 +217,6 @@ public static , S extends St } return changed; } + + public record StorageContents(long amount, long capacity) {} } diff --git a/src/main/java/dev/galacticraft/machinelib/client/api/screen/MachineScreen.java b/src/main/java/dev/galacticraft/machinelib/client/api/screen/MachineScreen.java index 6b87fe21..e3959837 100644 --- a/src/main/java/dev/galacticraft/machinelib/client/api/screen/MachineScreen.java +++ b/src/main/java/dev/galacticraft/machinelib/client/api/screen/MachineScreen.java @@ -30,7 +30,7 @@ import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; import dev.galacticraft.machinelib.api.machine.configuration.AccessLevel; import dev.galacticraft.machinelib.api.machine.configuration.MachineIOFace; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.menu.MachineMenu; import dev.galacticraft.machinelib.api.storage.slot.FluidResourceSlot; import dev.galacticraft.machinelib.api.storage.slot.ItemResourceSlot; @@ -40,8 +40,8 @@ import dev.galacticraft.machinelib.api.util.BlockFace; import dev.galacticraft.machinelib.client.api.render.MachineRenderData; import dev.galacticraft.machinelib.client.api.util.DisplayUtil; +import dev.galacticraft.machinelib.client.api.util.GraphicsUtil; import dev.galacticraft.machinelib.client.impl.model.MachineBakedModel; -import dev.galacticraft.machinelib.client.impl.util.GraphicsUtil; import dev.galacticraft.machinelib.impl.Constant; import dev.galacticraft.machinelib.impl.compat.vanilla.StorageSlot; import io.netty.buffer.ByteBufAllocator; @@ -59,7 +59,6 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.util.FormattedCharSequence; @@ -236,7 +235,9 @@ protected void init() { * * @param list The list to append to. */ - public void appendEnergyTooltip(List list) { + public void appendEnergyTooltip(List lines) { + lines.add(Component.translatable(Constant.TranslationKey.STATUS).setStyle(Constant.Text.GRAY_STYLE).append(this.menu.state.getStatusText(this.menu.configuration.getRedstoneMode()))); + lines.add(DisplayUtil.createEnergyTooltip(this.menu.energyStorage.getAmount(), this.menu.energyStorage.getCapacity())); } /** @@ -267,20 +268,20 @@ protected void drawConfigurationPanels(@NotNull GuiGraphics graphics, int mouseX if (Tab.REDSTONE.isOpen()) { poseStack.pushPose(); poseStack.translate(-PANEL_WIDTH, SPACING, 0); - this.drawButton(graphics, REDSTONE_IGNORE_X, REDSTONE_IGNORE_Y, mouseX + PANEL_WIDTH - this.leftPos, mouseY - SPACING - this.topPos, menu.configuration.getRedstoneActivation() == RedstoneActivation.IGNORE); - this.drawButton(graphics, REDSTONE_LOW_X, REDSTONE_LOW_Y, mouseX + PANEL_WIDTH - this.leftPos, mouseY - SPACING - this.topPos, menu.configuration.getRedstoneActivation() == RedstoneActivation.LOW); - this.drawButton(graphics, REDSTONE_HIGH_X, REDSTONE_HIGH_Y, mouseX + PANEL_WIDTH - this.leftPos, mouseY - SPACING - this.topPos, menu.configuration.getRedstoneActivation() == RedstoneActivation.HIGH); + this.drawButton(graphics, REDSTONE_IGNORE_X, REDSTONE_IGNORE_Y, mouseX + PANEL_WIDTH - this.leftPos, mouseY - SPACING - this.topPos, menu.configuration.getRedstoneMode() == RedstoneMode.IGNORE); + this.drawButton(graphics, REDSTONE_LOW_X, REDSTONE_LOW_Y, mouseX + PANEL_WIDTH - this.leftPos, mouseY - SPACING - this.topPos, menu.configuration.getRedstoneMode() == RedstoneMode.LOW); + this.drawButton(graphics, REDSTONE_HIGH_X, REDSTONE_HIGH_Y, mouseX + PANEL_WIDTH - this.leftPos, mouseY - SPACING - this.topPos, menu.configuration.getRedstoneMode() == RedstoneMode.HIGH); graphics.renderFakeItem(REDSTONE, PANEL_ICON_X, PANEL_ICON_Y); graphics.renderFakeItem(GUNPOWDER, REDSTONE_IGNORE_X, REDSTONE_IGNORE_Y); graphics.renderFakeItem(UNLIT_TORCH, REDSTONE_LOW_X, REDSTONE_LOW_Y - 2); graphics.renderFakeItem(REDSTONE_TORCH, REDSTONE_HIGH_X, REDSTONE_HIGH_Y - 2); - graphics.drawString(this.font, Component.translatable(Constant.TranslationKey.REDSTONE_ACTIVATION) + graphics.drawString(this.font, Component.translatable(Constant.TranslationKey.REDSTONE_MODE) .setStyle(Constant.Text.GRAY_STYLE), PANEL_TITLE_X, PANEL_TITLE_Y, 0xFFFFFFFF); graphics.drawString(this.font, Component.translatable(Constant.TranslationKey.REDSTONE_STATE, - menu.configuration.getRedstoneActivation().getName()).setStyle(Constant.Text.GRAY_STYLE), REDSTONE_STATE_TEXT_X, REDSTONE_STATE_TEXT_Y, 0xFFFFFFFF); + menu.configuration.getRedstoneMode().getName()).setStyle(Constant.Text.GRAY_STYLE), REDSTONE_STATE_TEXT_X, REDSTONE_STATE_TEXT_Y, 0xFFFFFFFF); graphics.drawString(this.font, Component.translatable(Constant.TranslationKey.REDSTONE_STATUS, - this.menu.configuration.getRedstoneActivation().isActive(this.menu.state.isPowered()) ? + this.menu.configuration.getRedstoneMode().isActive(this.menu.state.isPowered()) ? Component.translatable(Constant.TranslationKey.REDSTONE_ACTIVE).setStyle(Constant.Text.GREEN_STYLE) : Component.translatable(Constant.TranslationKey.REDSTONE_DISABLED).setStyle(Constant.Text.DARK_RED_STYLE)) .setStyle(Constant.Text.GRAY_STYLE), REDSTONE_STATUS_TEXT_X, REDSTONE_STATUS_TEXT_Y + this.font.lineHeight, 0xFFFFFFFF); @@ -412,17 +413,17 @@ public boolean checkConfigurationPanelClick(double mouseX, double mouseY, int bu return true; } if (mouseIn(mouseX, mouseY, REDSTONE_IGNORE_X, REDSTONE_IGNORE_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) { - this.setRedstone(RedstoneActivation.IGNORE); + this.setRedstone(RedstoneMode.IGNORE); this.playButtonSound(); return true; } if (mouseIn(mouseX, mouseY, REDSTONE_LOW_X, REDSTONE_LOW_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) { - this.setRedstone(RedstoneActivation.LOW); + this.setRedstone(RedstoneMode.LOW); this.playButtonSound(); return true; } if (mouseIn(mouseX, mouseY, REDSTONE_HIGH_X, REDSTONE_HIGH_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) { - this.setRedstone(RedstoneActivation.HIGH); + this.setRedstone(RedstoneMode.HIGH); this.playButtonSound(); return true; } @@ -551,8 +552,8 @@ protected void setAccessibility(@NotNull AccessLevel accessLevel) { * * @param redstone The redstone mode to set. */ - protected void setRedstone(@NotNull RedstoneActivation redstone) { - this.menu.configuration.setRedstoneActivation(redstone); + protected void setRedstone(@NotNull RedstoneMode redstone) { + this.menu.configuration.setRedstoneMode(redstone); PacketSender.c2s().send(Constant.id("redstone_config"), new FriendlyByteBuf(ByteBufAllocator.DEFAULT.buffer(1, 1).writeByte(redstone.ordinal()))); } @@ -571,19 +572,19 @@ protected void drawConfigurationPanelTooltips(GuiGraphics graphics, int mouseX, mouseX += PANEL_WIDTH; mouseY -= SPACING; if (mouseIn(mouseX, mouseY, REDSTONE_IGNORE_X, REDSTONE_IGNORE_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) { - graphics.renderTooltip(this.font, RedstoneActivation.IGNORE.getName(), mX, mY); + graphics.renderTooltip(this.font, RedstoneMode.IGNORE.getName(), mX, mY); } if (mouseIn(mouseX, mouseY, REDSTONE_LOW_X, REDSTONE_LOW_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) { - graphics.renderTooltip(this.font, RedstoneActivation.LOW.getName(), mX, mY); + graphics.renderTooltip(this.font, RedstoneMode.LOW.getName(), mX, mY); } if (mouseIn(mouseX, mouseY, REDSTONE_HIGH_X, REDSTONE_HIGH_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) { - graphics.renderTooltip(this.font, RedstoneActivation.HIGH.getName(), mX, mY); + graphics.renderTooltip(this.font, RedstoneMode.HIGH.getName(), mX, mY); } } else { mouseX += TAB_WIDTH; mouseY -= SPACING; if (mouseIn(mouseX, mouseY, 0, 0, TAB_WIDTH, TAB_HEIGHT)) { - graphics.renderTooltip(this.font, Component.translatable(Constant.TranslationKey.REDSTONE_ACTIVATION).setStyle(Constant.Text.RED_STYLE), mX, mY); + graphics.renderTooltip(this.font, Component.translatable(Constant.TranslationKey.REDSTONE_MODE).setStyle(Constant.Text.RED_STYLE), mX, mY); } } mouseX = mX - this.leftPos; @@ -743,8 +744,6 @@ protected void drawCapacitor(GuiGraphics graphics, int mouseX, int mouseY) { if (mouseIn(mouseX, mouseY, this.leftPos + this.capacitorX, this.topPos + this.capacitorY, 16, this.capacitorHeight)) { List lines = new ArrayList<>(); - lines.add(Component.translatable(Constant.TranslationKey.STATUS).setStyle(Constant.Text.GRAY_STYLE).append(this.menu.state.getStatusText(this.menu.configuration.getRedstoneActivation()))); - lines.add(Component.translatable(Constant.TranslationKey.CURRENT_ENERGY, DisplayUtil.formatEnergy(amount).setStyle(Style.EMPTY.withColor(DisplayUtil.colorScale(amount, capacity))), DisplayUtil.formatEnergy(capacity).setStyle(Constant.Text.GRAY_STYLE).setStyle(Constant.Text.LIGHT_PURPLE_STYLE))); this.appendEnergyTooltip(lines); this.setTooltipForNextRenderPass(Lists.transform(lines, Component::getVisualOrderText)); } diff --git a/src/main/java/dev/galacticraft/machinelib/client/api/util/DisplayUtil.java b/src/main/java/dev/galacticraft/machinelib/client/api/util/DisplayUtil.java index 2a9598e7..dc69e260 100644 --- a/src/main/java/dev/galacticraft/machinelib/client/api/util/DisplayUtil.java +++ b/src/main/java/dev/galacticraft/machinelib/client/api/util/DisplayUtil.java @@ -23,58 +23,64 @@ package dev.galacticraft.machinelib.client.api.util; import com.google.common.collect.ImmutableList; +import dev.galacticraft.machinelib.impl.Constant; import dev.galacticraft.machinelib.impl.MachineLib; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; +import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.contents.TranslatableContents; import net.minecraft.util.Mth; +import net.minecraft.world.level.material.Fluid; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; +import java.math.RoundingMode; import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.List; public final class DisplayUtil { - private static final DecimalFormat NUMBER_FORMAT = new DecimalFormat(); - private static final char DECIMAL_SEPARATOR; + private static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance(); static { - DECIMAL_SEPARATOR = NUMBER_FORMAT.getDecimalFormatSymbols().getDecimalSeparator(); + if (NUMBER_FORMAT instanceof DecimalFormat fmt) { + fmt.setRoundingMode(RoundingMode.FLOOR); + } NUMBER_FORMAT.setGroupingUsed(true); } private DisplayUtil() {} public static String truncateDecimal(double d, int places) { //fixme R -> L languages? - if (places == 0) return NUMBER_FORMAT.format(Math.round(d)); - String s = NUMBER_FORMAT.format(d); - int dot = s.indexOf(DECIMAL_SEPARATOR); - if (dot == -1) { - return s; - } - return s.substring(0, Math.min(s.length(), dot + 1 + places)); + NUMBER_FORMAT.setMaximumFractionDigits(places); + return NUMBER_FORMAT.format(d); + } + + @Contract(pure = true, value = "_ -> new") + public static @NotNull MutableComponent formatNumber(long amount) { + return Component.literal(NUMBER_FORMAT.format(amount)); } @Contract(pure = true, value = "_ -> new") public static @NotNull MutableComponent formatEnergy(long amount) { - if (amount >= MachineLib.CONFIG.megaGjBreakpoint()) { - return Component.literal(truncateDecimal(amount / 1_000_000.0, 3) + " MgJ"); - } else { - return Component.literal(NUMBER_FORMAT.format(amount) + " gJ"); - } + return formatNumber(amount).append(Component.translatable(Constant.TranslationKey.UNIT_GJ)); } @Contract(pure = true, value = "_, _ -> new") public static @NotNull MutableComponent formatFluid(long amount, boolean forceDetail) { return forceDetail || amount < MachineLib.CONFIG.bucketBreakpoint() ? - Component.literal(truncateDecimal((double) amount / ((double)(FluidConstants.BUCKET / 1000)), 0) + "mB") - : Component.literal(truncateDecimal((double) amount / (double) FluidConstants.BUCKET, 2) + "B"); + Component.literal(truncateDecimal((double) amount / ((double)(FluidConstants.BUCKET / 1000)), 0)).append(Component.translatable(Constant.TranslationKey.UNIT_MILLIBUCKET)) + : Component.literal(truncateDecimal((double) amount / (double) FluidConstants.BUCKET, 2)).append(Component.translatable(Constant.TranslationKey.UNIT_BUCKET)); } public static @NotNull @Unmodifiable List wrapText(@NotNull Component text, int length) { @@ -109,4 +115,22 @@ public static int colorScale(double stored, double capacity) { double scale = 1.0 - (stored < 0 ? 0.0 : (capacity == 0 ? 1.0 : (1.0 - stored / capacity))); return Mth.hsvToRgb((float) ((120.0 / 360.0) * scale), 1.0f, 0.90f); } + + public static void createFluidTooltip(@NotNull List tooltip, @Nullable Fluid fluid, @Nullable CompoundTag tag, long amount, long capacity) { + if (amount == 0) { + tooltip.add(Component.translatable(Constant.TranslationKey.TANK_EMPTY).setStyle(Constant.Text.GRAY_STYLE)); + return; + } + + tooltip.add(Component.translatable(Constant.TranslationKey.TANK_CONTENTS).setStyle(Constant.Text.GRAY_STYLE).append(FluidVariantAttributes.getName(FluidVariant.of(fluid, tag)))); + tooltip.add(Component.translatable(Constant.TranslationKey.TANK_AMOUNT).setStyle(Constant.Text.GRAY_STYLE).append(DisplayUtil.formatFluid(amount, Screen.hasShiftDown()).setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE)))); + + if (capacity != -1) { + tooltip.add(Component.translatable(Constant.TranslationKey.TANK_CAPACITY).setStyle(Constant.Text.GRAY_STYLE).append(DisplayUtil.formatFluid(capacity, Screen.hasShiftDown()).setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE)))); + } + } + + public static MutableComponent createEnergyTooltip(long amount, long capacity) { + return Component.translatable(Constant.TranslationKey.CURRENT_ENERGY, DisplayUtil.formatNumber(amount).setStyle(Style.EMPTY.withColor(DisplayUtil.colorScale(amount, capacity))), DisplayUtil.formatEnergy(capacity).setStyle(Constant.Text.LIGHT_PURPLE_STYLE)).setStyle(Constant.Text.GRAY_STYLE); + } } diff --git a/src/main/java/dev/galacticraft/machinelib/client/impl/util/GraphicsUtil.java b/src/main/java/dev/galacticraft/machinelib/client/api/util/GraphicsUtil.java similarity index 98% rename from src/main/java/dev/galacticraft/machinelib/client/impl/util/GraphicsUtil.java rename to src/main/java/dev/galacticraft/machinelib/client/api/util/GraphicsUtil.java index 5a006d2c..d22adc27 100644 --- a/src/main/java/dev/galacticraft/machinelib/client/impl/util/GraphicsUtil.java +++ b/src/main/java/dev/galacticraft/machinelib/client/api/util/GraphicsUtil.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package dev.galacticraft.machinelib.client.impl.util; +package dev.galacticraft.machinelib.client.api.util; import net.fabricmc.fabric.api.transfer.v1.client.fluid.FluidVariantRendering; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; diff --git a/src/main/java/dev/galacticraft/machinelib/impl/Constant.java b/src/main/java/dev/galacticraft/machinelib/impl/Constant.java index 98b4dc32..58980b45 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/Constant.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/Constant.java @@ -67,7 +67,7 @@ interface Nbt { String SECURITY = "Security"; String CONFIGURATION = "Configuration"; String ENERGY = "Energy"; - String REDSTONE_ACTIVATION = "RedstoneActivation"; + String REDSTONE_MODE = "RedstoneMode"; String MAX_PROGRESS = "MaxProgress"; String RESOURCE = "Resource"; String FLOW = "Flow"; @@ -159,14 +159,12 @@ interface TranslationKey { String PRESS_SHIFT = "tooltip.machinelib.press_shift"; String STATUS = "ui.machinelib.machine.status"; - String STATUS_INVALID = "status.machinelib.invalid"; String STATUS_NOT_ENOUGH_ENERGY = "status.machinelib.not_enough_energy"; String STATUS_INVALID_RECIPE = "status.machinelib.invalid_recipe"; String STATUS_OUTPUT_FULL = "status.machinelib.output_full"; String STATUS_CAPACITOR_FULL = "status.machinelib.capacitor_full"; String STATUS_ACTIVE = "status.machinelib.active"; String STATUS_IDLE = "status.machinelib.idle"; - String STATUS_OFF = "status.machinelib.off"; String CURRENT_ENERGY = "ui.machinelib.machine.current_energy"; @@ -178,18 +176,16 @@ interface TranslationKey { String ACCESS_DENIED = "ui.machinelib.machine.security.access_denied"; String OWNER = "ui.machinelib.machine.security.owner"; - String REDSTONE_ACTIVATION = "ui.machinelib.machine.redstone_activation"; - String IGNORE_REDSTONE = "ui.machinelib.machine.redstone_activation.ignored"; - String LOW_REDSTONE = "ui.machinelib.machine.redstone_activation.low"; - String HIGH_REDSTONE = "ui.machinelib.machine.redstone_activation.high"; - String REDSTONE_STATE = "ui.machinelib.machine.redstone_activation.state"; - String REDSTONE_STATUS = "ui.machinelib.machine.redstone_activation.status"; - String REDSTONE_ACTIVE = "ui.machinelib.machine.redstone_activation.status.enabled"; - String REDSTONE_DISABLED = "ui.machinelib.machine.redstone_activation.status.disabled"; + String REDSTONE_MODE = "ui.machinelib.machine.redstone_mode"; + String IGNORE_REDSTONE = "ui.machinelib.machine.redstone_mode.ignored"; + String LOW_REDSTONE = "ui.machinelib.machine.redstone_mode.low"; + String HIGH_REDSTONE = "ui.machinelib.machine.redstone_mode.high"; + String REDSTONE_STATE = "ui.machinelib.machine.redstone_mode.state"; + String REDSTONE_STATUS = "ui.machinelib.machine.redstone_mode.status"; + String REDSTONE_ACTIVE = "ui.machinelib.machine.redstone_mode.status.enabled"; + String REDSTONE_DISABLED = "ui.machinelib.machine.redstone_mode.status.disabled"; String CONFIGURATION = "ui.machinelib.machine.configuration"; - String GROUP = "ui.machinelib.machine.configuration.group"; - String SLOT = "ui.machinelib.machine.configuration.slot"; String STATISTICS = "ui.machinelib.machine.statistics"; @@ -212,8 +208,14 @@ interface TranslationKey { String TANK_CONTENTS = "ui.machinelib.machine.tank.contents"; String TANK_AMOUNT = "ui.machinelib.machine.tank.contents.amount"; + String TANK_CAPACITY = "ui.machinelib.machine.tank.contents.capacity"; String TANK_EMPTY = "ui.machinelib.machine.tank.contents.empty"; + String UNIT_GJ = "ui.machinelib.units.energy.base"; + String UNIT_MEGA_GJ = "ui.machinelib.units.energy.mega"; + String UNIT_BUCKET = "ui.machinelib.units.fluid.base"; + String UNIT_MILLIBUCKET = "ui.machinelib.units.fluid.milli"; + String UNKNOWN_STATUS = "status.machinelib.unknown"; String DISABLED = "status.machinelib.disabled"; String UNKNOWN = "tooltip.machinelib.machine.unknown"; diff --git a/src/main/java/dev/galacticraft/machinelib/impl/config/MachineLibConfig.java b/src/main/java/dev/galacticraft/machinelib/impl/config/MachineLibConfig.java index ce434af2..1db87dd1 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/config/MachineLibConfig.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/config/MachineLibConfig.java @@ -43,8 +43,6 @@ public MachineLibConfig() {} public boolean enableColouredVanillaFluidNames = true; @Expose public long bucketBreakpoint = FluidConstants.BUCKET * 100; - @Expose - public long megaGjBreakpoint = 1_000_000; @Override public boolean enableColouredVanillaFluidNames() { @@ -56,16 +54,10 @@ public long bucketBreakpoint() { return this.bucketBreakpoint; } - @Override - public long megaGjBreakpoint() { - return this.megaGjBreakpoint; - } - @Override public void copyFrom(Config config) { this.enableColouredVanillaFluidNames = config.enableColouredVanillaFluidNames(); this.bucketBreakpoint = config.bucketBreakpoint(); - this.megaGjBreakpoint = config.megaGjBreakpoint(); } @Override diff --git a/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineConfigurationImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineConfigurationImpl.java index 409a3b61..d46a0eaf 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineConfigurationImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineConfigurationImpl.java @@ -24,7 +24,7 @@ import dev.galacticraft.machinelib.api.machine.configuration.MachineConfiguration; import dev.galacticraft.machinelib.api.machine.configuration.MachineIOConfig; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.machine.configuration.SecuritySettings; import dev.galacticraft.machinelib.api.menu.sync.MenuSyncHandler; import dev.galacticraft.machinelib.impl.Constant; @@ -41,7 +41,7 @@ public final class MachineConfigurationImpl implements MachineConfiguration { private final MachineIOConfig configuration = MachineIOConfig.create(); private final SecuritySettings security = SecuritySettings.create(); - private @NotNull RedstoneActivation redstone = RedstoneActivation.IGNORE; + private @NotNull RedstoneMode redstone = RedstoneMode.IGNORE; public MachineConfigurationImpl() { } @@ -57,12 +57,12 @@ public MachineConfigurationImpl() { } @Override - public @NotNull RedstoneActivation getRedstoneActivation() { + public @NotNull RedstoneMode getRedstoneMode() { return this.redstone; } @Override - public void setRedstoneActivation(@NotNull RedstoneActivation redstone) { + public void setRedstoneMode(@NotNull RedstoneMode redstone) { this.redstone = redstone; } @@ -71,7 +71,7 @@ public void setRedstoneActivation(@NotNull RedstoneActivation redstone) { CompoundTag tag = new CompoundTag(); tag.put(Constant.Nbt.SECURITY, this.security.createTag()); tag.put(Constant.Nbt.CONFIGURATION, this.configuration.createTag()); - tag.put(Constant.Nbt.REDSTONE_ACTIVATION, this.redstone.createTag()); + tag.put(Constant.Nbt.REDSTONE_MODE, this.redstone.createTag()); return tag; } @@ -80,8 +80,8 @@ public void readTag(@NotNull CompoundTag tag) { this.security.readTag(tag.getCompound(Constant.Nbt.SECURITY)); this.configuration.readTag(tag.getCompound(Constant.Nbt.CONFIGURATION)); - if (tag.contains(Constant.Nbt.REDSTONE_ACTIVATION)) { - this.redstone = RedstoneActivation.readTag(Objects.requireNonNull((ByteTag) tag.get(Constant.Nbt.REDSTONE_ACTIVATION))); + if (tag.contains(Constant.Nbt.REDSTONE_MODE)) { + this.redstone = RedstoneMode.readTag(Objects.requireNonNull((ByteTag) tag.get(Constant.Nbt.REDSTONE_MODE))); } } @@ -96,7 +96,7 @@ public void writePacket(@NotNull FriendlyByteBuf buf) { public void readPacket(@NotNull FriendlyByteBuf buf) { this.security.readPacket(buf); this.configuration.readPacket(buf); - this.redstone = RedstoneActivation.readPacket(buf); + this.redstone = RedstoneMode.readPacket(buf); } @Override diff --git a/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineStateImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineStateImpl.java index 5eab2fa2..af9f3c1f 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineStateImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/machine/MachineStateImpl.java @@ -24,7 +24,7 @@ import dev.galacticraft.machinelib.api.machine.MachineState; import dev.galacticraft.machinelib.api.machine.MachineStatus; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.menu.sync.MenuSyncHandler; import dev.galacticraft.machinelib.impl.Constant; import dev.galacticraft.machinelib.impl.menu.sync.MachineStateSyncHandler; @@ -48,7 +48,7 @@ public MachineStateImpl() { } @Override - public @NotNull Component getStatusText(@NotNull RedstoneActivation activation) { + public @NotNull Component getStatusText(@NotNull RedstoneMode activation) { return activation.isActive(this.powered) ? this.status != null ? this.status.getText() : Component.translatable(Constant.TranslationKey.UNKNOWN_STATUS).withStyle(ChatFormatting.GRAY) : Component.translatable(Constant.TranslationKey.DISABLED).withStyle(ChatFormatting.RED); } diff --git a/src/main/java/dev/galacticraft/machinelib/impl/menu/TankImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/menu/TankImpl.java index 72ceed43..fb2441e4 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/menu/TankImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/menu/TankImpl.java @@ -27,25 +27,18 @@ import dev.galacticraft.machinelib.api.util.StorageHelper; import dev.galacticraft.machinelib.client.api.screen.Tank; import dev.galacticraft.machinelib.client.api.util.DisplayUtil; -import dev.galacticraft.machinelib.impl.Constant; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; -import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; import net.minecraft.world.level.material.Fluid; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -144,17 +137,9 @@ public void setId(int id) { @Override public List getTooltip() { - if (this.isEmpty()) { - return Collections.singletonList(Component.translatable(Constant.TranslationKey.TANK_EMPTY).setStyle(Constant.Text.GRAY_STYLE)); - } - List lines = new ArrayList<>(2); - long amount = this.getAmount(); - - MutableComponent contents = Component.translatable(Constant.TranslationKey.TANK_CONTENTS); - - lines.add(contents.setStyle(Constant.Text.GRAY_STYLE).append(FluidVariantAttributes.getName(this.createVariant()))); - lines.add(Component.translatable(Constant.TranslationKey.TANK_AMOUNT).setStyle(Constant.Text.GRAY_STYLE).append(DisplayUtil.formatFluid(amount, Screen.hasShiftDown()).setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE)))); - return lines; + List list = new ArrayList<>(); + DisplayUtil.createFluidTooltip(list, this.getFluid(), this.getTag(), this.getAmount(), this.getCapacity()); + return list; } @Override diff --git a/src/main/java/dev/galacticraft/machinelib/impl/menu/sync/MachineConfigurationSyncHandler.java b/src/main/java/dev/galacticraft/machinelib/impl/menu/sync/MachineConfigurationSyncHandler.java index 92080588..4b5f23f7 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/menu/sync/MachineConfigurationSyncHandler.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/menu/sync/MachineConfigurationSyncHandler.java @@ -23,7 +23,7 @@ package dev.galacticraft.machinelib.impl.menu.sync; import dev.galacticraft.machinelib.api.machine.configuration.MachineConfiguration; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.menu.sync.MenuSyncHandler; import net.minecraft.network.FriendlyByteBuf; import org.jetbrains.annotations.NotNull; @@ -33,19 +33,19 @@ public class MachineConfigurationSyncHandler implements MenuSyncHandler { private final MenuSyncHandler ioConfig; private final MenuSyncHandler security; - private RedstoneActivation redstone; + private RedstoneMode redstone; public MachineConfigurationSyncHandler(MachineConfiguration configuration) { this.configuration = configuration; this.ioConfig = configuration.getIOConfiguration().createSyncHandler(); this.security = configuration.getSecurity().createSyncHandler(); - this.redstone = configuration.getRedstoneActivation(); + this.redstone = configuration.getRedstoneMode(); } @Override public boolean needsSyncing() { - return this.ioConfig.needsSyncing() || this.security.needsSyncing() || this.redstone != configuration.getRedstoneActivation(); + return this.ioConfig.needsSyncing() || this.security.needsSyncing() || this.redstone != configuration.getRedstoneMode(); } @Override @@ -53,7 +53,7 @@ public void sync(@NotNull FriendlyByteBuf buf) { byte ref = 0b000; if (this.ioConfig.needsSyncing()) ref |= 0b001; if (this.security.needsSyncing()) ref |= 0b010; - if (this.redstone != this.configuration.getRedstoneActivation()) ref |= 0b100; + if (this.redstone != this.configuration.getRedstoneMode()) ref |= 0b100; buf.writeByte(ref); @@ -64,9 +64,9 @@ public void sync(@NotNull FriendlyByteBuf buf) { this.security.sync(buf); } - if (this.redstone != this.configuration.getRedstoneActivation()) { - this.redstone = this.configuration.getRedstoneActivation(); - buf.writeByte(this.configuration.getRedstoneActivation().ordinal()); + if (this.redstone != this.configuration.getRedstoneMode()) { + this.redstone = this.configuration.getRedstoneMode(); + buf.writeByte(this.configuration.getRedstoneMode().ordinal()); } } @@ -80,8 +80,8 @@ public void read(@NotNull FriendlyByteBuf buf) { this.security.read(buf); } if ((ref & 0b100) != 0) { - this.redstone = RedstoneActivation.VALUES[buf.readByte()]; - this.configuration.setRedstoneActivation(this.redstone); + this.redstone = RedstoneMode.VALUES[buf.readByte()]; + this.configuration.setRedstoneMode(this.redstone); } } } diff --git a/src/main/java/dev/galacticraft/machinelib/impl/network/MachineLibC2SPackets.java b/src/main/java/dev/galacticraft/machinelib/impl/network/MachineLibC2SPackets.java index 882076ae..9a3a3f58 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/network/MachineLibC2SPackets.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/network/MachineLibC2SPackets.java @@ -25,7 +25,7 @@ import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; import dev.galacticraft.machinelib.api.machine.configuration.AccessLevel; import dev.galacticraft.machinelib.api.machine.configuration.MachineIOFace; -import dev.galacticraft.machinelib.api.machine.configuration.RedstoneActivation; +import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.menu.MachineMenu; import dev.galacticraft.machinelib.api.storage.slot.ResourceSlot; import dev.galacticraft.machinelib.api.transfer.InputType; @@ -130,12 +130,12 @@ public static void register() { }); C2SPacketReceiver.register(Constant.id("redstone_config"), (server, player, handler, buf, responseSender) -> { - RedstoneActivation redstoneActivation = RedstoneActivation.values()[buf.readByte()]; + RedstoneMode redstoneMode = RedstoneMode.values()[buf.readByte()]; server.execute(() -> { if (player.containerMenu instanceof MachineMenu menu) { MachineBlockEntity machine = menu.machine; if (machine.getSecurity().hasAccess(player)) { - machine.setRedstone(redstoneActivation); + machine.setRedstone(redstoneMode); machine.setChanged(); } } diff --git a/src/main/resources/assets/machinelib/lang/en_us.json b/src/main/resources/assets/machinelib/lang/en_us.json index ec3a6c05..66125c98 100644 --- a/src/main/resources/assets/machinelib/lang/en_us.json +++ b/src/main/resources/assets/machinelib/lang/en_us.json @@ -1,6 +1,5 @@ { "ui.machinelib.machine.status": "Status: ", - "status.machinelib.invalid": "Error", "status.machinelib.not_enough_energy": "Not Enough Energy", "status.machinelib.invalid_recipe": "Invalid Recipe", "status.machinelib.output_full": "Output Full", @@ -9,6 +8,7 @@ "status.machinelib.idle": "Idle", "status.machinelib.unknown": "Unknown", "status.machinelib.disabled": "Disabled", + "ui.machinelib.machine.current_energy": "Energy: %s/%s", "ui.machinelib.machine.security": "Security", "ui.machinelib.machine.security.access": "Access: %s", @@ -17,17 +17,15 @@ "ui.machinelib.machine.security.access.private": "Private", "ui.machinelib.machine.security.access_denied": "Access Denied", "ui.machinelib.machine.security.owner": "Owner: %s", - "ui.machinelib.machine.redstone_activation": "Redstone Activation", - "ui.machinelib.machine.redstone_activation.ignored": "Ignored", - "ui.machinelib.machine.redstone_activation.low": "Low", - "ui.machinelib.machine.redstone_activation.high": "High", - "ui.machinelib.machine.redstone_activation.state": "State: %s", - "ui.machinelib.machine.redstone_activation.status": "Status: %s", - "ui.machinelib.machine.redstone_activation.status.enabled": "Enabled", - "ui.machinelib.machine.redstone_activation.status.disabled": "Disabled", + "ui.machinelib.machine.redstone_mode": "Redstone Mode", + "ui.machinelib.machine.redstone_mode.ignored": "Ignored", + "ui.machinelib.machine.redstone_mode.low": "Low", + "ui.machinelib.machine.redstone_mode.high": "High", + "ui.machinelib.machine.redstone_mode.state": "State: %s", + "ui.machinelib.machine.redstone_mode.status": "Status: %s", + "ui.machinelib.machine.redstone_mode.status.enabled": "Enabled", + "ui.machinelib.machine.redstone_mode.status.disabled": "Disabled", "ui.machinelib.machine.configuration": "Side Config", - "ui.machinelib.machine.configuration.group": "Group: %s", - "ui.machinelib.machine.configuration.slot": "Slot: %s", "ui.machinelib.machine.statistics": "Statistics", "ui.machinelib.face.front": "Front", "ui.machinelib.face.right": "Right", @@ -45,8 +43,16 @@ "ui.machinelib.resource.type.fluid": "Fluid", "ui.machinelib.machine.tank.contents": "Contents: ", "ui.machinelib.machine.tank.contents.amount": "Amount: ", + "ui.machinelib.machine.tank.contents.capacity": "Capacity: ", "ui.machinelib.machine.tank.contents.empty": "Empty", - "slot_type.machinelib.invalid": "Invalid", + + "ui.machinelib.units.energy.base": "gJ", + "ui.machinelib.units.energy.mega": "MgJ", + "ui.machinelib.units.energy.giga": "GgJ", + + "ui.machinelib.units.fluid.base": "B", + "ui.machinelib.units.fluid.milli": "mB", + "tooltip.machinelib.machine.unknown": "Unknown", "tooltip.machinelib.press_shift": "Press LSHIFT for more information." } \ No newline at end of file