mirror of
https://github.com/TeamMidnightDust/PictureSign.git
synced 2025-12-11 12:05:09 +01:00
Add video support
This commit is contained in:
14
build.gradle
14
build.gradle
@@ -17,6 +17,15 @@ repositories {
|
||||
maven {
|
||||
url = "https://api.modrinth.com/maven"
|
||||
}
|
||||
maven {
|
||||
url "https://cursemaven.com"
|
||||
content {
|
||||
includeGroup "curse.maven"
|
||||
}
|
||||
}
|
||||
flatDir {
|
||||
dirs("localMaven")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -26,9 +35,12 @@ dependencies {
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
modImplementation "maven.modrinth:iris:${project.iris_version}"
|
||||
modCompileOnly "maven.modrinth:iris:${project.iris_version}"
|
||||
modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
|
||||
include "maven.modrinth:midnightlib:${project.midnightlib_version}"
|
||||
modImplementation "maven.modrinth:videolib:${project.videolib_version}"
|
||||
include "maven.modrinth:videolib:${project.videolib_version}"
|
||||
implementation("uk.co.caprica:vlcj:${project.vlcj_version}")
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
@@ -8,12 +8,15 @@ org.gradle.jvmargs=-Xmx1G
|
||||
loader_version=0.14.8
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.4.1
|
||||
mod_version = 1.5.0
|
||||
maven_group = eu.midnightdust
|
||||
archives_base_name = picturesign
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.56.0+1.19
|
||||
midnightlib_version=0.5.2
|
||||
midnightlib_version=1.0.0-fabric
|
||||
videolib_version=0.2.0-mnd
|
||||
vlcj_version=4.8.2
|
||||
|
||||
iris_version=1.19.x-v1.2.5
|
||||
|
||||
BIN
localMaven/videolib-0.2.0-mnd.jar
Normal file
BIN
localMaven/videolib-0.2.0-mnd.jar
Normal file
Binary file not shown.
@@ -4,6 +4,7 @@ import eu.midnightdust.lib.config.MidnightConfig;
|
||||
|
||||
public class PictureSignConfig extends MidnightConfig {
|
||||
@Entry public static boolean enabled = true;
|
||||
@Entry public static boolean enableVideoSigns = true;
|
||||
@Entry public static boolean translucency = false;
|
||||
@Entry public static boolean helperUi = true;
|
||||
@Entry public static boolean exceedVanillaLineLength = false;
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.midnightdust.picturesign.mixin;
|
||||
|
||||
import eu.midnightdust.picturesign.config.PictureSignConfig;
|
||||
import eu.midnightdust.picturesign.render.PictureSignRenderer;
|
||||
import eu.midnightdust.picturesign.util.PictureSignType;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
@@ -19,14 +20,14 @@ public abstract class MixinSignBlockEntityRenderer implements BlockEntityRendere
|
||||
PictureSignRenderer psRenderer = new PictureSignRenderer();
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "render")
|
||||
public void ps$onRender(SignBlockEntity signBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, int overlay, CallbackInfo ci) {
|
||||
if (PictureSignConfig.enabled && signBlockEntity.getTextOnRow(0,false).getString().matches("(!PS:.*)")) {
|
||||
psRenderer.render(signBlockEntity, matrixStack, light, overlay);
|
||||
public void ps$onRender(SignBlockEntity sign, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, int overlay, CallbackInfo ci) {
|
||||
if (PictureSignConfig.enabled && !PictureSignType.isType(sign, PictureSignType.NONE)) {
|
||||
psRenderer.render(sign, matrixStack, light, overlay);
|
||||
}
|
||||
}
|
||||
@Inject(at = @At("HEAD"), method = "shouldRender", cancellable = true)
|
||||
private static void shouldRender(SignBlockEntity sign, int signColor, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (PictureSignConfig.enabled && sign.getTextOnRow(0,false).getString().matches("(!PS:.*)")) cir.setReturnValue(true);
|
||||
if (PictureSignConfig.enabled && !PictureSignType.isType(sign, PictureSignType.NONE)) cir.setReturnValue(true);
|
||||
}
|
||||
@Unique
|
||||
@Override
|
||||
@@ -36,6 +37,6 @@ public abstract class MixinSignBlockEntityRenderer implements BlockEntityRendere
|
||||
@Unique
|
||||
@Override
|
||||
public boolean rendersOutsideBoundingBox(SignBlockEntity sign) {
|
||||
return PictureSignConfig.enabled && sign.getTextOnRow(0, false).getString().matches("(!PS:.*)");
|
||||
return PictureSignConfig.enabled && !PictureSignType.isType(sign, PictureSignType.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,25 +35,17 @@ public abstract class MixinSignEditScreen extends Screen {
|
||||
private void picturesign$init(CallbackInfo ci) {
|
||||
if (PictureSignClient.clipboard != null && PictureSignClient.clipboard[0] != null)
|
||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width - 84, this.height - 40, 20, 20, 0, 0, 20, CLIPBOARD_ICON_TEXTURE, 32, 64, (buttonWidget) -> {
|
||||
sign.setTextOnRow(0, Text.of(PictureSignClient.clipboard[0]));
|
||||
sign.setTextOnRow(1, Text.of(PictureSignClient.clipboard[1]));
|
||||
sign.setTextOnRow(2, Text.of(PictureSignClient.clipboard[2]));
|
||||
sign.setTextOnRow(3, Text.of(PictureSignClient.clipboard[3]));
|
||||
text[0] = PictureSignClient.clipboard[0];
|
||||
text[1] = PictureSignClient.clipboard[1];
|
||||
text[2] = PictureSignClient.clipboard[2];
|
||||
text[3] = PictureSignClient.clipboard[3];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text[i] = PictureSignClient.clipboard[i];
|
||||
sign.setTextOnRow(i, Text.of(text[i]));
|
||||
}
|
||||
}, Text.of("")));
|
||||
if (PictureSignConfig.helperUi)
|
||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width - 62, this.height - 40, 20, 20, 0, 0, 20, TRASHBIN_ICON_TEXTURE, 32, 64, (buttonWidget) -> {
|
||||
sign.setTextOnRow(0, Text.of(""));
|
||||
sign.setTextOnRow(1, Text.of(""));
|
||||
sign.setTextOnRow(2, Text.of(""));
|
||||
sign.setTextOnRow(3, Text.of(""));
|
||||
text[0] = "";
|
||||
text[1] = "";
|
||||
text[2] = "";
|
||||
text[3] = "";
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text[i] = "";
|
||||
sign.setTextOnRow(i, Text.empty());
|
||||
}
|
||||
}, Text.of("")));
|
||||
if (PictureSignConfig.helperUi)
|
||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width - 40, this.height - 40, 20, 20, 0, 0, 20, PICTURESIGN_ICON_TEXTURE, 32, 64, (buttonWidget) -> {
|
||||
|
||||
@@ -1,40 +1,59 @@
|
||||
package eu.midnightdust.picturesign.render;
|
||||
|
||||
import com.igrium.videolib.VideoLib;
|
||||
import com.igrium.videolib.api.VideoHandle;
|
||||
import com.igrium.videolib.api.VideoHandleFactory;
|
||||
import com.igrium.videolib.api.VideoManager;
|
||||
import com.igrium.videolib.api.VideoPlayer;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import eu.midnightdust.picturesign.PictureDownloader;
|
||||
import eu.midnightdust.picturesign.PictureSignClient;
|
||||
import eu.midnightdust.picturesign.config.PictureSignConfig;
|
||||
import eu.midnightdust.picturesign.util.PictureSignType;
|
||||
import eu.midnightdust.picturesign.util.PictureURLUtils;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PictureSignRenderer {
|
||||
VideoManager videoManager = VideoLib.getInstance().getVideoManager();
|
||||
List<BlockPos> playedOnce = new ArrayList<>();
|
||||
|
||||
public void render(SignBlockEntity signBlockEntity, MatrixStack matrixStack, int light, int overlay) {
|
||||
String url = PictureURLUtils.getLink(signBlockEntity);
|
||||
if (!url.startsWith("https://") && !url.startsWith("http://")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
if (!url.contains(".png") && !url.contains(".jpg") && !url.contains(".jpeg")) return;
|
||||
if (PictureSignConfig.safeMode && !url.startsWith("https://i.imgur.com/") && !url.startsWith("https://i.ibb.co/")
|
||||
&& !url.startsWith("https://pictshare.net/") && !url.startsWith("https://iili.io/"))
|
||||
return;
|
||||
//if (!url.contains(".png") && !url.contains(".jpg") && !url.contains(".jpeg")) return;
|
||||
//if (PictureSignConfig.safeMode && !url.startsWith("https://i.imgur.com/") && !url.startsWith("https://i.ibb.co/")
|
||||
// && !url.startsWith("https://pictshare.net/") && !url.startsWith("https://iili.io/"))
|
||||
// return;
|
||||
World world = signBlockEntity.getWorld();
|
||||
BlockPos pos = signBlockEntity.getPos();
|
||||
if (world != null && (world.getBlockState(pos.down()).getBlock().equals(Blocks.REDSTONE_TORCH) || world.getBlockState(pos.down()).getBlock().equals(Blocks.REDSTONE_WALL_TORCH))
|
||||
&& world.getBlockState(pos.down()).get(Properties.LIT).equals(false)) return;
|
||||
if (world != null && (world.getBlockState(pos.up()).getBlock().equals(Blocks.REDSTONE_TORCH) || world.getBlockState(pos.up()).getBlock().equals(Blocks.REDSTONE_WALL_TORCH))
|
||||
&& world.getBlockState(pos.up()).get(Properties.LIT).equals(false)) return;
|
||||
|
||||
if (world != null && ((world.getBlockState(pos.down()).getBlock().equals(Blocks.REDSTONE_TORCH) || world.getBlockState(pos.down()).getBlock().equals(Blocks.REDSTONE_WALL_TORCH))
|
||||
&& world.getBlockState(pos.down()).get(Properties.LIT).equals(false)
|
||||
|| (world.getBlockState(pos.up()).getBlock().equals(Blocks.REDSTONE_TORCH) || world.getBlockState(pos.up()).getBlock().equals(Blocks.REDSTONE_WALL_TORCH))
|
||||
&& world.getBlockState(pos.up()).get(Properties.LIT).equals(false)))
|
||||
{
|
||||
if (videoManager != null)
|
||||
videoManager.closePlayer(new Identifier("picturesign", pos.getX() + "." + pos.getY() + "." + pos.getZ()));
|
||||
playedOnce.remove(pos);
|
||||
return;
|
||||
}
|
||||
|
||||
String lastLine = signBlockEntity.getTextOnRow(3, false).getString();
|
||||
|
||||
@@ -56,10 +75,31 @@ public class PictureSignRenderer {
|
||||
catch (NumberFormatException ignored) {}
|
||||
|
||||
// Download the picture data
|
||||
PictureDownloader.PictureData data = PictureDownloader.getInstance().getPicture(url);
|
||||
if (data == null || data.identifier == null) {
|
||||
return;
|
||||
PictureDownloader.PictureData data = null;
|
||||
VideoPlayer videoPlayer = null;
|
||||
if (PictureSignType.isType(signBlockEntity, PictureSignType.PICTURE)) {
|
||||
data = PictureDownloader.getInstance().getPicture(url);
|
||||
if (data == null || data.identifier == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (PictureSignType.isType(signBlockEntity, PictureSignType.VIDEO) || PictureSignType.isType(signBlockEntity, PictureSignType.LOOPED_VIDEO)) {
|
||||
videoPlayer = videoManager.getOrCreate(new Identifier("picturesign", pos.getX() + "." + pos.getY() + "." + pos.getZ()));
|
||||
try {
|
||||
if (PictureSignType.isType(signBlockEntity, PictureSignType.LOOPED_VIDEO)) {
|
||||
if (!videoPlayer.getMediaInterface().hasMedia())
|
||||
videoPlayer.getMediaInterface().play(url);
|
||||
}
|
||||
else if (!videoPlayer.getMediaInterface().hasMedia() && !playedOnce.contains(pos))
|
||||
videoPlayer.getMediaInterface().play(url);
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
PictureSignClient.LOGGER.error(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else return;
|
||||
if (PictureSignType.isType(signBlockEntity, PictureSignType.VIDEO)) playedOnce.add(pos);
|
||||
|
||||
float xOffset = 0.0F;
|
||||
float zOffset = 0.0F;
|
||||
@@ -105,7 +145,20 @@ public class PictureSignRenderer {
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorTexLightmapShader);
|
||||
l = light;
|
||||
}
|
||||
RenderSystem.setShaderTexture(0, data.identifier);
|
||||
Identifier texture;
|
||||
if (PictureSignType.isType(signBlockEntity, PictureSignType.PICTURE)) {
|
||||
assert data != null;
|
||||
texture = data.identifier;
|
||||
}
|
||||
else if (PictureSignType.isType(signBlockEntity, PictureSignType.VIDEO) || PictureSignType.isType(signBlockEntity, PictureSignType.LOOPED_VIDEO)) {
|
||||
assert videoPlayer != null;
|
||||
TextureManager textureManager = MinecraftClient.getInstance().getTextureManager();
|
||||
if (videoPlayer.getTexture() != null && videoPlayer.getCodecInterface().getFrameRate() > 1 && textureManager.getTexture(videoPlayer.getTexture()) != null && textureManager.getTexture(videoPlayer.getTexture()).getGlId() != 0)
|
||||
texture = videoPlayer.getTexture();
|
||||
else texture = new Identifier("picturesign", "textures/black.png");
|
||||
}
|
||||
else return;
|
||||
RenderSystem.setShaderTexture(0, texture);
|
||||
|
||||
if (PictureSignConfig.translucency) RenderSystem.enableBlend();
|
||||
else RenderSystem.disableBlend();
|
||||
|
||||
@@ -43,37 +43,32 @@ public class PictureSignHelperScreen extends Screen {
|
||||
protected void init() {
|
||||
super.init();
|
||||
sign.setEditable(false);
|
||||
if (!sign.getTextOnRow(3,false).getString().matches("(.*\\d:.*\\d:.*\\d:.*\\d:.*\\d)")) sign.setTextOnRow(3, Text.of("1:1:0:0:0"));
|
||||
if (!sign.getTextOnRow(0, false).getString().startsWith("!PS:")) sign.setTextOnRow(0, Text.of("!PS:"));
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
if (!text[3].matches("(.*\\d:.*\\d:.*\\d:.*\\d:.*\\d)")) text[3] = "1:1:0:0:0";
|
||||
if (!text[0].startsWith("!PS:") && !text[0].startsWith("!VS:") && !text[0].startsWith("!LS:")) text[0] = "!PS:"+text[0];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sign.setTextOnRow(i, Text.of(text[i]));
|
||||
}
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 4 + 120, 200, 20, ScreenTexts.DONE, (button) -> {
|
||||
this.finishEditing();
|
||||
}));
|
||||
|
||||
if (PictureSignClient.clipboard != null && PictureSignClient.clipboard[0] != null)
|
||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width - 84, this.height - 40, 20, 20, 0, 0, 20, CLIPBOARD_ICON_TEXTURE, 32, 64, (buttonWidget) -> {
|
||||
sign.setTextOnRow(0, Text.of(PictureSignClient.clipboard[0]));
|
||||
sign.setTextOnRow(1, Text.of(PictureSignClient.clipboard[1]));
|
||||
sign.setTextOnRow(2, Text.of(PictureSignClient.clipboard[2]));
|
||||
sign.setTextOnRow(3, Text.of(PictureSignClient.clipboard[3]));
|
||||
text[0] = PictureSignClient.clipboard[0];
|
||||
text[1] = PictureSignClient.clipboard[1];
|
||||
text[2] = PictureSignClient.clipboard[2];
|
||||
text[3] = PictureSignClient.clipboard[3];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text[i] = PictureSignClient.clipboard[i];
|
||||
sign.setTextOnRow(i, Text.of(text[i]));
|
||||
}
|
||||
assert client != null;
|
||||
client.setScreen(this);
|
||||
}, Text.of("")));
|
||||
if (PictureSignConfig.helperUi)
|
||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width - 62, this.height - 40, 20, 20, 0, 0, 20, TRASHBIN_ICON_TEXTURE, 32, 64, (buttonWidget) -> {
|
||||
sign.setTextOnRow(0, Text.of(""));
|
||||
sign.setTextOnRow(1, Text.of(""));
|
||||
sign.setTextOnRow(2, Text.of(""));
|
||||
sign.setTextOnRow(3, Text.of(""));
|
||||
text[0] = "";
|
||||
text[1] = "";
|
||||
text[2] = "";
|
||||
text[3] = "";
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text[i] = "";
|
||||
sign.setTextOnRow(i, Text.empty());
|
||||
}
|
||||
assert client != null;
|
||||
client.setScreen(this);
|
||||
}, Text.of("")));
|
||||
@@ -81,27 +76,34 @@ public class PictureSignHelperScreen extends Screen {
|
||||
sign.setEditable(true);
|
||||
Objects.requireNonNull(client).setScreen(new SignEditScreen(this.sign,false));
|
||||
}, Text.of("")));
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2,this.height / 5 + 70,40,20, Text.of(text[0].startsWith("!PS:") ? "Image" : (text[0].startsWith("!VS:") ? "Video" : "Loop")), (buttonWidget) -> {
|
||||
if (text[0].startsWith("!PS")) text[0] = "!VS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
|
||||
else if (text[0].startsWith("!VS")) text[0] = "!LS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
|
||||
else if (text[0].startsWith("!LS")) text[0] = "!PS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
|
||||
else text[0] = "!PS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
|
||||
buttonWidget.setMessage(Text.of(text[0].startsWith("!PS:") ? "Image" : (text[0].startsWith("!VS:") ? "Video" : "Loop")));
|
||||
|
||||
sign.setTextOnRow(0, Text.of(text[0]));
|
||||
}));
|
||||
TextFieldWidget linkWidget = new TextFieldWidget(textRenderer,this.width / 2 - 175,this.height / 5 + 13,210,40, Text.of("url"));
|
||||
linkWidget.setMaxLength(90);
|
||||
linkWidget.setMaxLength(900);
|
||||
linkWidget.setText(PictureURLUtils.getLink(sign));
|
||||
linkWidget.setChangedListener(s -> {
|
||||
String[] lines = breakLink(PictureURLUtils.shortenLink(s));
|
||||
sign.setTextOnRow(0, Text.of(lines[0]));
|
||||
sign.setTextOnRow(1, Text.of(lines[1]));
|
||||
sign.setTextOnRow(2, Text.of(lines[2]));
|
||||
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
text[i] = lines[i];
|
||||
sign.setTextOnRow(i, Text.of(text[i]));
|
||||
}
|
||||
});
|
||||
this.addDrawableChild(linkWidget);
|
||||
String[] initialDimensions = sign.getTextOnRow(3, false).getString().split(":");
|
||||
String[] initialDimensions = text[3].split(":");
|
||||
TextFieldWidget widthWidget = new TextFieldWidget(textRenderer,this.width / 2 - 175,this.height / 5 + 70,30,20, Text.of("width"));
|
||||
widthWidget.setText(initialDimensions[0]);
|
||||
widthWidget.setChangedListener(s -> {
|
||||
String[] dimensions = new String[5];
|
||||
for (int i = 0; i < dimensions.length; ++i){
|
||||
if (sign.getTextOnRow(3, false).getString().split(":").length > i)
|
||||
dimensions[i] = sign.getTextOnRow(3, false).getString().split(":")[i];
|
||||
if (text[3].split(":").length > i)
|
||||
dimensions[i] = text[3].split(":")[i];
|
||||
}
|
||||
dimensions[0] = s;
|
||||
StringBuilder mergedDimensions = new StringBuilder();
|
||||
@@ -110,9 +112,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
mergedDimensions.append(dimensions[i]);
|
||||
if (i < 4)mergedDimensions.append(":");
|
||||
}
|
||||
sign.setTextOnRow(3, Text.of(String.valueOf(mergedDimensions)));
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
text[3] = String.valueOf(mergedDimensions);
|
||||
sign.setTextOnRow(3, Text.of(text[3]));
|
||||
});
|
||||
this.addDrawableChild(widthWidget);
|
||||
TextFieldWidget heightWidget = new TextFieldWidget(textRenderer,this.width / 2 - 140,this.height / 5 + 70,30,20, Text.of("height"));
|
||||
@@ -120,8 +121,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
heightWidget.setChangedListener(s -> {
|
||||
String[] dimensions = new String[5];
|
||||
for (int i = 0; i < dimensions.length; ++i){
|
||||
if (sign.getTextOnRow(3, false).getString().split(":").length > i)
|
||||
dimensions[i] = sign.getTextOnRow(3, false).getString().split(":")[i];
|
||||
if (text[3].split(":").length > i)
|
||||
dimensions[i] = text[3].split(":")[i];
|
||||
}
|
||||
dimensions[1] = s;
|
||||
StringBuilder mergedDimensions = new StringBuilder();
|
||||
@@ -130,9 +131,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
mergedDimensions.append(dimensions[i]);
|
||||
if (i < 4)mergedDimensions.append(":");
|
||||
}
|
||||
sign.setTextOnRow(3, Text.of(String.valueOf(mergedDimensions)));
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
text[3] = String.valueOf(mergedDimensions);
|
||||
sign.setTextOnRow(3, Text.of(text[3]));
|
||||
});
|
||||
this.addDrawableChild(heightWidget);
|
||||
TextFieldWidget posXWidget = new TextFieldWidget(textRenderer,this.width / 2 - 105,this.height / 5 + 70,30,20, Text.of("posX"));
|
||||
@@ -140,8 +140,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
posXWidget.setChangedListener(s -> {
|
||||
String[] dimensions = new String[5];
|
||||
for (int i = 0; i < dimensions.length; ++i){
|
||||
if (sign.getTextOnRow(3, false).getString().split(":").length > i)
|
||||
dimensions[i] = sign.getTextOnRow(3, false).getString().split(":")[i];
|
||||
if (text[3].split(":").length > i)
|
||||
dimensions[i] = text[3].split(":")[i];
|
||||
}
|
||||
dimensions[2] = s;
|
||||
StringBuilder mergedDimensions = new StringBuilder();
|
||||
@@ -150,9 +150,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
mergedDimensions.append(dimensions[i]);
|
||||
if (i < 4)mergedDimensions.append(":");
|
||||
}
|
||||
sign.setTextOnRow(3, Text.of(String.valueOf(mergedDimensions)));
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
text[3] = String.valueOf(mergedDimensions);
|
||||
sign.setTextOnRow(3, Text.of(text[3]));
|
||||
});
|
||||
this.addDrawableChild(posXWidget);
|
||||
TextFieldWidget posYWidget = new TextFieldWidget(textRenderer,this.width / 2 - 70,this.height / 5 + 70,30,20, Text.of("posY"));
|
||||
@@ -160,8 +159,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
posYWidget.setChangedListener(s -> {
|
||||
String[] dimensions = new String[5];
|
||||
for (int i = 0; i < dimensions.length; ++i){
|
||||
if (sign.getTextOnRow(3, false).getString().split(":").length > i)
|
||||
dimensions[i] = sign.getTextOnRow(3, false).getString().split(":")[i];
|
||||
if (text[3].split(":").length > i)
|
||||
dimensions[i] = text[3].split(":")[i];
|
||||
}
|
||||
dimensions[3] = s;
|
||||
StringBuilder mergedDimensions = new StringBuilder();
|
||||
@@ -170,9 +169,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
mergedDimensions.append(dimensions[i]);
|
||||
if (i < 4)mergedDimensions.append(":");
|
||||
}
|
||||
sign.setTextOnRow(3, Text.of(String.valueOf(mergedDimensions)));
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
text[3] = String.valueOf(mergedDimensions);
|
||||
sign.setTextOnRow(3, Text.of(text[3]));
|
||||
});
|
||||
this.addDrawableChild(posYWidget);
|
||||
TextFieldWidget posZWidget = new TextFieldWidget(textRenderer,this.width / 2 - 35,this.height / 5 + 70,30,20, Text.of("posZ"));
|
||||
@@ -180,8 +178,8 @@ public class PictureSignHelperScreen extends Screen {
|
||||
posZWidget.setChangedListener(s -> {
|
||||
String[] dimensions = new String[5];
|
||||
for (int i = 0; i < dimensions.length; ++i){
|
||||
if (sign.getTextOnRow(3, false).getString().split(":").length > i)
|
||||
dimensions[i] = sign.getTextOnRow(3, false).getString().split(":")[i];
|
||||
if (text[3].split(":").length > i)
|
||||
dimensions[i] = text[3].split(":")[i];
|
||||
}
|
||||
dimensions[4] = s;
|
||||
StringBuilder mergedDimensions = new StringBuilder();
|
||||
@@ -190,19 +188,20 @@ public class PictureSignHelperScreen extends Screen {
|
||||
mergedDimensions.append(dimensions[i]);
|
||||
if (i < 4)mergedDimensions.append(":");
|
||||
}
|
||||
sign.setTextOnRow(3, Text.of(String.valueOf(mergedDimensions)));
|
||||
text = IntStream.range(0, 4).mapToObj((row) ->
|
||||
sign.getTextOnRow(row, false)).map(Text::getString).toArray(String[]::new);
|
||||
text[3] = String.valueOf(mergedDimensions);
|
||||
sign.setTextOnRow(3, Text.of(text[3]));
|
||||
});
|
||||
this.addDrawableChild(posZWidget);
|
||||
this.model = SignBlockEntityRenderer.createSignModel(this.client.getEntityModelLoader(), SignBlockEntityRenderer.getSignType(sign.getCachedState().getBlock()));
|
||||
}
|
||||
public void removed() {
|
||||
ClientPlayNetworkHandler clientPlayNetworkHandler = this.client.getNetworkHandler();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
sign.setTextOnRow(i, Text.of(text[i]));
|
||||
}
|
||||
if (clientPlayNetworkHandler != null) {
|
||||
clientPlayNetworkHandler.sendPacket(new UpdateSignC2SPacket(this.sign.getPos(), this.text[0], this.text[1], this.text[2], this.text[3]));
|
||||
}
|
||||
this.sign.setEditable(true);
|
||||
}
|
||||
private String[] breakLink(String link) {
|
||||
Text linkText = Text.of("!PS:"+link);
|
||||
@@ -242,7 +241,6 @@ public class PictureSignHelperScreen extends Screen {
|
||||
}
|
||||
}
|
||||
private void finishEditing() {
|
||||
sign.setEditable(true);
|
||||
sign.markDirty();
|
||||
assert this.client != null;
|
||||
this.client.setScreen(null);
|
||||
@@ -254,8 +252,9 @@ public class PictureSignHelperScreen extends Screen {
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("Width"),this.width / 2 - 175, this.height / 5 + 60, -8816268);
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("Height"),this.width / 2 - 140, this.height / 5 + 60, -8816268);
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("PosX"),this.width / 2 - 105, this.height / 5 + 60, -8816268);
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("PosY"),this.width / 2 - 75, this.height / 5 + 60, -8816268);
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("PosY"),this.width / 2 - 70, this.height / 5 + 60, -8816268);
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("PosZ"),this.width / 2 - 35, this.height / 5 + 60, -8816268);
|
||||
drawTextWithShadow(matrices,textRenderer, Text.of("Mode"),this.width / 2, this.height / 5 + 60, -8816268);
|
||||
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 40, 16777215);
|
||||
matrices.push();
|
||||
matrices.translate(this.width / 2f + 100, this.height / 5f - 60, 50.0);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package eu.midnightdust.picturesign.util;
|
||||
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
|
||||
public enum PictureSignType {
|
||||
NONE, PICTURE, VIDEO, LOOPED_VIDEO;
|
||||
public static PictureSignType getType(SignBlockEntity signBlockEntity) {
|
||||
String rowOne = signBlockEntity.getTextOnRow(0,false).getString();
|
||||
if (rowOne.startsWith("!PS:")) return PICTURE;
|
||||
if (rowOne.startsWith("!VS:")) return VIDEO;
|
||||
if (rowOne.startsWith("!LS:")) return LOOPED_VIDEO;
|
||||
else return NONE;
|
||||
}
|
||||
public static boolean isType(SignBlockEntity signBlockEntity, PictureSignType type) {
|
||||
return getType(signBlockEntity) == type;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class PictureURLUtils {
|
||||
String text = signBlockEntity.getTextOnRow(0, false).getString() +
|
||||
signBlockEntity.getTextOnRow(1, false).getString() +
|
||||
signBlockEntity.getTextOnRow(2, false).getString();
|
||||
String url = text.replaceAll("!PS:", "").replaceAll(" ","");
|
||||
String url = text.replaceAll("!PS:", "").replaceAll("!VS:", "").replaceAll("!LS:", "").replaceAll(" ","");
|
||||
if (url.startsWith("ps:")) url = url.replace("ps:", "https://pictshare.net/");
|
||||
if (url.startsWith("imgur:")) url = url.replace("imgur:", "https://i.imgur.com/");
|
||||
if (url.startsWith("imgbb:")) url = url.replace("imgbb:", "https://i.ibb.co/");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"picturesign.midnightconfig.title":"PictureSign Config",
|
||||
|
||||
"picturesign.midnightconfig.enabled":"Enable Pictures",
|
||||
"picturesign.midnightconfig.enableVideoSigns":"Enable Videos",
|
||||
"picturesign.midnightconfig.translucency":"Enable Translucency",
|
||||
"picturesign.midnightconfig.translucency.tooltip":"Translucency doesn't work too great on block entities\n(and therefore signs)",
|
||||
"picturesign.midnightconfig.helperUi":"Enable Helper UI",
|
||||
|
||||
BIN
src/main/resources/assets/picturesign/textures/black.png
Normal file
BIN
src/main/resources/assets/picturesign/textures/black.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 104 B |
Reference in New Issue
Block a user