personthecat.catlib.client.gui.LibMenu Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of catlib-quilt Show documentation
Show all versions of catlib-quilt Show documentation
Utilities for serialization, commands, noise generation, IO, and some new data types.
The newest version!
package personthecat.catlib.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.class_1041;
import net.minecraft.class_2561;
import net.minecraft.class_287;
import net.minecraft.class_289;
import net.minecraft.class_290;
import net.minecraft.class_293;
import net.minecraft.class_310;
import net.minecraft.class_327;
import net.minecraft.class_332;
import net.minecraft.class_4185;
import net.minecraft.class_437;
import net.minecraft.class_4587;
import net.minecraft.class_5244;
import net.minecraft.class_757;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class LibMenu extends class_437 {
protected static final float G = 32.0F;
protected static final int Y0 = 35;
protected static final int Y1 = 50;
@Nullable protected class_437 parent;
protected class_327 field_22793;
protected class_4185 previous;
protected class_4185 cancel;
protected class_4185 next;
protected LibMenu(@Nullable class_437 parent, class_2561 title) {
super(title);
this.field_22793 = class_310.method_1551().field_1772;
this.parent = parent;
}
@Override
protected void method_25426() {
this.method_37067();
this.method_25396().clear();
this.previous = new class_4185(this.field_22789 / 2 - 60 - 120 - 10, this.field_22790 - 35, 120, 20,
class_5244.field_24339, b -> this.onPrevious());
this.cancel = new class_4185(this.field_22789 / 2 - 60, this.field_22790 - 35, 120, 20,
class_5244.field_24335, b -> this.method_25419());
this.next = new class_4185(this.field_22789 / 2 - 60 + 120 + 10, this.field_22790 - 35, 120, 20,
class_5244.field_24338, b -> this.onNext());
this.method_37063(this.previous);
this.method_37063(this.cancel);
this.method_37063(this.next);
}
public LibMenu loadImmediately() {
final class_310 minecraft = class_310.method_1551();
final class_1041 window = minecraft.method_22683();
this.method_25423(minecraft, window.method_4486(), window.method_4502());
return this;
}
boolean menu = true;
@Override
public void method_25394(@NotNull class_4587 stack, int x, int y, float partial) {
this.method_25420(stack);
final class_289 tx = class_289.method_1348();
final class_287 builder = tx.method_1349();
RenderSystem.setShader(class_757::method_34543);
this.renderBackground(tx, builder);
if (menu) {
this.renderMenu(stack, x, y, partial);
}
this.renderTopAndBottom(tx, builder);
this.renderDetails(stack, x, y, partial);
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
boolean bgConfig = true, bg = true;
protected void renderBackground(class_289 tx, class_287 builder) {
if (bgConfig) {
RenderSystem.setShaderTexture(0, class_332.field_22735);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
if (bg) {
builder.method_1328(class_293.class_5596.field_27382, class_290.field_1575);
builder.method_22912(0.0, this.field_22790 - Y1, 0.0D).method_22913(0.0F, (this.field_22790 - Y1) / G).method_1336(32, 32, 32, 255).method_1344();
builder.method_22912(this.field_22789, this.field_22790 - Y1, 0.0D).method_22913((float) this.field_22789 / G, (float) (this.field_22790 - Y1) / G).method_1336(32, 32, 32, 255).method_1344();
builder.method_22912(this.field_22789, Y0, 0.0D).method_22913(this.field_22789 / G, (float) Y0 / G).method_1336(32, 32, 32, 255).method_1344();
builder.method_22912(0.0, Y0, 0.0D).method_22913(0.0F, Y0 / G).method_1336(32, 32, 32, 255).method_1344();
tx.method_1350();
}
}
protected void renderMenu(class_4587 stack, int x, int y, float partial) {}
boolean topConfig = true,
top = true,
bottomConfig = true,
bottom = true,
forceBlack = true;
protected void renderTopAndBottom(class_289 tx, class_287 builder) {
if (topConfig) {
RenderSystem.setShader(class_757::method_34543);
RenderSystem.setShaderTexture(0, class_332.field_22735);
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(519); // GL_ALWAYS
}
if (top) { // top and bottom
builder.method_1328(class_293.class_5596.field_27382, class_290.field_1575);
builder.method_22912(0.0, Y0, -100.0D).method_22913(0.0F, Y0 / G).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(this.field_22789, Y0, -100.0D).method_22913((float)this.field_22789 / G, Y0 / G).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(this.field_22789, 0.0D, -100.0D).method_22913((float)this.field_22789 / G, 0.0F).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(0.0, 0.0D, -100.0D).method_22913(0.0F, 0.0F).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(0.0, this.field_22790, -100.0D).method_22913(0.0F, (float)this.field_22790 / G).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(this.field_22789, this.field_22790, -100.0D).method_22913((float)this.field_22789 / G, (float)this.field_22790 / G).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(this.field_22789, this.field_22790 - Y1, -100.0D).method_22913((float)this.field_22789 / G, (this.field_22790 - Y1) / G).method_1336(64, 64, 64, 255).method_1344();
builder.method_22912(0.0, this.field_22790 - Y1, -100.0D).method_22913(0.0F, (this.field_22790 - Y1) / G).method_1336(64, 64, 64, 255).method_1344();
tx.method_1350();
}
if (bottomConfig) {
RenderSystem.depthFunc(515); // GL_EQUAL
RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.class_4535.SRC_ALPHA, GlStateManager.class_4534.ONE_MINUS_SRC_ALPHA, GlStateManager.class_4535.ZERO, GlStateManager.class_4534.ONE);
RenderSystem.disableTexture();
RenderSystem.setShader(class_757::method_34540);
}
if (forceBlack) {
RenderSystem.setShaderColor(0, 0, 0, 1);
}
if (bottom) { // shadows
builder.method_1328(class_293.class_5596.field_27382, class_290.field_1576);
builder.method_22912(0.0, Y0 + 4, 0.0D).method_22913(0.0F, 1.0F).method_1336(0, 0, 0, 0).method_1344();
builder.method_22912(this.field_22789, Y0 + 4, 0.0D).method_22913(1.0F, 1.0F).method_1336(0, 0, 0, 0).method_1344();
builder.method_22912(this.field_22789, Y0, 0.0D).method_22913(1.0F, 0.0F).method_1336(0, 0, 0, 255).method_1344();
builder.method_22912(0.0, Y0, 0.0D).method_22913(0.0F, 0.0F).method_1336(0, 0, 0, 255).method_1344();
builder.method_22912(0.0, this.field_22790 - Y1, 0.0D).method_22913(0.0F, 1.0F).method_1336(0, 0, 0, 255).method_1344();
builder.method_22912(this.field_22789, this.field_22790 - Y1, 0.0D).method_22913(1.0F, 1.0F).method_1336(0, 0, 0, 255).method_1344();
builder.method_22912(this.field_22789, this.field_22790 - Y1 - 4, 0.0D).method_22913(1.0F, 0.0F).method_1336(0, 0, 0, 0).method_1344();
builder.method_22912(0.0, this.field_22790 - Y1 - 4, 0.0D).method_22913(0.0F, 0.0F).method_1336(0, 0, 0, 0).method_1344();
tx.method_1350();
}
}
protected void renderDetails(class_4587 stack, int x, int y, float partial) {
method_27534(stack, this.field_22793, this.field_22785, this.field_22789 / 2, 20, 16777215);
super.method_25394(stack, x, y, partial);
}
@Override
public void method_25424(@NotNull class_4587 stack, @NotNull class_2561 tooltip, int x, int y) {
this.method_25417(stack, this.field_22793.method_1728(tooltip,this.field_22789 / 2), x, y);
}
@Override
public void method_25419() {
class_310.method_1551().method_1507(this.parent);
}
protected void onPrevious() {}
protected void onNext() {}
}