From d7e8b8a57a88f3914354f986d49bdea0cf39c9ef Mon Sep 17 00:00:00 2001 From: J-RAP Date: Wed, 11 Jun 2025 22:21:54 -0600 Subject: [PATCH 1/3] Update Forge buildscript to Gradle 8.1 and FG 6 --- build.gradle | 63 +++++++++--------------- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 12 +++++ 3 files changed, 37 insertions(+), 40 deletions(-) create mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle index cf7cd4a..3be8d7e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,60 +1,45 @@ -buildscript { - repositories { - // These repositories are only for Gradle plugins, put any other repositories in the repository block further below - maven { url = 'https://maven.minecraftforge.net' } - maven { url = 'https://maven.parchmentmc.org' } - maven { url = 'https://repo.spongepowered.org/maven' } - maven { url 'https://jitpack.io' } - mavenCentral() - jcenter() - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - classpath 'org.parchmentmc:librarian:1.+' - } -} -// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. plugins { - id 'eclipse' - id 'maven-publish' + id 'java' + id 'idea' + id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'org.spongepowered.mixin' version '0.7.+' + id 'org.parchmentmc.librarian.forgegradle' version '1.+' + id "me.modmuss50.mod-publish-plugin" version "0.8.3" } -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'org.parchmentmc.librarian.forgegradle' -version = '3.1.3-FORGE-1.18.X' +// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. +def MT_TOKEN = System.getenv("MODRINTH_TOKEN") +def CF_TOKEN = System.getenv("CURSEFORGE_TOKEN") + group = 'com.github.NGoedix.VideoPlayer' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'VideoPlayer' +base { + archivesName = "VideoPlayer" + version = '3.1.3-FORGE-1.18.X' +} // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { - mappings channel: 'parchment', version: '1.18.1-2022.03.06-1.18.2' + mappings channel: 'parchment', version: '2022.11.06-1.18.2' runs { - client { + configureEach { workingDirectory project.file('run') - property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' - property 'forge.enabledGameTestNamespaces', 'videoplayer' - mods { - videoplayer { - source sourceSets.main - } - } - } + property 'log4j.appender.Console', "org.apache.log4j.ConsoleAppender" + property 'terminal.jline', 'true' + arg '--nogui' - server { - workingDirectory project.file('run') - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - property 'forge.enabledGameTestNamespaces', 'videoplayer' mods { - videoplayer { + "videoplayer" { source sourceSets.main } } } + + client {} + server {} } } @@ -72,7 +57,7 @@ repositories { } dependencies { - minecraft 'net.minecraftforge:forge:1.18.2-40.2.10' + minecraft 'net.minecraftforge:forge:1.18.2-40.3.10' implementation 'com.github.WaterMediaTeam:watermedia:2.1.22' implementation fg.deobf("curse.maven:jei-238222:4434393") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..e48eca5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..3af0b05 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,12 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { url 'https://maven.minecraftforge.net/' } + maven { url 'https://repo.spongepowered.org/maven' } + maven { url 'https://maven.parchmentmc.org' } + } +} + +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' +} \ No newline at end of file From 9b9bedb4469111b0f5c4f079c00cf1e0baeb5f9c Mon Sep 17 00:00:00 2001 From: J-RAP Date: Wed, 11 Jun 2025 22:49:20 -0600 Subject: [PATCH 2/3] Modernize VP code, using regular Screen and modern Minecraft implementations --- .../watchvideo/client/gui/DummyContainer.java | 16 -- .../watchvideo/client/gui/RadioScreen.java | 149 ++++++------ .../watchvideo/client/gui/TVVideoScreen.java | 170 +++++++------- .../watchvideo/client/gui/VideoScreen.java | 213 +++++++++--------- .../watchvideo/network/PacketHandler.java | 2 +- src/main/resources/META-INF/mods.toml | 20 +- 6 files changed, 271 insertions(+), 299 deletions(-) delete mode 100644 src/main/java/com/github/NGoedix/watchvideo/client/gui/DummyContainer.java diff --git a/src/main/java/com/github/NGoedix/watchvideo/client/gui/DummyContainer.java b/src/main/java/com/github/NGoedix/watchvideo/client/gui/DummyContainer.java deleted file mode 100644 index c5e3b22..0000000 --- a/src/main/java/com/github/NGoedix/watchvideo/client/gui/DummyContainer.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.NGoedix.watchvideo.client.gui; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; - -public class DummyContainer extends AbstractContainerMenu { - - protected DummyContainer() { - super(null, 0); - } - - @Override - public boolean stillValid(Player playerIn) { - return true; - } -} diff --git a/src/main/java/com/github/NGoedix/watchvideo/client/gui/RadioScreen.java b/src/main/java/com/github/NGoedix/watchvideo/client/gui/RadioScreen.java index 4324e89..b7acbc5 100644 --- a/src/main/java/com/github/NGoedix/watchvideo/client/gui/RadioScreen.java +++ b/src/main/java/com/github/NGoedix/watchvideo/client/gui/RadioScreen.java @@ -27,16 +27,9 @@ import java.util.List; import java.util.Map; -public class RadioScreen extends Screen { - - // Textures - private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/background.png"); +import static com.github.NGoedix.watchvideo.client.gui.VideoScreen.*; - private static final ResourceLocation PLAY_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/play_button.png"); - private static final ResourceLocation PLAY_HOVER_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/play_button_hover.png"); - - private static final ResourceLocation PAUSE_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/pause_button.png"); - private static final ResourceLocation PAUSE_HOVER_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/pause_button_hover.png"); +public class RadioScreen extends Screen { private ScrollingStringList countryList, stationList; private EditBox urlField; @@ -46,7 +39,7 @@ public class RadioScreen extends Screen { // Control private final RadioBlockEntity be; - private String url; + private final String url; private int volume; private boolean ready = false; @@ -56,7 +49,7 @@ public class RadioScreen extends Screen { private int leftPos; private int topPos; - public RadioScreen(BlockEntity be) { + public RadioScreen(final BlockEntity be) { super(new TranslatableComponent("gui.radio_screen.title")); this.be = (RadioBlockEntity) be; this.url = this.be.getUrl(); @@ -67,93 +60,93 @@ public RadioScreen(BlockEntity be) { protected void init() { super.init(); - leftPos = (width - imageWidth) / 2; - topPos = (height - imageHeight) / 2; + this.leftPos = (this.width - this.imageWidth) / 2; + this.topPos = (this.height - this.imageHeight) / 2; Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(true); - List sortedCountries = new ArrayList<>(RadioStreams.getRadioStreams().keySet()); + final List sortedCountries = new ArrayList<>(RadioStreams.getRadioStreams().keySet()); Collections.sort(sortedCountries); // Country list - addRenderableWidget(countryList = new ScrollingStringList((width / 2) - 177, height / 2 - 3, 100, 248, sortedCountries)); - countryList.setSelected("Custom"); - countryList.setPlayerSlotClickListener(text -> { - if (urlField != null) - urlField.setEditable(text.equals("Custom")); - if (stationList != null) - stationList.updateEntries(getStationNamesForCountry(text, RadioStreams.getRadioStreams())); + this.addRenderableWidget(this.countryList = new ScrollingStringList((this.width / 2) - 177, this.height / 2 - 3, 100, 248, sortedCountries)); + this.countryList.setSelected("Custom"); + this.countryList.setPlayerSlotClickListener(text -> { + if (this.urlField != null) + this.urlField.setEditable(text.equals("Custom")); + if (this.stationList != null) + this.stationList.updateEntries(this.getStationNamesForCountry(text, RadioStreams.getRadioStreams())); }); - countryList.setSelected(getCountryFromStationUrl(url)); + this.countryList.setSelected(this.getCountryFromStationUrl(this.url)); // Custom URL callback - addRenderableWidget(urlField = new EditBox(font, leftPos + 12, height / 2 - 30, imageWidth - 28, 20, new TextComponent(""))); - urlField.setResponder(text -> { - if (!ready) return; + this.addRenderableWidget(this.urlField = new EditBox(this.font, this.leftPos + 12, this.height / 2 - 30, this.imageWidth - 28, 20, new TextComponent(""))); + this.urlField.setResponder(text -> { + if (!this.ready) return; - if (countryList.getSelectedText().equals("Custom")) { + if (this.countryList.getSelectedText().equals("Custom")) { if (text.matches(TVConfig.URL_PATTERN)) - PacketHandler.sendToServer(new UrlPacket(be.getBlockPos(), text)); + PacketHandler.sendToServer(new UrlPacket(this.be.getBlockPos(), text)); } }); - urlField.setEditable(countryList.getSelectedText().equals("Custom")); - urlField.setMaxLength(32767); - urlField.setValue(url); + this.urlField.setEditable(this.countryList.getSelectedText().equals("Custom")); + this.urlField.setMaxLength(32767); + this.urlField.setValue(this.url); // Station of country - addRenderableWidget(stationList = new ScrollingStringList((width / 2) + 172, height / 2 - 3, 100, 248, getStationNamesForCountry(countryList.getSelectedText(), RadioStreams.getRadioStreams()))); - stationList.setPlayerSlotClickListener(text -> { - if (!ready) return; + this.addRenderableWidget(this.stationList = new ScrollingStringList((this.width / 2) + 172, this.height / 2 - 3, 100, 248, this.getStationNamesForCountry(this.countryList.getSelectedText(), RadioStreams.getRadioStreams()))); + this.stationList.setPlayerSlotClickListener(text -> { + if (!this.ready) return; if (text != null && !text.isEmpty()) { - urlField.setValue(getStationUrlFromStation(text)); - PacketHandler.sendToServer(new UrlPacket(be.getBlockPos(), getStationUrlFromStation(text))); + this.urlField.setValue(this.getStationUrlFromStation(text)); + PacketHandler.sendToServer(new UrlPacket(this.be.getBlockPos(), this.getStationUrlFromStation(text))); } }); - stationList.setSelected(getStationFromStationUrl(url)); - stationList.updateEntries(getStationNamesForCountry(countryList.getSelectedText(), RadioStreams.getRadioStreams())); + this.stationList.setSelected(this.getStationFromStationUrl(this.url)); + this.stationList.updateEntries(this.getStationNamesForCountry(this.countryList.getSelectedText(), RadioStreams.getRadioStreams())); // Volume slider - addRenderableWidget(volumeSlider = new CustomSlider(leftPos + 10, height / 2 - 5, imageWidth - 24, 20, new TranslatableComponent("gui.tv_video_screen.volume"), volume / 100f, false)); - volumeSlider.setOnSlideListener(value -> { - if (!ready) return; + this.addRenderableWidget(this.volumeSlider = new CustomSlider(this.leftPos + 10, this.height / 2 - 5, this.imageWidth - 24, 20, new TranslatableComponent("gui.tv_video_screen.volume"), this.volume / 100f, false)); + this.volumeSlider.setOnSlideListener(value -> { + if (!this.ready) return; - volume = (int) volumeSlider.getValue(); - PacketHandler.sendToServer(new VolumePacket(be.getBlockPos(), volume)); + this.volume = (int) this.volumeSlider.getValue(); + PacketHandler.sendToServer(new VolumePacket(this.be.getBlockPos(), this.volume)); }); - volumeSlider.setValue(volume / 100f); + this.volumeSlider.setValue(this.volume / 100f); // Buttons - addRenderableWidget(playButton = new ImageButtonHoverable(width / 2 - 10, topPos + 150, 20, 20, 0, 0, 0, PLAY_BUTTON_TEXTURE, PLAY_HOVER_BUTTON_TEXTURE, 20, 20, button -> { - if (!ready) return; + this.addRenderableWidget(this.playButton = new ImageButtonHoverable(this.width / 2 - 10, this.topPos + 150, 20, 20, 0, 0, 0, PLAY_BUTTON_TEXTURE, PLAY_HOVER_BUTTON_TEXTURE, 20, 20, button -> { + if (!this.ready) return; - if (!urlField.getValue().isEmpty()) { - playButton.visible = false; - pauseButton.visible = true; + if (!this.urlField.getValue().isEmpty()) { + this.playButton.visible = false; + this.pauseButton.visible = true; - if (be.requestDisplay() == null) return; - PacketHandler.sendToServer(new PausePacket(be.getBlockPos(), false)); + if (this.be.requestDisplay() == null) return; + PacketHandler.sendToServer(new PausePacket(this.be.getBlockPos(), false)); } })); - playButton.visible = be != null ? !be.isPlaying() : url.isEmpty(); + this.playButton.visible = this.be != null ? !this.be.isPlaying() : this.url.isEmpty(); - addRenderableWidget(pauseButton = new ImageButtonHoverable(width / 2 - 10, topPos + 150, 20, 20, 0, 0, 0, PAUSE_BUTTON_TEXTURE, PAUSE_HOVER_BUTTON_TEXTURE, 20, 20, button -> { - if (!ready) return; + this.addRenderableWidget(this.pauseButton = new ImageButtonHoverable(this.width / 2 - 10, this.topPos + 150, 20, 20, 0, 0, 0, PAUSE_BUTTON_TEXTURE, PAUSE_HOVER_BUTTON_TEXTURE, 20, 20, button -> { + if (!this.ready) return; - if (!urlField.getValue().isEmpty()) { - playButton.visible = true; - pauseButton.visible = false; + if (!this.urlField.getValue().isEmpty()) { + this.playButton.visible = true; + this.pauseButton.visible = false; - if (be.requestDisplay() == null) return; - PacketHandler.sendToServer(new PausePacket(be.getBlockPos(), true)); + if (this.be.requestDisplay() == null) return; + PacketHandler.sendToServer(new PausePacket(this.be.getBlockPos(), true)); } })); - pauseButton.visible = be != null ? be.isPlaying() : !url.isEmpty(); + this.pauseButton.visible = this.be != null ? this.be.isPlaying() : !this.url.isEmpty(); } - private String getCountryFromStationUrl(String url) { - for (Map.Entry> entry : RadioStreams.getRadioStreams().entrySet()) { - for (RadioStreams.RadioStream station : entry.getValue()) { + private String getCountryFromStationUrl(final String url) { + for (final Map.Entry> entry : RadioStreams.getRadioStreams().entrySet()) { + for (final RadioStreams.RadioStream station : entry.getValue()) { if (station.getStreamLink().equals(url)) { return entry.getKey(); } @@ -162,9 +155,9 @@ private String getCountryFromStationUrl(String url) { return "Custom"; } - private String getStationFromStationUrl(String url) { - for (Map.Entry> entry : RadioStreams.getRadioStreams().entrySet()) { - for (RadioStreams.RadioStream station : entry.getValue()) { + private String getStationFromStationUrl(final String url) { + for (final Map.Entry> entry : RadioStreams.getRadioStreams().entrySet()) { + for (final RadioStreams.RadioStream station : entry.getValue()) { if (station.getStreamLink().equals(url)) { return station.getRadioName(); } @@ -173,8 +166,8 @@ private String getStationFromStationUrl(String url) { return null; } - private List getStationNamesForCountry(String country, Map> radioStreamsByCountry) { - List stationNames = new ArrayList<>(9); + private List getStationNamesForCountry(final String country, final Map> radioStreamsByCountry) { + final List stationNames = new ArrayList<>(9); if (country == null) { for (int i = 0; i < 8; i++) @@ -182,9 +175,9 @@ private List getStationNamesForCountry(String country, Map stations = radioStreamsByCountry.get(country); + final List stations = radioStreamsByCountry.get(country); if (stations != null) { - for (RadioStreams.RadioStream station : stations) { + for (final RadioStreams.RadioStream station : stations) { stationNames.add(station.getRadioName()); } } @@ -195,9 +188,9 @@ private List getStationNamesForCountry(String country, Map> entry : RadioStreams.getRadioStreams().entrySet()) { - for (RadioStreams.RadioStream station : entry.getValue()) { + private String getStationUrlFromStation(final String stationUrl) { + for (final Map.Entry> entry : RadioStreams.getRadioStreams().entrySet()) { + for (final RadioStreams.RadioStream station : entry.getValue()) { if (station.getRadioName().equals(stationUrl)) { return station.getStreamLink(); } @@ -207,22 +200,22 @@ private String getStationUrlFromStation(String stationUrl) { } @Override - public void render(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { - if (!ready) ready = true; - renderBackground(pPoseStack); + public void render(final PoseStack pPoseStack, final int pMouseX, final int pMouseY, final float pPartialTick) { + if (!this.ready) this.ready = true; + this.renderBackground(pPoseStack); RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem._setShaderTexture(0, TEXTURE); - blit(pPoseStack, leftPos, topPos, 320, 320, 0, 0, imageWidth, imageHeight, imageWidth, imageHeight); + blit(pPoseStack, this.leftPos, this.topPos, 320, 320, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight); - font.draw(pPoseStack, "Radio Player (by Goedix)", (width / 2f) - 62, height / 2f - 100, 0xFFFFFF); + this.font.draw(pPoseStack, "Radio Player (by Goedix)", (this.width / 2f) - 62, this.height / 2f - 100, 0xFFFFFF); super.render(pPoseStack, pMouseX, pMouseY, pPartialTick); } @Override public void removed() { - PacketHandler.sendToServer(new ClosedScreenPacket(be != null ? be.getBlockPos() : null)); + PacketHandler.sendToServer(new ClosedScreenPacket(this.be != null ? this.be.getBlockPos() : null)); Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(false); } diff --git a/src/main/java/com/github/NGoedix/watchvideo/client/gui/TVVideoScreen.java b/src/main/java/com/github/NGoedix/watchvideo/client/gui/TVVideoScreen.java index 4f5d9e1..bbe5a3d 100644 --- a/src/main/java/com/github/NGoedix/watchvideo/client/gui/TVVideoScreen.java +++ b/src/main/java/com/github/NGoedix/watchvideo/client/gui/TVVideoScreen.java @@ -1,6 +1,5 @@ package com.github.NGoedix.watchvideo.client.gui; -import com.github.NGoedix.watchvideo.Reference; import com.github.NGoedix.watchvideo.block.entity.custom.TVBlockEntity; import com.github.NGoedix.watchvideo.client.gui.components.CustomSlider; import com.github.NGoedix.watchvideo.client.gui.components.ImageButtonHoverable; @@ -16,12 +15,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; import org.lwjgl.opengl.GL11; @@ -30,18 +27,9 @@ import java.awt.*; -public class TVVideoScreen extends Screen { - - private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/background.png"); - - private static final ResourceLocation PLAY_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/play_button.png"); - private static final ResourceLocation PLAY_HOVER_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/play_button_hover.png"); +import static com.github.NGoedix.watchvideo.client.gui.VideoScreen.*; - private static final ResourceLocation PAUSE_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/pause_button.png"); - private static final ResourceLocation PAUSE_HOVER_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/pause_button_hover.png"); - - private static final ResourceLocation STOP_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/stop_button.png"); - private static final ResourceLocation STOP_HOVER_BUTTON_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/gui/stop_button_hover.png"); +public class TVVideoScreen extends Screen { private ImageButtonHoverable playButton; private ImageButtonHoverable pauseButton; @@ -67,7 +55,7 @@ public class TVVideoScreen extends Screen { private EditBox urlBox; private CustomSlider volumeSlider; - public TVVideoScreen(BlockEntity be) { + public TVVideoScreen(final BlockEntity be) { super(new TranslatableComponent("gui.tv_video_screen.title")); this.be = (TVBlockEntity) be; this.url = this.be.getUrl(); @@ -78,106 +66,106 @@ public TVVideoScreen(BlockEntity be) { protected void init() { super.init(); - leftPos = (width - imageWidth) / 2; - topPos = (height - imageHeight) / 2; + this.leftPos = (this.width - this.imageWidth) / 2; + this.topPos = (this.height - this.imageHeight) / 2; Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(true); - addRenderableWidget(urlBox = new EditBox(font, leftPos + 10, topPos + 165, imageWidth - 26, 20, new TextComponent(""))); + this.addRenderableWidget(this.urlBox = new EditBox(this.font, this.leftPos + 10, this.topPos + 165, this.imageWidth - 26, 20, new TextComponent(""))); // Set the text to the url - urlBox.setMaxLength(32767); - urlBox.setValue(url == null ? "" : url); - urlBox.setSuggestion(url == null || url.isEmpty() ? "https://youtube.com/watch?v=FUIcBBM5-xQ" : ""); - urlBox.setResponder(s -> { + this.urlBox.setMaxLength(32767); + this.urlBox.setValue(this.url == null ? "" : this.url); + this.urlBox.setSuggestion(this.url == null || this.url.isEmpty() ? "https://youtube.com/watch?v=FUIcBBM5-xQ" : ""); + this.urlBox.setResponder(s -> { if (s != null && !s.isEmpty()) { - urlBox.setSuggestion(""); - if (s.matches(TVConfig.URL_PATTERN) && (be.getTick() > 5 || url.isEmpty())) { - if (!url.equals(s)) { - url = s; - PacketHandler.sendToServer(new UrlPacket(be.getBlockPos(), url)); - - maxDuration = 0; - timeSlider.setValue(0); + this.urlBox.setSuggestion(""); + if (s.matches(TVConfig.URL_PATTERN) && (this.be.getTick() > 5 || this.url.isEmpty())) { + if (!this.url.equals(s)) { + this.url = s; + PacketHandler.sendToServer(new UrlPacket(this.be.getBlockPos(), this.url)); + + this.maxDuration = 0; + this.timeSlider.setValue(0); } } } else { - urlBox.setSuggestion("https://youtube.com/watch?v=FUIcBBM5-xQ"); + this.urlBox.setSuggestion("https://youtube.com/watch?v=FUIcBBM5-xQ"); } }); // Play button - addRenderableWidget(playButton = new ImageButtonHoverable(leftPos + 10, topPos + 190, 20, 20, 0, 0, 0, PLAY_BUTTON_TEXTURE, PLAY_HOVER_BUTTON_TEXTURE, 20, 20, button -> { - if (be.requestDisplay() != null && !url.isEmpty()) { - playButton.visible = false; - pauseButton.visible = true; + this.addRenderableWidget(this.playButton = new ImageButtonHoverable(this.leftPos + 10, this.topPos + 190, 20, 20, 0, 0, 0, PLAY_BUTTON_TEXTURE, PLAY_HOVER_BUTTON_TEXTURE, 20, 20, button -> { + if (this.be.requestDisplay() != null && !this.url.isEmpty()) { + this.playButton.visible = false; + this.pauseButton.visible = true; - PacketHandler.sendToServer(new PausePacket(be.getBlockPos(), false)); + PacketHandler.sendToServer(new PausePacket(this.be.getBlockPos(), false)); } })); // Pause button - addRenderableWidget(pauseButton = new ImageButtonHoverable(leftPos + 10, topPos + 190, 20, 20, 0, 0, 0, PAUSE_BUTTON_TEXTURE, PAUSE_HOVER_BUTTON_TEXTURE, 20, 20, button -> { - if (be.requestDisplay() != null && !url.isEmpty()) { - playButton.visible = true; - pauseButton.visible = false; + this.addRenderableWidget(this.pauseButton = new ImageButtonHoverable(this.leftPos + 10, this.topPos + 190, 20, 20, 0, 0, 0, PAUSE_BUTTON_TEXTURE, PAUSE_HOVER_BUTTON_TEXTURE, 20, 20, button -> { + if (this.be.requestDisplay() != null && !this.url.isEmpty()) { + this.playButton.visible = true; + this.pauseButton.visible = false; - PacketHandler.sendToServer(new PausePacket(be.getBlockPos(), true)); + PacketHandler.sendToServer(new PausePacket(this.be.getBlockPos(), true)); } })); - playButton.visible = !be.isPlaying(); - pauseButton.visible = be.isPlaying(); + this.playButton.visible = !this.be.isPlaying(); + this.pauseButton.visible = this.be.isPlaying(); // Stop button - addRenderableWidget(stopButton = new ImageButtonHoverable(leftPos + 32, topPos + 190, 20, 20, 0, 0, 0, STOP_BUTTON_TEXTURE, STOP_HOVER_BUTTON_TEXTURE, 20, 20, button -> { - if (be.requestDisplay() != null && !url.isEmpty()) { - playButton.visible = true; - pauseButton.visible = false; + this.addRenderableWidget(this.stopButton = new ImageButtonHoverable(this.leftPos + 32, this.topPos + 190, 20, 20, 0, 0, 0, STOP_BUTTON_TEXTURE, STOP_HOVER_BUTTON_TEXTURE, 20, 20, button -> { + if (this.be.requestDisplay() != null && !this.url.isEmpty()) { + this.playButton.visible = true; + this.pauseButton.visible = false; - timeSlider.setValue(0); + this.timeSlider.setValue(0); - PacketHandler.sendToServer(new StopPacket(be.getBlockPos())); + PacketHandler.sendToServer(new StopPacket(this.be.getBlockPos())); } })); // Time slider - addRenderableWidget(timeSlider = new CustomSlider(leftPos + 54, topPos + 200, 187, 10, null, 0 / 100f, true)); - timeSlider.setOnSlideListener(value -> { - if (be.requestDisplay() == null) return; + this.addRenderableWidget(this.timeSlider = new CustomSlider(this.leftPos + 54, this.topPos + 200, 187, 10, null, 0 / 100f, true)); + this.timeSlider.setOnSlideListener(value -> { + if (this.be.requestDisplay() == null) return; - long time = (long) ((value / 100D) * be.requestDisplay().getDuration()); - if (maxDuration != 0) - PacketHandler.sendToServer(new TickPacket(be.getBlockPos(), MathAPI.msToTick(time))); + final long time = (long) ((value / 100D) * this.be.requestDisplay().getDuration()); + if (this.maxDuration != 0) + PacketHandler.sendToServer(new TickPacket(this.be.getBlockPos(), MathAPI.msToTick(time))); }); - if (be.requestDisplay() != null) timeSlider.setValue((double) be.requestDisplay().getTime() / be.requestDisplay().getDuration()); + if (this.be.requestDisplay() != null) this.timeSlider.setValue((double) this.be.requestDisplay().getTime() / this.be.requestDisplay().getDuration()); // Volume slider - addRenderableWidget(volumeSlider = new CustomSlider(leftPos + 10, topPos + 215, imageWidth - 24, 20, new TranslatableComponent("gui.tv_video_screen.volume"), volume / 100f, false)); - volumeSlider.setOnSlideListener(value -> { - be.setVolume((int) value); - volume = (int) volumeSlider.getValue(); + this.addRenderableWidget(this.volumeSlider = new CustomSlider(this.leftPos + 10, this.topPos + 215, this.imageWidth - 24, 20, new TranslatableComponent("gui.tv_video_screen.volume"), this.volume / 100f, false)); + this.volumeSlider.setOnSlideListener(value -> { + this.be.setVolume((int) value); + this.volume = (int) this.volumeSlider.getValue(); - PacketHandler.sendToServer(new VolumePacket(be.getBlockPos(), volume)); + PacketHandler.sendToServer(new VolumePacket(this.be.getBlockPos(), this.volume)); }); - volumeSlider.setValue(volume / 100f); + this.volumeSlider.setValue(this.volume / 100f); - be.setVolume(volume); + this.be.setVolume(this.volume); } @Override - public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { - Display display = be.requestDisplay(); + public void render(@NotNull final PoseStack pPoseStack, final int pMouseX, final int pMouseY, final float pPartialTick) { + final Display display = this.be.requestDisplay(); - renderBackground(pPoseStack); + this.renderBackground(pPoseStack); RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, TEXTURE); - blit(pPoseStack, leftPos, topPos, 320, 320, 0, 0, imageWidth, imageHeight, imageWidth, imageHeight); + blit(pPoseStack, this.leftPos, this.topPos, 320, 320, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight); // Draw black square GlStateManager._bindTexture(ImageAPI.blackPicture().texture(0)); RenderSystem.setShaderTexture(0, ImageAPI.blackPicture().texture(0)); - blit(pPoseStack, leftPos + (imageWidth / 2) - (videoWidth / 2), topPos + 10, videoWidth, videoHeight, 0, 0, videoWidth, videoHeight, videoWidth, videoHeight); + blit(pPoseStack, this.leftPos + (this.imageWidth / 2) - (this.videoWidth / 2), this.topPos + 10, this.videoWidth, this.videoHeight, 0, 0, this.videoWidth, this.videoHeight, this.videoWidth, this.videoHeight); super.render(pPoseStack, pMouseX, pMouseY, pPartialTick); @@ -186,28 +174,28 @@ public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, floa // Time slider if not live if (display != null && display.isReady()) { - timeSlider.setActive(!display.isLive()); + this.timeSlider.setActive(!display.isLive()); - if (maxDuration <= 0 && !display.isLive()) - maxDuration = display.getDuration(); + if (this.maxDuration <= 0 && !display.isLive()) + this.maxDuration = display.getDuration(); // If not live, calculate the time if (!display.isLive()) { - long durationSeconds = maxDuration / 1000; - long maxMinute = durationSeconds / 60; - long maxSeconds = durationSeconds % 60; - long actualTime = MathAPI.tickToMs(be.getTick()) / 1000; + final long durationSeconds = this.maxDuration / 1000; + final long maxMinute = durationSeconds / 60; + final long maxSeconds = durationSeconds % 60; + long actualTime = MathAPI.tickToMs(this.be.getTick()) / 1000; // Check if actualTime exceeds maxDuration and reset to 0 if it does - if (maxDuration > 0 && actualTime > durationSeconds) { + if (this.maxDuration > 0 && actualTime > durationSeconds) { actualTime = actualTime % durationSeconds; } - long actualMinute = actualTime / 60; + final long actualMinute = actualTime / 60; long actualSeconds = actualTime % 60; if (durationSeconds != 0) - timeSlider.setValue((double) actualTime / durationSeconds); + this.timeSlider.setValue((double) actualTime / durationSeconds); maxTimeFormatted = String.format("%02d:%02d", maxMinute, maxSeconds); if (actualSeconds == -1) actualSeconds = 0; @@ -215,21 +203,21 @@ public void render(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY, floa } } - font.draw(pPoseStack, new TranslatableComponent("gui.tv_video_screen.time", actualTimeFormatted, maxTimeFormatted), leftPos + 54, topPos + 190, 0xFFFFFF); + this.font.draw(pPoseStack, new TranslatableComponent("gui.tv_video_screen.time", actualTimeFormatted, maxTimeFormatted), this.leftPos + 54, this.topPos + 190, 0xFFFFFF); - renderVideo(pPoseStack); + this.renderVideo(pPoseStack); } - public void renderVideo(PoseStack pPoseStack) { - if (url.isEmpty()) return; + public void renderVideo(final PoseStack pPoseStack) { + if (this.url.isEmpty()) return; - Display display = be.requestDisplay(); + final Display display = this.be.requestDisplay(); if (display == null) { RenderSystem.enableBlend(); RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - VideoRenderer.renderTexture(pPoseStack, ImageAPI.loadingGif().texture(be.getTick(), 1, true), 1, 0, 0,width - 36, height - 36, 36, 36); + VideoRenderer.renderTexture(pPoseStack, ImageAPI.loadingGif().texture(this.be.getTick(), 1, true), 1, 0, 0, this.width - 36, this.height - 36, 36, 36); RenderSystem.disableBlend(); return; } @@ -239,25 +227,25 @@ public void renderVideo(PoseStack pPoseStack) { if (display.getDimensions() == null) return; // Checking if video available RenderSystem.enableBlend(); - int localLeftPos = leftPos + (imageWidth / 2) - (videoWidth / 2); - int localTopPos = topPos + 10; - fill(pPoseStack, localLeftPos, localTopPos, leftPos + (imageWidth / 2) - (videoWidth / 2) + videoWidth, topPos + 10 + videoHeight, MathAPI.argb(255, 0, 0, 0)); + final int localLeftPos = this.leftPos + (this.imageWidth / 2) - (this.videoWidth / 2); + final int localTopPos = this.topPos + 10; + fill(pPoseStack, localLeftPos, localTopPos, this.leftPos + (this.imageWidth / 2) - (this.videoWidth / 2) + this.videoWidth, this.topPos + 10 + this.videoHeight, MathAPI.argb(255, 0, 0, 0)); // Get dimension and get aspect ratio details - Dimension videoDimensions = display.getDimensions(); - VideoDimensionInfo info = VideoMathUtil.calculateAspectRatio(videoWidth, videoHeight, (int) videoDimensions.getWidth(), (int) videoDimensions.getHeight()); + final Dimension videoDimensions = display.getDimensions(); + final VideoDimensionInfo info = VideoMathUtil.calculateAspectRatio(this.videoWidth, this.videoHeight, (int) videoDimensions.getWidth(), (int) videoDimensions.getHeight()); RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - VideoRenderer.renderTexture(pPoseStack, be.requestDisplay().renderTexture(), 1, info.getOffsetX() + localLeftPos, info.getOffsetY() + localTopPos, 0, 0, info.getWidth(), info.getHeight()); + VideoRenderer.renderTexture(pPoseStack, this.be.requestDisplay().renderTexture(), 1, info.getOffsetX() + localLeftPos, info.getOffsetY() + localTopPos, 0, 0, info.getWidth(), info.getHeight()); RenderSystem.disableBlend(); } } @Override public void removed() { - PacketHandler.sendToServer(new ClosedScreenPacket(be.getBlockPos())); + PacketHandler.sendToServer(new ClosedScreenPacket(this.be.getBlockPos())); Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(false); } diff --git a/src/main/java/com/github/NGoedix/watchvideo/client/gui/VideoScreen.java b/src/main/java/com/github/NGoedix/watchvideo/client/gui/VideoScreen.java index 53d58ce..07d6f34 100644 --- a/src/main/java/com/github/NGoedix/watchvideo/client/gui/VideoScreen.java +++ b/src/main/java/com/github/NGoedix/watchvideo/client/gui/VideoScreen.java @@ -2,14 +2,17 @@ import com.github.NGoedix.watchvideo.Reference; import com.github.NGoedix.watchvideo.VideoPlayer; +import com.github.NGoedix.watchvideo.VideoPlayerUtils; import com.github.NGoedix.watchvideo.util.VideoRenderer; import com.github.NGoedix.watchvideo.util.math.VideoDimensionInfo; import com.github.NGoedix.watchvideo.util.math.VideoMathUtil; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.TextComponent; +import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundSource; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraftforge.fml.loading.FMLLoader; @@ -26,15 +29,26 @@ import java.util.Objects; import java.util.TimeZone; -public class VideoScreen extends AbstractContainerScreen { +public class VideoScreen extends Screen { private static final DateFormat FORMAT = new SimpleDateFormat("HH:mm:ss"); + public static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/background.png"); + + public static final ResourceLocation PLAY_BUTTON_TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/play_button.png"); + public static final ResourceLocation PLAY_HOVER_BUTTON_TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/play_button_hover.png"); + + public static final ResourceLocation PAUSE_BUTTON_TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/pause_button.png"); + public static final ResourceLocation PAUSE_HOVER_BUTTON_TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/pause_button_hover.png"); + + public static final ResourceLocation STOP_BUTTON_TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/stop_button.png"); + public static final ResourceLocation STOP_HOVER_BUTTON_TEXTURE = ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/stop_button_hover.png"); + static { FORMAT.setTimeZone(TimeZone.getTimeZone("GMT-00:00")); } // STATUS - private int tick = 0; + private final int tick = 0; private int closingOnTick = -1; private float fadeLevel = 0; private float fadeStep10 = 0; @@ -57,7 +71,7 @@ public class VideoScreen extends AbstractContainerScreen // VIDEO INFO int videoTexture = -1; - public VideoScreen(String url, int volume, boolean controlBlocked, boolean canSkip, int optionInMode, int optionInSecs, int optionOutMode, int optionOutSecs) { + public VideoScreen(final String url, final int volume, final boolean controlBlocked, final boolean canSkip, final int optionInMode, final int optionInSecs, final int optionOutMode, final int optionOutSecs) { this(url, volume, controlBlocked, canSkip, optionInMode != -1 && optionInSecs > 0); this.optionInMode = optionInMode; this.optionInSecs = optionInSecs; @@ -65,10 +79,10 @@ public VideoScreen(String url, int volume, boolean controlBlocked, boolean canSk this.optionOutSecs = optionOutSecs; } - public VideoScreen(String url, int volume, boolean controlBlocked, boolean canSkip, boolean fadeIn) { - super(new DummyContainer(), Objects.requireNonNull(Minecraft.getInstance().player).getInventory(), new TextComponent("")); + public VideoScreen(final String url, final int volume, final boolean controlBlocked, final boolean canSkip, final boolean fadeIn) { + super(new TextComponent("")); - Minecraft minecraft = Minecraft.getInstance(); + final Minecraft minecraft = Minecraft.getInstance(); minecraft.getSoundManager().pause(); this.volume = volume; @@ -82,102 +96,99 @@ public VideoScreen(String url, int volume, boolean controlBlocked, boolean canSk this.player = new org.watermedia.api.player.videolan.VideoPlayer(null, minecraft); Reference.LOGGER.info("Playing video (" + (!controlBlocked ? "not" : "") + "blocked) (" + url + " with volume: " + (int) (minecraft.options.getSoundSourceVolume(SoundSource.MASTER) * volume)); - player.setVolume((int) (minecraft.options.getSoundSourceVolume(SoundSource.MASTER) * volume)); - if (!fadeIn && player.isSafeUse()) { - started = true; - player.start(URI.create(url)); + this.player.setVolume((int) (minecraft.options.getSoundSourceVolume(SoundSource.MASTER) * volume)); + if (!fadeIn && this.player.isSafeUse()) { + this.started = true; + this.player.start(URI.create(url)); } else { - player.startPaused(URI.create(url)); + this.player.startPaused(URI.create(url)); } } @Override - protected void renderLabels(@NotNull PoseStack pPoseStack, int pMouseX, int pMouseY) {} - - @Override - protected void renderBg(@NotNull PoseStack stack, float pPartialTicks, int pMouseX, int pMouseY) { - if (started && !closing) { - videoTexture = player.preRender(); + public void render(final PoseStack stack, final int pMouseX, final int pMouseY, final float pPartialTick) { + if (this.started && !this.closing) { + this.videoTexture = this.player.preRender(); } // Handle easing for fade-in - if ((tick < optionInSecs * 20 && optionInMode != -1) || !started) { - float t = tick / (float) (optionInSecs * 20); - fadeLevel = (float) VideoRenderer.applyEasing(optionInMode, 0, 1, t); - if (!started && fadeLevel >= 1.0) { - if (player.isSafeUse()) - player.play(); - started = true; - fadeLevel = 0; + if ((this.tick < this.optionInSecs * 20 && this.optionInMode != -1) || !this.started) { + final float t = this.tick / (float) (this.optionInSecs * 20); + this.fadeLevel = (float) VideoRenderer.applyEasing(this.optionInMode, 0, 1, t); + if (!this.started && this.fadeLevel >= 1.0) { + if (this.player.isSafeUse()) + this.player.play(); + this.started = true; + this.fadeLevel = 0; } } // Handle easing for fade-out - if (closing || player.isEnded() || player.isBroken()) { - if (optionOutMode == -1) { - System.out.println("Closing without fading out"); - onClose(); + if (this.closing || this.player.isEnded() || this.player.isBroken()) { + if (this.optionOutMode == -1) { + Reference.LOGGER.info("Closed video screen without fade-out"); + this.onClose(); } - if (optionInMode != -1 || closing) { - closing = true; - if (closingOnTick == -1) closingOnTick = tick + optionOutSecs * 20; - float t = (tick - closingOnTick + optionOutSecs * 20) / (float)(optionOutSecs * 20); - fadeLevel = (float) VideoRenderer.applyEasing(optionOutMode, 1, 0, t); - renderBlackBackground(stack); - if (fadeLevel == 0) onClose(); + if (this.optionInMode != -1 || this.closing) { + this.closing = true; + if (this.closingOnTick == -1) this.closingOnTick = this.tick + this.optionOutSecs * 20; + final float t = (this.tick - this.closingOnTick + this.optionOutSecs * 20) / (float)(this.optionOutSecs * 20); + this.fadeLevel = (float) VideoRenderer.applyEasing(this.optionOutMode, 1, 0, t); + this.renderBlackBackground(stack); + if (this.fadeLevel == 0) this.onClose(); return; } } // BLACK SCREEN - if (!player.isPaused() || optionInMode != -1 || optionOutMode != -1) - renderBlackBackground(stack); + if (!this.player.isPaused() || this.optionInMode != -1 || this.optionOutMode != -1) + this.renderBlackBackground(stack); - if (!started) return; + if (!this.started) return; - boolean playingState = (player.isPlaying() || player.isPaused()); + final boolean playingState = (this.player.isPlaying() || this.player.isPaused()); // RENDER VIDEO - if (playingState || player.isStopped() || player.isEnded()) { - renderTexture(stack, videoTexture); + if (playingState || this.player.isStopped() || this.player.isEnded()) { + this.renderTexture(stack, this.videoTexture); } // BLACK SCREEN - if (!player.isPaused()) - renderBlackBackground(stack); + if (!this.player.isPaused()) + this.renderBlackBackground(stack); // RENDER GIF - if (!player.isPlaying() || !player.isPlaying()) { - if (player.isPaused() && player.isPaused()) { - VideoRenderer.renderTexture(stack, VideoPlayer.pausedImage().texture(tick, 1, true), 1, 0, 0, width - 36, height - 36, 36, 36); + if (!this.player.isPlaying() || !this.player.isPlaying()) { + if (this.player.isPaused() && this.player.isPaused()) { + VideoRenderer.renderTexture(stack, VideoPlayer.pausedImage().texture(this.tick, 1, true), 1, 0, 0, this.width - 36, this.height - 36, 36, 36); } else { - VideoRenderer.renderTexture(stack, ImageAPI.loadingGif().texture(tick, 1, true), 1, 0, 0,width - 36, height - 36, 36, 36); + VideoRenderer.renderTexture(stack, ImageAPI.loadingGif().texture(this.tick, 1, true), 1, 0, 0, this.width - 36, this.height - 36, 36, 36); } } // Render icons 10 and -5 seconds - renderStepIcon(stack, pPartialTicks, true); - renderStepIcon(stack, pPartialTicks, false); + this.renderStepIcon(stack, pPartialTick, true); + this.renderStepIcon(stack, pPartialTick, false); // DEBUG RENDERING if (!FMLLoader.isProduction()) { - if (!player.isReady()) return; - VideoRenderer.drawString(stack, String.format("State: %s", player.raw().mediaPlayer().media().info().state().toString()), VideoMathUtil.getHeightCenter(height, -12)); - VideoRenderer.drawString(stack, String.format("Time: %s (%s) / %s (%s)", FORMAT.format(new Date(player.getTime())), player.getTime(), FORMAT.format(new Date(player.getDuration())), player.getDuration()), VideoMathUtil.getHeightCenter(height, 0)); - VideoRenderer.drawString(stack, String.format("Media Duration: %s (%s)", FORMAT.format(new Date(player.getMediaInfoDuration())), player.getMediaInfoDuration()), VideoMathUtil.getHeightCenter(height, 12)); + if (!this.player.isReady()) return; + VideoRenderer.drawString(stack, String.format("State: %s", this.player.raw().mediaPlayer().media().info().state().toString()), VideoMathUtil.getHeightCenter(this.height, -12)); + VideoRenderer.drawString(stack, String.format("Time: %s (%s) / %s (%s)", FORMAT.format(new Date(this.player.getTime())), this.player.getTime(), FORMAT.format(new Date(this.player.getDuration())), this.player.getDuration()), VideoMathUtil.getHeightCenter(this.height, 0)); + VideoRenderer.drawString(stack, String.format("Media Duration: %s (%s)", FORMAT.format(new Date(this.player.getMediaInfoDuration())), this.player.getMediaInfoDuration()), VideoMathUtil.getHeightCenter(this.height, 12)); } } - private void renderTexture(PoseStack stack, int texture) { - if (player.dimension() == null) return; // Checking if video available + private void renderTexture(final PoseStack stack, final int texture) { + if (this.player.dimension() == null) return; // Checking if video available RenderSystem.enableBlend(); - fill(stack, 0, 0, width, height, MathAPI.argb(255, 0, 0, 0)); + fill(stack, 0, 0, this.width, this.height, MathAPI.argb(255, 0, 0, 0)); // Get video dimensions - Dimension videoDimensions = player.dimension(); - VideoDimensionInfo info = VideoMathUtil.calculateAspectRatio(width, height, (int) videoDimensions.getWidth(), (int) videoDimensions.getHeight()); + final Dimension videoDimensions = this.player.dimension(); + final VideoDimensionInfo info = VideoMathUtil.calculateAspectRatio(this.width, this.height, (int) videoDimensions.getWidth(), (int) videoDimensions.getHeight()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); @@ -185,87 +196,87 @@ private void renderTexture(PoseStack stack, int texture) { } - private void renderBlackBackground(PoseStack stack) { + private void renderBlackBackground(final PoseStack stack) { RenderSystem.enableBlend(); - fill(stack, 0, 0, width, height, MathAPI.argb((int) (fadeLevel * 255), 0, 0, 0)); + fill(stack, 0, 0, this.width, this.height, MathAPI.argb((int) (this.fadeLevel * 255), 0, 0, 0)); RenderSystem.disableBlend(); } - private void renderStepIcon(PoseStack stack, float pPartialTicks, boolean forward) { - int texture = forward ? VideoPlayer.step10Image().texture(tick, 1, true) : VideoPlayer.step5Image().texture(tick, 1, true); - float alpha = forward ? fadeStep10 : fadeStep5; - VideoRenderer.renderTexture(stack, texture, alpha, width / 2 + (forward ? 70 : -134), height / 2 - 32, 0, 0, 64, 64); + private void renderStepIcon(final PoseStack stack, final float pPartialTicks, final boolean forward) { + final int texture = forward ? VideoPlayer.step10Image().texture(this.tick, 1, true) : VideoPlayer.step5Image().texture(this.tick, 1, true); + final float alpha = forward ? this.fadeStep10 : this.fadeStep5; + VideoRenderer.renderTexture(stack, texture, alpha, this.width / 2 + (forward ? 70 : -134), this.height / 2 - 32, 0, 0, 64, 64); if (forward) { - fadeStep10 = Math.max(fadeStep10 - (pPartialTicks / 8), 0.0f); + this.fadeStep10 = Math.max(this.fadeStep10 - (pPartialTicks / 8), 0.0f); } else { - fadeStep5 = Math.max(fadeStep5 - (pPartialTicks / 8), 0.0f); + this.fadeStep5 = Math.max(this.fadeStep5 - (pPartialTicks / 8), 0.0f); } } @Override - public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) { + public boolean keyPressed(final int pKeyCode, final int pScanCode, final int pModifiers) { // Shift + ESC (Exit) - if (canSkip && hasShiftDown() && pKeyCode == 256) { + if (this.canSkip && hasShiftDown() && pKeyCode == 256) { this.onClose(); } // Up arrow key (Volume) if (pKeyCode == 265) { - if (volume <= 120) { - volume += 5; + if (this.volume <= 120) { + this.volume += 5; } else { - volume = 125; - float masterVolume = Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER); + this.volume = 125; + final float masterVolume = Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER); Minecraft.getInstance().options.setSoundCategoryVolume(SoundSource.MASTER, masterVolume <= 0.95 ? masterVolume + 0.1F : 1.0F); } - float actualVolume = Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER); - float newVolume = volume * actualVolume; + final float actualVolume = Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER); + final float newVolume = this.volume * actualVolume; Reference.LOGGER.info("Volume UP to: " + newVolume); - player.setVolume((int) newVolume); + this.player.setVolume((int) newVolume); } // Down arrow key (Volume) if (pKeyCode == 264) { - if (volume >= 5) { - volume -= 5; + if (this.volume >= 5) { + this.volume -= 5; } else { - volume = 0; + this.volume = 0; } - float actualVolume = Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER); - float newVolume = volume * actualVolume; + final float actualVolume = Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER); + final float newVolume = this.volume * actualVolume; Reference.LOGGER.info("Volume DOWN to: " + newVolume); - player.setVolume((int) newVolume); + this.player.setVolume((int) newVolume); } // M to mute if (pKeyCode == 77) { - if (player.isMuted()) { - player.unmute(); + if (this.player.isMuted()) { + this.player.unmute(); } else { - player.mute(); + this.player.mute(); } } // If control blocked can't modify the video time - if (controlBlocked) return super.keyPressed(pKeyCode, pScanCode, pModifiers); + if (this.controlBlocked) return super.keyPressed(pKeyCode, pScanCode, pModifiers); // Shift + Right arrow key (Forwards) if (hasShiftDown() && pKeyCode == 262) { - player.seekTo(player.getTime() + 10000); - fadeStep10 = 1; + this.player.seekTo(this.player.getTime() + 10000); + this.fadeStep10 = 1; } // Shift + Left arrow key (Backwards) if (hasShiftDown() && pKeyCode == 263) { - player.seekTo(player.getTime() - 5000); - fadeStep5 = 1; + this.player.seekTo(this.player.getTime() - 5000); + this.fadeStep5 = 1; } // Shift + Space (Pause / Play) if (hasShiftDown() && pKeyCode == 32) { - player.togglePlayback(); + this.player.togglePlayback(); } return super.keyPressed(pKeyCode, pScanCode, pModifiers); @@ -279,31 +290,21 @@ public boolean shouldCloseOnEsc() { @Override public void onClose() { super.onClose(); - if (started) { - started = false; - player.stop(); - player.release(); + if (this.started) { + this.started = false; + this.player.stop(); + this.player.release(); Minecraft.getInstance().getSoundManager().resume(); } } public boolean isFinished() { - return !started; + return !this.started; } @Override protected void init() { - if (Minecraft.getInstance().screen != null) { - this.imageWidth = Minecraft.getInstance().screen.width; - this.imageHeight = Minecraft.getInstance().screen.height; - } super.init(); } - - @Override - protected void containerTick() { - super.containerTick(); - tick++; - } } diff --git a/src/main/java/com/github/NGoedix/watchvideo/network/PacketHandler.java b/src/main/java/com/github/NGoedix/watchvideo/network/PacketHandler.java index c2e446f..82c0c97 100644 --- a/src/main/java/com/github/NGoedix/watchvideo/network/PacketHandler.java +++ b/src/main/java/com/github/NGoedix/watchvideo/network/PacketHandler.java @@ -33,7 +33,7 @@ public class PacketHandler { public static void init() { INSTANCE = NetworkRegistry.ChannelBuilder - .named(new ResourceLocation(Reference.MOD_ID, "network")) + .named(ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "network")) .networkProtocolVersion(() -> PROTOCOL_VERSION) .clientAcceptedVersions(PROTOCOL_VERSION::equals) .serverAcceptedVersions(PROTOCOL_VERSION::equals) diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 42bf5db..cd03c7e 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,12 +1,12 @@ modLoader="javafml" -loaderVersion="[38,)" +loaderVersion="[40,)" license="All Rights Reserved" [[mods]] -modId="videoplayer" -version="3.0.5" -displayName="VideoPlayer" -authors="Goedix" -description=''' + modId="videoplayer" + version="3.1.3" + displayName="VideoPlayer" + authors="Goedix" + description=''' This mod allows the playback of videos in the user interface (GUI), you can play videos for all connected users or for a specific user. Thanks to anarkh_angel for the blocks. ''' @@ -16,4 +16,10 @@ credits="Thanks J-RAP for the help with the API" mandatory=true versionRange="[2.0,)" ordering="AFTER" - side="CLIENT" \ No newline at end of file + side="CLIENT" +[[dependencies.videoplayer]] + modId="forge" + mandatory=true + versionRange="[40.3,)" + ordering="NONE" + side="BOTH" \ No newline at end of file From bca30dfb384b6860cea5f1e4077b31d36f047a33 Mon Sep 17 00:00:00 2001 From: J-RAP Date: Wed, 11 Jun 2025 22:52:48 -0600 Subject: [PATCH 3/3] Require modern watermedia --- src/main/resources/META-INF/mods.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index cd03c7e..58040d2 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -14,7 +14,7 @@ credits="Thanks J-RAP for the help with the API" [[dependencies.videoplayer]] modId="watermedia" mandatory=true - versionRange="[2.0,)" + versionRange="[2.1,2.2)" ordering="AFTER" side="CLIENT" [[dependencies.videoplayer]]