Skip to content

Commit

Permalink
PictureSign 1.4.0 - Assisting UI and Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Motschen committed May 27, 2022
1 parent 69cf564 commit faaff87
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 18 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/use
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.61
loader_version=0.11.7
loader_version=0.14.6

# Mod Properties
mod_version = 1.3.0
mod_version = 1.4.0
maven_group = eu.midnightdust
archives_base_name = picturesign

Expand Down
59 changes: 59 additions & 0 deletions src/main/java/eu/midnightdust/picturesign/PictureSignClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,72 @@

import eu.midnightdust.picturesign.config.PictureSignConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.client.gui.screen.ingame.SignEditScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

public class PictureSignClient implements ClientModInitializer {
public static Logger LOGGER = LogManager.getLogger("PictureSign");
public static String[] clipboard = new String[4];
public static final KeyBinding BINDING_EDIT_SIGN = new KeyBinding("key.picturesign.edit_sign",
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, "key.categories.picturesign");
public static final KeyBinding BINDING_COPY_SIGN = new KeyBinding("key.picturesign.copy_sign",
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_U, "key.categories.picturesign");
@Override
public void onInitializeClient() {
PictureSignConfig.init("picturesign", PictureSignConfig.class);

KeyBindingHelper.registerKeyBinding(BINDING_COPY_SIGN);

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!PictureSignClient.BINDING_COPY_SIGN.isPressed()) return;
PictureSignClient.BINDING_COPY_SIGN.setPressed(false);
if (client.player == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK) return;
if (client.crosshairTarget.getType() == HitResult.Type.BLOCK && client.world.getBlockState(new BlockPos(client.crosshairTarget.getPos())).hasBlockEntity()) {
if (client.world.getBlockEntity(new BlockPos(client.crosshairTarget.getPos())) instanceof SignBlockEntity) {
SignBlockEntity sign = (SignBlockEntity) client.world.getBlockEntity(new BlockPos(client.crosshairTarget.getPos()));
clipboard[0] = sign.getTextOnRow(0, false).asString();
clipboard[1] = sign.getTextOnRow(1, false).asString();
clipboard[2] = sign.getTextOnRow(2, false).asString();
clipboard[3] = sign.getTextOnRow(3, false).asString();
}
}
});
if (PictureSignConfig.debug) {
KeyBindingHelper.registerKeyBinding(BINDING_EDIT_SIGN);
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!PictureSignClient.BINDING_EDIT_SIGN.isPressed()) return;
PictureSignClient.BINDING_EDIT_SIGN.setPressed(false);
if (client.player == null || client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK) return;
if (client.crosshairTarget.getType() == HitResult.Type.BLOCK && client.world.getBlockState(new BlockPos(client.crosshairTarget.getPos())).hasBlockEntity()) {
if (client.world.getBlockEntity(new BlockPos(client.crosshairTarget.getPos())) instanceof SignBlockEntity) {
BlockPos pos = new BlockPos(client.crosshairTarget.getPos());
SignBlockEntity sign = (SignBlockEntity) client.world.getBlockEntity(pos);
sign.setEditable(true);
sign.setEditor(client.player.getUuid());
sign.toUpdatePacket();
sign.markDirty();
client.world.updateListeners(pos, sign.getCachedState(), sign.getCachedState(), 3);
client.setScreen(new SignEditScreen(sign,false));
// clipboard[0] = sign.getTextOnRow(0, false).asString();
// clipboard[1] = sign.getTextOnRow(1, false).asString();
// clipboard[2] = sign.getTextOnRow(2, false).asString();
// clipboard[3] = sign.getTextOnRow(3, false).asString();
// Block signBlock = sign.getCachedState().getBlock();
// client.interactionManager.breakBlock(pos);
// client.player.setStackInHand(client.player.preferredHand, new ItemStack(signBlock.asItem()));
// client.interactionManager.interactBlock(client.player, client.world, client.player.preferredHand, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), Direction.DOWN, pos,false));
}
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

public class PictureSignConfig extends MidnightConfig {
@Entry public static boolean enabled = true;
@Entry public static boolean translucency = false;
@Entry public static boolean helperUi = true;
@Entry public static boolean exceedVanillaLineLength = false;
@Entry public static boolean debug = false;
@Entry(min = 1, max = 10) public static int maxThreads = 4;
@Entry(min = 0, max = 4096) public static int signRenderDistance = 64;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package eu.midnightdust.picturesign.mixin;

import eu.midnightdust.lib.util.screen.TexturedOverlayButtonWidget;
import eu.midnightdust.picturesign.PictureSignClient;
import eu.midnightdust.picturesign.config.PictureSignConfig;
import eu.midnightdust.picturesign.screen.PictureSignHelperScreen;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.SignEditScreen;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

@Mixin(SignEditScreen.class)
public abstract class MixinSignEditScreen extends Screen {
private static final Identifier PICTURESIGN_ICON_TEXTURE = new Identifier("picturesign","textures/gui/picturesign_button.png");
private static final Identifier CLIPBOARD_ICON_TEXTURE = new Identifier("picturesign","textures/gui/clipboard_button.png");
private static final Identifier TRASHBIN_ICON_TEXTURE = new Identifier("picturesign","textures/gui/trashbin_button.png");
@Shadow @Final private SignBlockEntity sign;

@Shadow @Final private String[] text;

protected MixinSignEditScreen(Text title) {
super(title);
}

@Inject(at = @At("TAIL"),method = "init")
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];
}, 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] = "";
}, 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) -> {
sign.setEditable(true);
Objects.requireNonNull(client).setScreen(new PictureSignHelperScreen(this.sign,false));
}, Text.of("")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import eu.midnightdust.picturesign.PictureDownloader;
import eu.midnightdust.picturesign.config.PictureSignConfig;
import eu.midnightdust.picturesign.util.PictureURLUtils;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.block.Blocks;
Expand All @@ -19,21 +20,20 @@
public class PictureSignRenderer {

public void render(SignBlockEntity signBlockEntity, MatrixStack matrixStack, int light, int overlay) {
String text = signBlockEntity.getTextOnRow(0, false).getString() +
signBlockEntity.getTextOnRow(1, false).getString() +
signBlockEntity.getTextOnRow(2, false).getString();
String url = text.replaceAll("!PS:", "").replaceAll(" ","");
if (url.contains("imgur:")) url = url.replace("imgur:", "https://i.imgur.com/");
if (url.contains("imgbb:")) url = url.replace("imgbb:", "https://i.ibb.co/");
if (!url.contains("https://") && !url.contains("http://")) {
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.contains("//i.imgur.com/") && !url.contains("//i.ibb.co/")) 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)) 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;


String lastLine = signBlockEntity.getTextOnRow(3, false).getString();
Expand Down Expand Up @@ -107,7 +107,8 @@ else if (signBlockEntity.getCachedState().contains(Properties.ROTATION)) {
}
RenderSystem.setShaderTexture(0, data.identifier);

RenderSystem.enableBlend();
if (PictureSignConfig.translucency) RenderSystem.enableBlend();
else RenderSystem.disableBlend();
RenderSystem.enableDepthTest();
RenderSystem.depthMask(true);

Expand Down
Loading

0 comments on commit faaff87

Please sign in to comment.