mirror of
https://github.com/TeamMidnightDust/PictureSign.git
synced 2025-12-16 22:25:09 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd9bae83ca | ||
|
|
fcdde95971 | ||
|
|
22d3d621da | ||
|
|
3b3009fefb | ||
|
|
9c550dcd7d |
@@ -58,7 +58,7 @@ allprojects {
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
options.release = 17
|
||||
options.release = 21
|
||||
}
|
||||
ext {
|
||||
releaseChangelog = {
|
||||
|
||||
@@ -2,6 +2,10 @@ package eu.midnightdust.picturesign;
|
||||
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import eu.midnightdust.picturesign.config.PictureSignConfig;
|
||||
import eu.midnightdust.picturesign.util.GIFHandler;
|
||||
import eu.midnightdust.picturesign.util.MediaHandler;
|
||||
import eu.midnightdust.picturesign.util.WaterGIFHandler;
|
||||
import eu.midnightdust.picturesign.util.WaterMediaHandler;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
@@ -13,7 +17,6 @@ import org.lwjgl.glfw.GLFW;
|
||||
public class PictureSignClient {
|
||||
public static Logger LOGGER = LogManager.getLogger("PictureSign");
|
||||
public static final String MOD_ID = "picturesign";
|
||||
public static final boolean hasWaterMedia = PlatformFunctions.isModLoaded("watermedia");
|
||||
public static String[] clipboard = new String[4];
|
||||
public static final MinecraftClient client = MinecraftClient.getInstance();
|
||||
public static final KeyBinding BINDING_COPY_SIGN = new KeyBinding("key."+MOD_ID+".copy_sign",
|
||||
@@ -21,8 +24,12 @@ public class PictureSignClient {
|
||||
|
||||
public static void init() {
|
||||
PictureSignConfig.init(MOD_ID, PictureSignConfig.class);
|
||||
if (PlatformFunctions.isModLoaded("watermedia")) {
|
||||
MediaHandler.registerHandler(WaterMediaHandler::new);
|
||||
GIFHandler.registerHandler(WaterGIFHandler::new);
|
||||
}
|
||||
}
|
||||
public static Identifier id(String path) {
|
||||
return new Identifier(MOD_ID, path);
|
||||
return Identifier.of(MOD_ID, path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ package eu.midnightdust.picturesign.mixin;
|
||||
import eu.midnightdust.picturesign.PictureSignClient;
|
||||
import eu.midnightdust.picturesign.config.PictureSignConfig;
|
||||
import eu.midnightdust.picturesign.screen.PictureSignHelperScreen;
|
||||
import eu.midnightdust.picturesign.screen.TextIconButtonWidget;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen;
|
||||
import net.minecraft.client.gui.widget.TextIconButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -30,7 +30,7 @@ public abstract class MixinSignEditScreen extends Screen {
|
||||
@Unique private static final Identifier PICTURESIGN_ICON_TEXTURE = id("icon/picturesign");
|
||||
@Unique private static final Identifier CLIPBOARD_ICON_TEXTURE = id("icon/clipboard");
|
||||
@Unique private static final Identifier TRASHBIN_ICON_TEXTURE = id("icon/trashbin");
|
||||
@Unique private static boolean picturesign$switchScreen = false;
|
||||
@Unique private static boolean switchScreen = false;
|
||||
|
||||
protected MixinSignEditScreen(Text title) {
|
||||
super(title);
|
||||
@@ -61,7 +61,7 @@ public abstract class MixinSignEditScreen extends Screen {
|
||||
this.addDrawableChild(trashbinBuilder);
|
||||
|
||||
TextIconButtonWidget picturesignBuilder = TextIconButtonWidget.builder(Text.empty(), (buttonWidget) -> {
|
||||
picturesign$switchScreen = true;
|
||||
switchScreen = true;
|
||||
Objects.requireNonNull(client).setScreen(new PictureSignHelperScreen(this.blockEntity, front, false));
|
||||
}, true).texture(PICTURESIGN_ICON_TEXTURE, 16, 16).dimension(20, 20).build();
|
||||
picturesignBuilder.setPosition(this.width - 40, this.height - 40);
|
||||
@@ -70,8 +70,8 @@ public abstract class MixinSignEditScreen extends Screen {
|
||||
}
|
||||
@Inject(at = @At("HEAD"), method = "removed", cancellable = true)
|
||||
private void picturesign$removed(CallbackInfo ci) {
|
||||
if (picturesign$switchScreen) {
|
||||
picturesign$switchScreen = false;
|
||||
if (switchScreen) {
|
||||
switchScreen = false;
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.joml.Matrix4f;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.client;
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.hasWaterMedia;
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.id;
|
||||
import static eu.midnightdust.picturesign.util.PictureSignType.GIF;
|
||||
import static eu.midnightdust.picturesign.util.PictureSignType.PICTURE;
|
||||
@@ -96,9 +95,9 @@ public class PictureRenderer {
|
||||
|
||||
MediaHandler mediaHandler = null;
|
||||
GIFHandler gifHandler = null;
|
||||
if (errorMessage == null && MediaHandler.hasValidImplementation()) {
|
||||
if (type.isVideo || type.isAudio) mediaHandler = MediaHandler.getOrCreate(videoId, pos);
|
||||
else if (type == GIF && hasWaterMedia) gifHandler = GIFHandler.getOrCreate(videoId);
|
||||
if (errorMessage == null) {
|
||||
if ((type.isVideo || type.isAudio) && MediaHandler.hasValidImplementation()) mediaHandler = MediaHandler.getOrCreate(videoId, pos);
|
||||
else if (type == GIF && GIFHandler.hasValidImplementation()) gifHandler = GIFHandler.getOrCreate(videoId);
|
||||
else {
|
||||
MediaHandler.closePlayer(videoId);
|
||||
GIFHandler.closePlayer(videoId);
|
||||
@@ -107,8 +106,6 @@ public class PictureRenderer {
|
||||
|
||||
if (isDisabledViaRedstone(blockEntity.getWorld(), pos)) {
|
||||
if (mediaHandler != null && mediaHandler.isWorking() && !mediaHandler.isStopped()) mediaHandler.stop();
|
||||
|
||||
//PictureURLUtils.cachedJsonData.remove(url);
|
||||
return;
|
||||
}
|
||||
else if (mediaHandler != null && mediaHandler.isDeactivated) {
|
||||
@@ -126,8 +123,7 @@ public class PictureRenderer {
|
||||
if (!mediaHandler.playbackStarted && !mediaHandler.hasMedia()) {
|
||||
mediaHandler.play(url, type.isVideo);
|
||||
if (info != null && info.start() > 0) mediaHandler.setTime(info.start());
|
||||
if (type.isLooped && !mediaHandler.hasMedia() && !mediaHandler.playbackStarted)
|
||||
mediaHandler.setRepeat(true);
|
||||
mediaHandler.setRepeat(type.isLooped);
|
||||
}
|
||||
|
||||
if (info != null && info.volume() >= 0) mediaHandler.setMaxVolume(info.volume());
|
||||
@@ -163,6 +159,7 @@ public class PictureRenderer {
|
||||
texture = data.identifier;
|
||||
} else if (type.isVideo && mediaHandler != null) {
|
||||
if (mediaHandler.isWorking()) {
|
||||
mediaHandler.preRender();
|
||||
int rawTexture = mediaHandler.getTexture();
|
||||
if (rawTexture != -1) {
|
||||
RenderSystem.setShaderTexture(0, rawTexture);
|
||||
@@ -192,16 +189,15 @@ public class PictureRenderer {
|
||||
matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(dimensions.zRot()));
|
||||
|
||||
Matrix4f matrix4f = matrixStack.peek().getPositionMatrix();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT);
|
||||
BufferBuilder buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT);
|
||||
|
||||
buffer.vertex(matrix4f, dimensions.width(), 0.0F, 1.0F).color(255, 255, 255, 255).texture(1.0F, 1.0F).light(l).overlay(overlay).next();
|
||||
buffer.vertex(matrix4f, dimensions.width(), 0.0F, 1.0F).color(255, 255, 255, 255).texture(1.0F, 1.0F).light(l).overlay(overlay);
|
||||
|
||||
buffer.vertex(matrix4f, dimensions.width(), dimensions.height(), 1.0F).color(255, 255, 255, 255).texture(1.0F, 0.0F).light(l).overlay(overlay).next();
|
||||
buffer.vertex(matrix4f, dimensions.width(), dimensions.height(), 1.0F).color(255, 255, 255, 255).texture(1.0F, 0.0F).light(l).overlay(overlay);
|
||||
|
||||
buffer.vertex(matrix4f, 0.0F, dimensions.height(), 1.0F).color(255, 255, 255, 255).texture(0.0F, 0.0F).light(l).overlay(overlay).next();
|
||||
buffer.vertex(matrix4f, 0.0F, dimensions.height(), 1.0F).color(255, 255, 255, 255).texture(0.0F, 0.0F).light(l).overlay(overlay);
|
||||
|
||||
buffer.vertex(matrix4f, 0.0F, 0.0F, 1.0F).color(255, 255, 255, 255).texture(0.0F, 1.0F).light(l).overlay(overlay).next();
|
||||
buffer.vertex(matrix4f, 0.0F, 0.0F, 1.0F).color(255, 255, 255, 255).texture(0.0F, 1.0F).light(l).overlay(overlay);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(buffer.end());
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.SliderWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.TextIconButtonWidget;
|
||||
import net.minecraft.client.render.DiffuseLighting;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
@@ -384,7 +385,7 @@ public class PictureSignHelperScreen extends Screen {
|
||||
else {
|
||||
MatrixStack matrices = context.getMatrices();
|
||||
matrices.scale(4.5F, 4.5F, 1.0F);
|
||||
context.drawTexture(new Identifier("textures/gui/hanging_signs/" + this.signType.name() + ".png"), -8, -8, 0.0F, 0.0F, 16, 16, 16, 16);
|
||||
context.drawTexture(Identifier.ofVanilla("textures/gui/hanging_signs/" + this.signType.name() + ".png"), -8, -8, 0.0F, 0.0F, 16, 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package eu.midnightdust.picturesign.screen;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract class TextIconButtonWidget extends ButtonWidget {
|
||||
protected final Identifier texture;
|
||||
protected final int textureWidth;
|
||||
protected final int textureHeight;
|
||||
|
||||
TextIconButtonWidget(int width, int height, Text message, int textureWidth, int textureHeight, Identifier texture, ButtonWidget.PressAction onPress, @Nullable ButtonWidget.NarrationSupplier narrationSupplier) {
|
||||
super(0, 0, width, height, message, onPress, narrationSupplier == null ? DEFAULT_NARRATION_SUPPLIER : narrationSupplier);
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public static Builder builder(Text text, ButtonWidget.PressAction onPress, boolean hideLabel) {
|
||||
return new Builder(text, onPress, hideLabel);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class Builder {
|
||||
private final Text text;
|
||||
private final ButtonWidget.PressAction onPress;
|
||||
private final boolean hideText;
|
||||
private int width = 150;
|
||||
private int height = 20;
|
||||
@Nullable
|
||||
private Identifier texture;
|
||||
private int textureWidth;
|
||||
private int textureHeight;
|
||||
@Nullable
|
||||
ButtonWidget.NarrationSupplier narrationSupplier;
|
||||
|
||||
public Builder(Text text, ButtonWidget.PressAction onPress, boolean hideText) {
|
||||
this.text = text;
|
||||
this.onPress = onPress;
|
||||
this.hideText = hideText;
|
||||
}
|
||||
|
||||
public Builder width(int width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dimension(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder texture(Identifier texture, int width, int height) {
|
||||
this.texture = texture;
|
||||
this.textureWidth = width;
|
||||
this.textureHeight = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder narration(ButtonWidget.NarrationSupplier narrationSupplier) {
|
||||
this.narrationSupplier = narrationSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextIconButtonWidget build() {
|
||||
if (this.texture == null) {
|
||||
throw new IllegalStateException("Sprite not set");
|
||||
} else {
|
||||
this.texture = new Identifier(texture.getNamespace(), "textures/gui/sprites/"+texture.getPath() +".png");
|
||||
return new IconOnly(this.width, this.height, this.text, this.textureWidth, this.textureHeight, this.texture, this.onPress, this.narrationSupplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class IconOnly extends TextIconButtonWidget {
|
||||
protected IconOnly(int i, int j, Text text, int k, int l, Identifier identifier, ButtonWidget.PressAction pressAction, @Nullable ButtonWidget.NarrationSupplier narrationSupplier) {
|
||||
super(i, j, text, k, l, identifier, pressAction, narrationSupplier);
|
||||
}
|
||||
@Override
|
||||
public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.renderButton(context, mouseX, mouseY, delta);
|
||||
int i = this.getX() + this.getWidth() / 2 - this.textureWidth / 2;
|
||||
int j = this.getY() + this.getHeight() / 2 - this.textureHeight / 2;
|
||||
context.drawTexture(this.texture, i, j, 0, 0, this.textureWidth, this.textureHeight, this.textureWidth, this.textureHeight);
|
||||
}
|
||||
|
||||
public void drawMessage(DrawContext context, TextRenderer textRenderer, int color) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,63 @@
|
||||
package eu.midnightdust.picturesign.util;
|
||||
|
||||
import me.srrapero720.watermedia.api.image.ImageAPI;
|
||||
import me.srrapero720.watermedia.api.image.ImageCache;
|
||||
import me.srrapero720.watermedia.api.math.MathAPI;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.client;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class GIFHandler {
|
||||
public static Map<Identifier, GIFHandler> gifPlayers = new HashMap<>();
|
||||
private static final List<Function<Identifier, GIFHandler>> implementations = new ArrayList<>();
|
||||
public static Map<Identifier, GIFHandler> gifHandlers = new HashMap<>();
|
||||
|
||||
public final Identifier id;
|
||||
public boolean playbackStarted;
|
||||
private ImageCache player;
|
||||
private long tick = 0L;
|
||||
|
||||
private GIFHandler(Identifier id) {
|
||||
System.out.println("New GIF handler :" + id);
|
||||
public GIFHandler(Identifier id) {
|
||||
this.id = id;
|
||||
gifPlayers.put(id, this);
|
||||
gifHandlers.put(id, this);
|
||||
}
|
||||
public static void registerHandler(Function<Identifier, GIFHandler> handler) {
|
||||
implementations.add(handler);
|
||||
}
|
||||
public static boolean hasValidImplementation() {
|
||||
return !implementations.isEmpty();
|
||||
}
|
||||
public static GIFHandler getOrCreate(Identifier id) {
|
||||
if (gifPlayers.containsKey(id)) return gifPlayers.get(id);
|
||||
else return new GIFHandler(id);
|
||||
if (gifHandlers.containsKey(id)) return gifHandlers.get(id);
|
||||
AtomicReference<GIFHandler> handler = new AtomicReference<>();
|
||||
implementations.forEach(impl -> {
|
||||
handler.set(impl.apply(id));
|
||||
});
|
||||
return handler.get();
|
||||
}
|
||||
public void tick() {
|
||||
if (player != null && player.getRenderer() != null && tick < player.getRenderer().duration) tick += 1;
|
||||
else tick = 0;
|
||||
}
|
||||
|
||||
public void closePlayer() {
|
||||
player.release();
|
||||
player = null;
|
||||
gifPlayers.remove(this.id);
|
||||
gifHandlers.remove(this.id);
|
||||
}
|
||||
public static void closePlayer(Identifier videoId) {
|
||||
if (gifPlayers.containsKey(videoId)) gifPlayers.get(videoId).closePlayer();
|
||||
if (gifHandlers.containsKey(videoId)) gifHandlers.get(videoId).closePlayer();
|
||||
}
|
||||
public static void closeAll() {
|
||||
gifPlayers.forEach((id, handler) -> handler.closePlayer());
|
||||
gifPlayers.clear();
|
||||
gifHandlers.forEach((id, handler) -> handler.closePlayer());
|
||||
gifHandlers.clear();
|
||||
}
|
||||
|
||||
public void play(String url) {
|
||||
this.player = ImageAPI.getCache(url, client);
|
||||
player.load();
|
||||
this.playbackStarted = true;
|
||||
}
|
||||
public boolean hasMedia() {
|
||||
return player != null && player.getStatus() == ImageCache.Status.READY;
|
||||
return false;
|
||||
}
|
||||
public int getTexture() {
|
||||
return player.getRenderer().texture(tick,
|
||||
(MathAPI.tickToMs(client.getTickDelta())), true);
|
||||
return -1;
|
||||
}
|
||||
public boolean isWorking() {
|
||||
if (player != null && player.getException() != null) player.getException().fillInStackTrace();
|
||||
return player != null && player.getStatus() == ImageCache.Status.READY && player.getRenderer() != null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,21 @@ package eu.midnightdust.picturesign.util;
|
||||
import eu.midnightdust.picturesign.config.PictureSignConfig;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.watermedia.api.player.videolan.VideoPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.client;
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.hasWaterMedia;
|
||||
|
||||
public abstract class MediaHandler {
|
||||
private static final List<BiFunction<Identifier, BlockPos, MediaHandler>> implementations = new ArrayList<>();
|
||||
public static Map<Identifier, MediaHandler> mediaHandlers = new HashMap<>();
|
||||
|
||||
public final Identifier id;
|
||||
@@ -21,19 +26,23 @@ public abstract class MediaHandler {
|
||||
public boolean isDeactivated;
|
||||
int maxVolume = 100;
|
||||
|
||||
MediaHandler(Identifier id, BlockPos pos) {
|
||||
public MediaHandler(Identifier id, BlockPos pos) {
|
||||
this.id = id;
|
||||
this.pos = pos;
|
||||
}
|
||||
public static void registerHandler(BiFunction<Identifier, BlockPos, MediaHandler> handler) {
|
||||
implementations.add(handler);
|
||||
}
|
||||
public static boolean hasValidImplementation() {
|
||||
return !implementations.isEmpty();
|
||||
}
|
||||
public static MediaHandler getOrCreate(Identifier id, BlockPos pos) {
|
||||
if (mediaHandlers.containsKey(id)) return mediaHandlers.get(id);
|
||||
else if (hasWaterMedia) return new WaterMediaHandler(id, pos);
|
||||
// Add new implementations here via Mixin
|
||||
else return null;
|
||||
}
|
||||
public static boolean hasValidImplementation() { // Mixin here to add new Multimedia implementations
|
||||
if (hasWaterMedia) return true;
|
||||
else return false;
|
||||
AtomicReference<MediaHandler> handler = new AtomicReference<>();
|
||||
implementations.forEach(impl -> {
|
||||
handler.set(impl.apply(id, pos));
|
||||
});
|
||||
return handler.get();
|
||||
}
|
||||
public void setVolumeBasedOnDistance() {
|
||||
if (!isWorking() || client.player == null) return;
|
||||
@@ -44,9 +53,11 @@ public abstract class MediaHandler {
|
||||
return;
|
||||
}
|
||||
double distance = this.pos.getSquaredDistance(playerPos) / PictureSignConfig.audioDistanceMultiplier;
|
||||
setVolume((int) MathHelper.clamp(maxVolume-distance, 0, 100));
|
||||
setVolume((int) Math.clamp(maxVolume-distance, 0, 100));
|
||||
}
|
||||
void setVolume(int volume) {}
|
||||
@ApiStatus.Internal
|
||||
public void setVolume(int volume) {} // Please use 'setMaxVolume' to adjust the playback volume
|
||||
|
||||
public void setMaxVolume(int volume) {
|
||||
maxVolume = volume;
|
||||
}
|
||||
@@ -54,8 +65,7 @@ public abstract class MediaHandler {
|
||||
public void closePlayer() {}
|
||||
|
||||
public static void closePlayer(Identifier videoId) {
|
||||
MediaHandler mediaHandler = mediaHandlers.getOrDefault(videoId, null);
|
||||
if (mediaHandler != null) mediaHandler.closePlayer();
|
||||
if (mediaHandlers.get(videoId) instanceof MediaHandler mediaHandler) mediaHandler.closePlayer();
|
||||
}
|
||||
public static void closeAll() {
|
||||
mediaHandlers.forEach(((id, player) -> player.closePlayer()));
|
||||
@@ -84,6 +94,8 @@ public abstract class MediaHandler {
|
||||
}
|
||||
public void setTime(long value) {
|
||||
}
|
||||
public void preRender() {
|
||||
}
|
||||
public int getTexture() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package eu.midnightdust.picturesign.util;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.watermedia.api.image.ImageAPI;
|
||||
import org.watermedia.api.image.ImageCache;
|
||||
import org.watermedia.api.math.MathAPI;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.client;
|
||||
|
||||
public class WaterGIFHandler extends GIFHandler {
|
||||
private ImageCache player;
|
||||
private int tick = 0;
|
||||
|
||||
public WaterGIFHandler(Identifier id) {
|
||||
super(id);
|
||||
}
|
||||
@Override
|
||||
public void tick() {
|
||||
if (player != null && player.getRenderer() != null && tick < player.getRenderer().duration) tick += 1;
|
||||
else tick = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closePlayer() {
|
||||
player.release();
|
||||
player = null;
|
||||
super.closePlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void play(String url) {
|
||||
this.player = ImageAPI.getCache(URI.create(url), client);
|
||||
player.load();
|
||||
super.play(url);
|
||||
}
|
||||
@Override
|
||||
public boolean hasMedia() {
|
||||
return player != null && player.getStatus() == ImageCache.Status.READY;
|
||||
}
|
||||
@Override
|
||||
public int getTexture() {
|
||||
return player.getRenderer().texture(tick,
|
||||
(MathAPI.tickToMs(client.getRenderTickCounter().getTickDelta(true))), true);
|
||||
}
|
||||
@Override
|
||||
public boolean isWorking() {
|
||||
if (player != null && player.getException() != null) player.getException().fillInStackTrace();
|
||||
return player != null && player.getStatus() == ImageCache.Status.READY && player.getRenderer() != null;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,28 @@
|
||||
package eu.midnightdust.picturesign.util;
|
||||
|
||||
import me.srrapero720.watermedia.api.player.PlayerAPI;
|
||||
import me.srrapero720.watermedia.api.player.SyncBasePlayer;
|
||||
import me.srrapero720.watermedia.api.player.SyncMusicPlayer;
|
||||
import me.srrapero720.watermedia.api.player.SyncVideoPlayer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.watermedia.api.player.PlayerAPI;
|
||||
import org.watermedia.api.player.videolan.BasePlayer;
|
||||
import org.watermedia.api.player.videolan.MusicPlayer;
|
||||
import org.watermedia.api.player.videolan.VideoPlayer;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.client;
|
||||
|
||||
public class WaterMediaHandler extends MediaHandler {
|
||||
private SyncBasePlayer player;
|
||||
private BasePlayer player;
|
||||
|
||||
WaterMediaHandler(Identifier id, BlockPos pos) {
|
||||
public WaterMediaHandler(Identifier id, BlockPos pos) {
|
||||
super(id, pos);
|
||||
mediaHandlers.put(id, this);
|
||||
}
|
||||
@Override
|
||||
void setVolume(int volume) {
|
||||
public void setVolume(int volume) {
|
||||
player.setVolume((int) (volume * MinecraftClient.getInstance().options.getSoundVolume(SoundCategory.MASTER)));
|
||||
}
|
||||
|
||||
@@ -36,7 +38,7 @@ public class WaterMediaHandler extends MediaHandler {
|
||||
@Override
|
||||
public void stop() {
|
||||
player.stop();
|
||||
isDeactivated = true;
|
||||
super.stop();
|
||||
}
|
||||
@Override
|
||||
public boolean isStopped() {
|
||||
@@ -57,10 +59,10 @@ public class WaterMediaHandler extends MediaHandler {
|
||||
|
||||
@Override
|
||||
public void play(String url, boolean isVideo) {
|
||||
this.player = isVideo ? new SyncVideoPlayer(client) : new SyncMusicPlayer();
|
||||
this.player = isVideo ? new VideoPlayer(client) : new MusicPlayer();
|
||||
mediaHandlers.put(id, this);
|
||||
if (player.isBroken()) return;
|
||||
player.start(url);
|
||||
player.start(URI.create(url));
|
||||
this.playbackStarted = true;
|
||||
}
|
||||
@Override
|
||||
@@ -80,10 +82,15 @@ public class WaterMediaHandler extends MediaHandler {
|
||||
player.seekTo(value);
|
||||
}
|
||||
@Override
|
||||
public void preRender() {
|
||||
if (player instanceof VideoPlayer videoPlayer) {
|
||||
videoPlayer.preRender();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getTexture() {
|
||||
if (player instanceof SyncVideoPlayer videoPlayer) {
|
||||
int tex = videoPlayer.getGlTexture();
|
||||
if (GL11.glIsTexture(tex)) return tex;
|
||||
if (player instanceof VideoPlayer videoPlayer) {
|
||||
return videoPlayer.texture();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PictureSignClientFabric implements ClientModInitializer {
|
||||
}
|
||||
});
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
GIFHandler.gifPlayers.forEach(((identifier, handler) -> handler.tick()));
|
||||
GIFHandler.gifHandlers.forEach(((identifier, handler) -> handler.tick()));
|
||||
if (!BINDING_COPY_SIGN.isPressed()) return;
|
||||
BINDING_COPY_SIGN.setPressed(false);
|
||||
if (client.player == null || client.world == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK) return;
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
"recommends": {
|
||||
"watermedia": "*"
|
||||
},
|
||||
"breaks": {
|
||||
"watermedia": "<2.1.0"
|
||||
},
|
||||
"mixins": [
|
||||
"picturesign.mixins.json"
|
||||
]
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
org.gradle.jvmargs=-Xmx2048M
|
||||
|
||||
minecraft_version=1.20.1
|
||||
yarn_mappings=1.20.1+build.10
|
||||
enabled_platforms=fabric
|
||||
minecraft_version=1.21
|
||||
yarn_mappings=1.21+build.2
|
||||
enabled_platforms=fabric,neoforge
|
||||
|
||||
archives_base_name=picturesign
|
||||
mod_version=2.0.0-1.20.1
|
||||
mod_version=2.0.1
|
||||
maven_group=eu.midnightdust
|
||||
release_type=alpha
|
||||
release_type=release
|
||||
curseforge_id=533897
|
||||
modrinth_id=9WP2dmkk
|
||||
|
||||
midnightlib_version=1.4.1
|
||||
watermedia_version=2.0.64
|
||||
midnightlib_version=1.6.3
|
||||
watermedia_version=2.1.2
|
||||
|
||||
iris_version=1.6.17+1.20.4
|
||||
# The latest Iris version causes the build to fail, but we don't need that anyway
|
||||
|
||||
fabric_loader_version=0.15.11
|
||||
fabric_api_version=0.92.2+1.20.1
|
||||
fabric_api_version=0.100.1+1.21
|
||||
|
||||
neoforge_version=21.0.14-beta
|
||||
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PictureSignClientGameEvents {
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void endClientTick(ClientTickEvent.Post event) {
|
||||
GIFHandler.gifPlayers.forEach(((identifier, handler) -> handler.tick()));
|
||||
GIFHandler.gifHandlers.forEach(((identifier, handler) -> handler.tick()));
|
||||
if (!BINDING_COPY_SIGN.isPressed()) return;
|
||||
BINDING_COPY_SIGN.setPressed(false);
|
||||
if (client.player == null || client.world == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK) return;
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
package eu.midnightdust.picturesign.neoforge;
|
||||
|
||||
import eu.midnightdust.picturesign.PictureSignClient;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static eu.midnightdust.picturesign.PictureSignClient.MOD_ID;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@Mod(value = MOD_ID, dist = Dist.CLIENT)
|
||||
public class PictureSignClientNeoForge {
|
||||
public static List<ResourcePackProfile> defaultEnabledPacks = Lists.newArrayList();
|
||||
|
||||
public PictureSignClientNeoForge() {
|
||||
PictureSignClient.init();
|
||||
}
|
||||
|
||||
@@ -16,21 +16,21 @@ Use signs to display custom images and videos completely client-side!
|
||||
[[mixins]]
|
||||
config = "picturesign.mixins.json"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
[[dependencies.picturesign]]
|
||||
modId = "neoforge"
|
||||
mandatory = true
|
||||
versionRange = "[21.0,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
[[dependencies.picturesign]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.21,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.visualoverhaul]]
|
||||
[[dependencies.picturesign]]
|
||||
modId = "midnightlib"
|
||||
mandatory = true
|
||||
versionRange = "[1.0,)"
|
||||
|
||||
@@ -10,6 +10,6 @@ pluginManagement {
|
||||
include("common")
|
||||
include("fabric")
|
||||
//include("quilt")
|
||||
//include("neoforge")
|
||||
include("neoforge")
|
||||
|
||||
rootProject.name = "picturesign"
|
||||
|
||||
Reference in New Issue
Block a user