mirror of
https://github.com/TeamMidnightDust/PictureSign.git
synced 2025-12-13 12:55:09 +01:00
1.20.1 port
This will not receive any future updates
This commit is contained in:
@@ -23,6 +23,6 @@ public class PictureSignClient {
|
||||
PictureSignConfig.init(MOD_ID, PictureSignConfig.class);
|
||||
}
|
||||
public static Identifier id(String path) {
|
||||
return Identifier.of(MOD_ID, path);
|
||||
return new Identifier(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 switchScreen = false;
|
||||
@Unique private static boolean picturesign$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) -> {
|
||||
switchScreen = true;
|
||||
picturesign$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 (switchScreen) {
|
||||
switchScreen = false;
|
||||
if (picturesign$switchScreen) {
|
||||
picturesign$switchScreen = false;
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,15 +192,16 @@ public class PictureRenderer {
|
||||
matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(dimensions.zRot()));
|
||||
|
||||
Matrix4f matrix4f = matrixStack.peek().getPositionMatrix();
|
||||
BufferBuilder buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT);
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.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);
|
||||
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(), dimensions.height(), 1.0F).color(255, 255, 255, 255).texture(1.0F, 0.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, 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, dimensions.height(), 1.0F).color(255, 255, 255, 255).texture(0.0F, 0.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);
|
||||
buffer.vertex(matrix4f, 0.0F, 0.0F, 1.0F).color(255, 255, 255, 255).texture(0.0F, 1.0F).light(l).overlay(overlay).next();
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(buffer.end());
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ 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;
|
||||
@@ -385,7 +384,7 @@ public class PictureSignHelperScreen extends Screen {
|
||||
else {
|
||||
MatrixStack matrices = context.getMatrices();
|
||||
matrices.scale(4.5F, 4.5F, 1.0F);
|
||||
context.drawTexture(Identifier.ofVanilla("textures/gui/hanging_signs/" + this.signType.name() + ".png"), -8, -8, 0.0F, 0.0F, 16, 16, 16, 16);
|
||||
context.drawTexture(new Identifier("textures/gui/hanging_signs/" + this.signType.name() + ".png"), -8, -8, 0.0F, 0.0F, 16, 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class GIFHandler {
|
||||
}
|
||||
public int getTexture() {
|
||||
return player.getRenderer().texture(tick,
|
||||
(MathAPI.tickToMs(client.getRenderTickCounter().getTickDelta(true))), true);
|
||||
(MathAPI.tickToMs(client.getTickDelta())), true);
|
||||
}
|
||||
public boolean isWorking() {
|
||||
if (player != null && player.getException() != null) player.getException().fillInStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user