diff --git a/src/main/java/dev/enjarai/minitardis/block/console/ConsoleScreenBlockEntity.java b/src/main/java/dev/enjarai/minitardis/block/console/ConsoleScreenBlockEntity.java index a7a74a9..92838fe 100644 --- a/src/main/java/dev/enjarai/minitardis/block/console/ConsoleScreenBlockEntity.java +++ b/src/main/java/dev/enjarai/minitardis/block/console/ConsoleScreenBlockEntity.java @@ -4,7 +4,6 @@ import dev.enjarai.minitardis.block.ModBlocks; import dev.enjarai.minitardis.block.TardisAware; import dev.enjarai.minitardis.canvas.ModCanvasUtils; -import dev.enjarai.minitardis.component.DestinationScanner; import dev.enjarai.minitardis.component.Tardis; import eu.pb4.mapcanvas.api.core.CanvasColor; import eu.pb4.mapcanvas.api.core.DrawableCanvas; @@ -17,12 +16,13 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; import net.minecraft.util.ClickType; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import org.joml.Vector2i; import java.util.ArrayList; import java.util.List; @@ -149,8 +149,9 @@ private void handleClick(ServerPlayerEntity player, ClickType type, int x, int y Optional.ofNullable(selectedApp).flatMap(controls::getScreenApp).ifPresentOrElse(app -> { if (type == ClickType.RIGHT && x >= 96 + 2 && x < 96 + 2 + 28 && y >= 16 + 2 && y < 16 + 2 + 14) { selectedApp = null; + playClickSound(0.5f); } else { - app.onClick(controls, player, type, x, y - 16); + app.onClick(controls, this, player, type, x, y - 16); } }, () -> { var apps = controls.getAllApps(); @@ -162,6 +163,7 @@ private void handleClick(ServerPlayerEntity player, ClickType type, int x, int y if (x >= appX && x < appX + 24 && y >= appY && y < appY + 24) { var app = apps.get(i); selectedApp = app.id(); + playClickSound(1.5f); } } } @@ -176,4 +178,10 @@ private int getAppX(int i) { private int getAppY(int i) { return 16 + 4; } + + public void playClickSound(float pitch) { + if (getWorld() instanceof ServerWorld serverWorld) { + serverWorld.playSound(null, getPos(), SoundEvents.BLOCK_NOTE_BLOCK_BIT.value(), SoundCategory.BLOCKS, 0.5f, pitch); + } + } } diff --git a/src/main/java/dev/enjarai/minitardis/canvas/ModCanvasUtils.java b/src/main/java/dev/enjarai/minitardis/canvas/ModCanvasUtils.java index cd5d033..207b75c 100644 --- a/src/main/java/dev/enjarai/minitardis/canvas/ModCanvasUtils.java +++ b/src/main/java/dev/enjarai/minitardis/canvas/ModCanvasUtils.java @@ -14,7 +14,8 @@ public class ModCanvasUtils { public static final CanvasImage APP_BACKGROUND = loadImage("app_background.png"); public static final CanvasImage SCREEN_SIDE_BUTTON = loadImage("screen_side_button.png"); public static final CanvasImage SCREEN_SIDE_BUTTON_PRESSED = loadImage("screen_side_button_pressed.png"); - public static final CanvasImage COORD_WIDGET = loadImage("coord_widget.png"); + public static final CanvasImage COORD_WIDGET_X = loadImage("coord_widget_x.png"); + public static final CanvasImage COORD_WIDGET_Z = loadImage("coord_widget_z.png"); public static final CanvasImage FACING_WIDGET = loadImage("facing_widget.png"); private static CanvasImage loadImage(String filename) { diff --git a/src/main/java/dev/enjarai/minitardis/component/DestinationScanner.java b/src/main/java/dev/enjarai/minitardis/component/DestinationScanner.java index 25faf1c..c6a86d2 100644 --- a/src/main/java/dev/enjarai/minitardis/component/DestinationScanner.java +++ b/src/main/java/dev/enjarai/minitardis/component/DestinationScanner.java @@ -63,6 +63,10 @@ public void useZAxis() { isZAxis = true; } + public boolean isZAxis() { + return isZAxis; + } + public void resetIterators() { xIterator = newIterator(); zIterator = newIterator(); diff --git a/src/main/java/dev/enjarai/minitardis/component/TardisControl.java b/src/main/java/dev/enjarai/minitardis/component/TardisControl.java index d3d4410..8c65da1 100644 --- a/src/main/java/dev/enjarai/minitardis/component/TardisControl.java +++ b/src/main/java/dev/enjarai/minitardis/component/TardisControl.java @@ -100,6 +100,6 @@ public Optional getScreenApp(Identifier id) { } public List getAllApps() { - return ImmutableList.copyOf(screenApps.values()); + return screenApps.values().stream().sorted(Comparator.comparing(ScreenApp::id)).toList(); } } diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/ElementHoldingApp.java b/src/main/java/dev/enjarai/minitardis/component/screen/ElementHoldingApp.java index acbd083..1752580 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/ElementHoldingApp.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/ElementHoldingApp.java @@ -1,5 +1,6 @@ package dev.enjarai.minitardis.component.screen; +import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity; import dev.enjarai.minitardis.component.TardisControl; import dev.enjarai.minitardis.component.screen.element.AppElement; import eu.pb4.mapcanvas.api.core.DrawableCanvas; @@ -23,9 +24,9 @@ public void draw(TardisControl controls, DrawableCanvas canvas) { } @Override - public boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) { + public boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) { for (var element : children) { - if (element.onClick(controls, player, type, x, y)) { + if (element.onClick(controls, blockEntity, player, type, x, y)) { return true; } } diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/GpsApp.java b/src/main/java/dev/enjarai/minitardis/component/screen/GpsApp.java index 8a78da6..b2f9509 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/GpsApp.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/GpsApp.java @@ -2,6 +2,7 @@ import com.mojang.serialization.Codec; import dev.enjarai.minitardis.MiniTardis; +import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity; import dev.enjarai.minitardis.component.TardisControl; import eu.pb4.mapcanvas.api.core.CanvasColor; import eu.pb4.mapcanvas.api.core.DrawableCanvas; @@ -24,7 +25,7 @@ public void draw(TardisControl controls, DrawableCanvas canvas) { } @Override - public boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) { + public boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) { return false; } diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/ScannerApp.java b/src/main/java/dev/enjarai/minitardis/component/screen/ScannerApp.java index aa30a0b..1494ab2 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/ScannerApp.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/ScannerApp.java @@ -9,6 +9,7 @@ import eu.pb4.mapcanvas.api.core.CanvasColor; import eu.pb4.mapcanvas.api.core.DrawableCanvas; import eu.pb4.mapcanvas.api.utils.CanvasUtils; +import eu.pb4.mapcanvas.impl.view.Rotate90ClockwiseView; import eu.pb4.mapcanvas.impl.view.RotatedView; import net.minecraft.util.Identifier; @@ -41,9 +42,14 @@ public void draw(TardisControl controls, DrawableCanvas canvas) { canvas.set(DestinationScanner.RANGE / 2 - 1, DestinationScanner.RANGE / 2, CanvasColor.ORANGE_HIGH); canvas.set(DestinationScanner.RANGE / 2 - 1, DestinationScanner.RANGE / 2 - 1, CanvasColor.ORANGE_HIGH); - CanvasUtils.draw(canvas, 96, 64, ModCanvasUtils.COORD_WIDGET); - controls.getTardis().getDestination().ifPresent(destination -> - CanvasUtils.draw(canvas, 96, 64, new RotatedView(ModCanvasUtils.FACING_WIDGET, Math.toRadians(destination.facing().asRotation()), 16, 16))); + CanvasUtils.draw(canvas, 96, 64, controls.getTardis().getDestinationScanner().isZAxis() ? ModCanvasUtils.COORD_WIDGET_Z : ModCanvasUtils.COORD_WIDGET_X); + controls.getTardis().getDestination().ifPresent(destination -> { + DrawableCanvas view = ModCanvasUtils.FACING_WIDGET; + for (int i = 0; i < destination.facing().getHorizontal(); i++) { + view = new Rotate90ClockwiseView(view); + } + CanvasUtils.draw(canvas, 96, 64, view); + }); super.draw(controls, canvas); } diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/ScreenApp.java b/src/main/java/dev/enjarai/minitardis/component/screen/ScreenApp.java index dd53dcb..3a72c7f 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/ScreenApp.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/ScreenApp.java @@ -1,6 +1,7 @@ package dev.enjarai.minitardis.component.screen; import com.mojang.serialization.Codec; +import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity; import dev.enjarai.minitardis.component.TardisControl; import eu.pb4.mapcanvas.api.core.DrawableCanvas; import net.minecraft.server.network.ServerPlayerEntity; @@ -23,7 +24,7 @@ public interface ScreenApp { void draw(TardisControl controls, DrawableCanvas canvas); - boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y); + boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y); void drawIcon(TardisControl controls, DrawableCanvas canvas); diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/element/AppElement.java b/src/main/java/dev/enjarai/minitardis/component/screen/element/AppElement.java index 51e8739..55b81d1 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/element/AppElement.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/element/AppElement.java @@ -1,5 +1,6 @@ package dev.enjarai.minitardis.component.screen.element; +import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity; import dev.enjarai.minitardis.component.TardisControl; import eu.pb4.mapcanvas.api.core.DrawableCanvas; import net.minecraft.server.network.ServerPlayerEntity; @@ -8,5 +9,5 @@ public interface AppElement { void draw(TardisControl controls, DrawableCanvas canvas); - boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y); + boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y); } diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/element/PlacedElement.java b/src/main/java/dev/enjarai/minitardis/component/screen/element/PlacedElement.java index b170e4c..c2127f7 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/element/PlacedElement.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/element/PlacedElement.java @@ -1,5 +1,6 @@ package dev.enjarai.minitardis.component.screen.element; +import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity; import dev.enjarai.minitardis.component.TardisControl; import eu.pb4.mapcanvas.api.core.DrawableCanvas; import eu.pb4.mapcanvas.impl.view.SubView; @@ -27,12 +28,12 @@ public void draw(TardisControl controls, DrawableCanvas canvas) { protected abstract void drawElement(TardisControl controls, DrawableCanvas canvas); @Override - public boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) { + public boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) { if (x >= this.x && x < this.x + width && y >= this.y && y < this.y + height) { - return onClickElement(controls, player, type, x - this.x, y - this.y); + return onClickElement(controls, blockEntity, player, type, x - this.x, y - this.y); } return false; } - protected abstract boolean onClickElement(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y); + protected abstract boolean onClickElement(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y); } diff --git a/src/main/java/dev/enjarai/minitardis/component/screen/element/SideButtonElement.java b/src/main/java/dev/enjarai/minitardis/component/screen/element/SideButtonElement.java index b563411..e970d93 100644 --- a/src/main/java/dev/enjarai/minitardis/component/screen/element/SideButtonElement.java +++ b/src/main/java/dev/enjarai/minitardis/component/screen/element/SideButtonElement.java @@ -1,5 +1,6 @@ package dev.enjarai.minitardis.component.screen.element; +import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity; import dev.enjarai.minitardis.canvas.ModCanvasUtils; import dev.enjarai.minitardis.component.TardisControl; import eu.pb4.mapcanvas.api.core.CanvasColor; @@ -31,10 +32,11 @@ protected void drawElement(TardisControl controls, DrawableCanvas canvas) { } @Override - protected boolean onClickElement(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) { + protected boolean onClickElement(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) { if (type == ClickType.RIGHT) { pressedFrames = 2; clickCallback.accept(controls); + blockEntity.playClickSound(1); return true; } return false; diff --git a/src/main/resources/assets/mini_tardis/textures/map/coord_widget.png b/src/main/resources/assets/mini_tardis/textures/map/coord_widget.png deleted file mode 100644 index 93eaad7..0000000 Binary files a/src/main/resources/assets/mini_tardis/textures/map/coord_widget.png and /dev/null differ diff --git a/src/main/resources/assets/mini_tardis/textures/map/facing_widget.png b/src/main/resources/assets/mini_tardis/textures/map/facing_widget.png index 1f25dc8..95bab51 100644 Binary files a/src/main/resources/assets/mini_tardis/textures/map/facing_widget.png and b/src/main/resources/assets/mini_tardis/textures/map/facing_widget.png differ