Skip to content

Commit d7c65f2

Browse files
committed
2.5
1 parent 83e3803 commit d7c65f2

File tree

11 files changed

+126
-59
lines changed

11 files changed

+126
-59
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dev.felnull.otyacraftengine.client.gui;
2+
3+
import com.mojang.blaze3d.vertex.PoseStack;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.gui.GuiComponent;
6+
import net.minecraft.network.chat.Component;
7+
8+
public interface IOEBaseGUI {
9+
Minecraft mc = Minecraft.getInstance();
10+
11+
default void drawTextBase(PoseStack poseStack, Component text, int x, int y, int color) {
12+
GuiComponent.drawString(poseStack, mc.font, text, x, y, color);
13+
}
14+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package dev.felnull.otyacraftengine.client.gui.components;
2+
3+
import com.mojang.blaze3d.systems.RenderSystem;
4+
import com.mojang.blaze3d.vertex.PoseStack;
5+
import dev.felnull.otyacraftengine.client.gui.TextureSpecifyLocation;
6+
import dev.felnull.otyacraftengine.client.gui.components.base.OEBaseWidget;
7+
import dev.felnull.otyacraftengine.client.util.OERenderUtil;
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.renderer.GameRenderer;
10+
import net.minecraft.network.chat.Component;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.function.Consumer;
14+
15+
public class IconButton extends OEBaseWidget {
16+
@NotNull
17+
private final Consumer<IconButton> onPress;
18+
@NotNull
19+
protected TextureSpecifyLocation iconTexture;
20+
21+
public IconButton(int x, int y, int width, int height, @NotNull Component message, @NotNull TextureSpecifyLocation iconTexture, @NotNull Consumer<IconButton> onPress) {
22+
super(x, y, width, height, "button", message);
23+
this.onPress = onPress;
24+
this.iconTexture = iconTexture;
25+
}
26+
27+
@Override
28+
public void onPress() {
29+
onPress.accept(this);
30+
}
31+
32+
public @NotNull TextureSpecifyLocation getIconTexture() {
33+
return iconTexture;
34+
}
35+
36+
public void setIconTexture(@NotNull TextureSpecifyLocation iconTexture) {
37+
this.iconTexture = iconTexture;
38+
}
39+
40+
@Override
41+
public void renderButton(@NotNull PoseStack poseStack, int i, int j, float f) {
42+
Minecraft minecraft = Minecraft.getInstance();
43+
RenderSystem.setShader(GameRenderer::getPositionTexShader);
44+
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
45+
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
46+
int k = this.getYImage(this.isHoveredOrFocused());
47+
RenderSystem.enableBlend();
48+
RenderSystem.defaultBlendFunc();
49+
RenderSystem.enableDepthTest();
50+
this.blit(poseStack, this.x, this.y, 0, 46 + k * 20, this.width / 2, this.height);
51+
this.blit(poseStack, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
52+
this.renderBg(poseStack, minecraft, i, j);
53+
renderIcon(poseStack, i, j, f);
54+
}
55+
56+
protected void renderIcon(@NotNull PoseStack poseStack, int i, int j, float f) {
57+
OERenderUtil.drawTexture(poseStack, x + (width - iconTexture.width()) / 2f, y + (height - iconTexture.height()) / 2f, iconTexture);
58+
}
59+
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
package dev.felnull.otyacraftengine.client.gui.components.base;
22

3-
import com.mojang.blaze3d.vertex.PoseStack;
43
import dev.felnull.otyacraftengine.OtyacraftEngine;
5-
import net.minecraft.client.Minecraft;
6-
import net.minecraft.client.gui.GuiComponent;
7-
import net.minecraft.network.chat.Component;
4+
import dev.felnull.otyacraftengine.client.gui.IOEBaseGUI;
85
import net.minecraft.resources.ResourceLocation;
96

10-
public interface IOEBaseComponent {
11-
Minecraft mc = Minecraft.getInstance();
7+
public interface IOEBaseComponent extends IOEBaseGUI {
128
ResourceLocation WIDGETS = new ResourceLocation(OtyacraftEngine.MODID, "textures/gui/widgets.png");
13-
14-
default void drawTextBase(PoseStack poseStack, Component text, int x, int y, int color) {
15-
GuiComponent.drawString(poseStack, mc.font, text, x, y, color);
16-
}
179
}

common/src/main/java/dev/felnull/otyacraftengine/client/gui/components/base/OEBaseWidget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public abstract class OEBaseWidget extends AbstractWidget implements IOEBaseComp
1414
@Nullable
1515
private final String widgetTypeName;
1616

17-
public OEBaseWidget(int x, int y, int width, int height, Component component) {
18-
this(x, y, width, height, null, component);
17+
public OEBaseWidget(int x, int y, int width, int height, @NotNull Component message) {
18+
this(x, y, width, height, null, message);
1919
}
2020

2121
public OEBaseWidget(int x, int y, int width, int height, @Nullable String widgetTypeName, @NotNull Component message) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package dev.felnull.otyacraftengine.client.gui.screen;
22

3-
import net.minecraft.client.gui.screens.Screen;
3+
import net.minecraft.client.gui.components.Button;
44
import net.minecraft.network.chat.TextComponent;
55

6-
public class DebugScreen extends Screen {
6+
public class DebugScreen extends OEBaseScreen {
77
public DebugScreen() {
88
super(new TextComponent("Debug Screen"));
99
}
1010

1111
@Override
1212
protected void init() {
1313
super.init();
14+
this.addRenderableWidget(new Button(0, 0, 100, 20, new TextComponent("Test Screen"), n -> mc.setScreen(new TestScreen(this))));
1415
}
1516
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package dev.felnull.otyacraftengine.client.gui.screen;
2+
3+
import dev.felnull.otyacraftengine.client.gui.IOEBaseGUI;
4+
5+
public interface IOEBaseScreen extends IOEBaseGUI {
6+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package dev.felnull.otyacraftengine.client.gui.screen;
2+
3+
import net.minecraft.client.gui.screens.Screen;
4+
import net.minecraft.network.chat.Component;
5+
import org.jetbrains.annotations.Nullable;
6+
7+
public abstract class OEBaseScreen extends Screen implements IOEBaseScreen {
8+
@Nullable
9+
private final Screen parentScreen;
10+
11+
protected OEBaseScreen(Component message, @Nullable Screen parent) {
12+
super(message);
13+
this.parentScreen = parent;
14+
}
15+
16+
protected OEBaseScreen(Component message) {
17+
this(message, null);
18+
}
19+
20+
public @Nullable Screen getParentScreen() {
21+
return parentScreen;
22+
}
23+
24+
@Override
25+
public void onClose() {
26+
mc.setScreen(parentScreen);
27+
}
28+
}

common/src/main/java/dev/felnull/otyacraftengine/client/gui/screen/OEContainerBaseScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import java.util.UUID;
1717

18-
public abstract class OEContainerBaseScreen<T extends OEBaseMenu> extends AbstractContainerScreen<T> implements IInstructionScreen {
18+
public abstract class OEContainerBaseScreen<T extends OEBaseMenu> extends AbstractContainerScreen<T> implements IInstructionScreen, IOEBaseScreen {
1919
protected static final Minecraft mc = Minecraft.getInstance();
2020
protected final UUID id = UUID.randomUUID();
2121
protected int bgTextureWidth = 256;
Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,35 @@
11
package dev.felnull.otyacraftengine.client.gui.screen;
22

33
import com.mojang.blaze3d.vertex.PoseStack;
4-
import dev.felnull.otyacraftengine.client.gui.components.RadioButton;
5-
import dev.felnull.otyacraftengine.client.util.OERenderUtil;
4+
import dev.felnull.otyacraftengine.client.gui.TextureSpecifyLocation;
5+
import dev.felnull.otyacraftengine.client.gui.components.IconButton;
6+
import dev.felnull.otyacraftengine.client.util.OETextureUtil;
67
import net.minecraft.client.gui.screens.Screen;
78
import net.minecraft.network.chat.TextComponent;
89
import org.jetbrains.annotations.NotNull;
910

10-
import java.io.InputStream;
1111
import java.util.UUID;
1212

13-
public class TestScreen extends Screen {
13+
public class TestScreen extends OEBaseScreen {
1414
private static final UUID id = UUID.randomUUID();
15-
private RadioButton rdo1;
16-
private RadioButton rdo2;
1715

18-
private InputStream stream;
19-
20-
public TestScreen() {
21-
super(new TextComponent("Test Screen"));
22-
try {
23-
// stream = new URL("https://cdn.discordapp.com/attachments/887769442019323924/887770177381478530/test.gif").openStream();// new FileInputStream("D:\\newpcdatas\\pictures\\汚物\\gabaana_dadhi.png");
24-
} catch (Exception e) {
25-
e.printStackTrace();
26-
}
16+
public TestScreen(Screen parent) {
17+
super(new TextComponent("Test Screen"), parent);
2718
}
2819

2920
@Override
3021
protected void init() {
3122
super.init();
32-
/*addRenderableWidget(new Button(0, 0, 10, 10, new TextComponent("TEST"), n -> {
33-
FNJLNativeWrapper.FileChooserFlagWrapper flagWrapper = new FNJLNativeWrapper.FileChooserFlagWrapper().fileMustExist(true).readOnly(true);
34-
File[] files = FNJLNativeWrapper.openNativeFileChooser("TEST", Paths.get("."), flagWrapper, new FNJLNativeWrapper.FileChooserFilterWrapper("All file"));
35-
if (files != null) {
36-
for (File file : files) {
37-
System.out.println(file.getAbsolutePath());
38-
}
39-
}
40-
}));*/
41-
/* rdo1 = this.addRenderableWidget(new RadioButton(0, 0, 20, 20, new TextComponent("TEST1"), false, true, () -> new RadioButton[]{rdo1, rdo2}, n -> {
23+
this.addRenderableWidget(new IconButton(0, 0, 20, 20, new TextComponent("TEST"), new TextureSpecifyLocation(OETextureUtil.getPlayerSkinTexture(UUID.fromString("0f286fc2-0c86-42d5-8518-c306cad74f03")), 0, 0, 10, 10, 10, 10), n -> {
4224

4325
}));
44-
rdo2 = this.addRenderableWidget(new RadioButton(0, 50, 20, 20, new TextComponent("TEST2"), false, true, () -> new RadioButton[]{rdo1, rdo2}, n -> {
45-
46-
}));*/
4726
}
4827

4928
@Override
5029
public void render(@NotNull PoseStack poseStack, int x, int y, float f) {
5130
this.renderBackground(poseStack);
5231
super.render(poseStack, x, y, f);
5332

54-
OERenderUtil.drawPlayerFace(poseStack, UUID.fromString("0f286fc2-0c86-42d5-8518-c306cad74f03"), 0, 0, height);
55-
56-
// OERenderUtil.drawTexture(OETextureUtil.getNativeTexture(id, stream), poseStack, x, y, 10, 10, 10, 10, 10, 10);
57-
// OERenderUtil.drawText(poseStack, OETextureUtil.getPlayerTexture(MinecraftProfileTexture.Type.SKIN,UUID.fromString("5c751dd1-0882-4f31-ad61-c4ee928c4595")), x, y, 0xFFFFFF);
58-
/* var tex = OETextureUtil.getURLTextureAsyncLoad("https://cdn.discordapp.com/attachments/887769442019323924/888494682492010519/gabaana_dadhi.png", true);
59-
var sc = OETextureUtil.getTextureScale(null);
60-
float w = 100;
61-
float h = 100;
62-
OERenderUtil.drawTexture(tex == null ? MissingTextureAtlasSprite.getLocation() : tex, poseStack, 0, 0, 0, 0, w, h, w, h);
63-
*/
64-
// float siz = Minecraft.getInstance().font.width("TESTTEST");
65-
// OERenderUtil.drawFixedWidthText(poseStack, "F.C.O.H", 10, 10, 0xFF000000, siz * ((float) (System.currentTimeMillis() % 5000) / 5000f));
66-
//ResourceLocation tex = OETextureUtil.getNativeTextureAsyncLoad(id, stream);//OETextureUtil.getURLTextureAsyncLoad("https://cdn.discordapp.com/attachments/887769442019323924/893111745927856128/broken.gif", true, MissingTextureAtlasSprite.getLocation()); //OETextureUtil.getPlayerSkinTexture(UUID.fromString("0f286fc2-0c86-42d5-8518-c306cad74f03"));
33+
// OERenderUtil.drawPlayerFace(poseStack, UUID.fromString("0f286fc2-0c86-42d5-8518-c306cad74f03"), 0, 0, height);
6734
}
6835
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ minecraft_version=1.18.2
55
#-------------------MOD Data--------------------#
66
archives_base_name=otyacraftengine
77
mod_display_name=OtyacraftEngine
8-
mod_version=2.4
8+
mod_version=2.5
99
#-----------------Library Version---------------#
1010
architectury_version=4.0.29
1111
fabric_loader_version=0.13.3

0 commit comments

Comments
 (0)