1
0
forked from Clones/Controlify

Update to Minecraft 1.20

This commit is contained in:
isXander
2023-05-16 20:30:56 +01:00
parent d81b1f59cc
commit 0adbccc498
41 changed files with 259 additions and 491 deletions

View File

@ -6,7 +6,7 @@ import dev.isxander.controlify.bindings.JoystickAxisBind;
import dev.isxander.controlify.controller.joystick.JoystickState;
import dev.isxander.controlify.gui.DrawSize;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
@ -19,14 +19,15 @@ public abstract class GenericRenderer implements JoystickRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size) {
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size) {
if (annotation != null) {
minecraft.font.draw(
poseStack,
graphics.drawString(
minecraft.font,
annotation,
x + size + 2 - minecraft.font.width(annotation),
centerY + size/2f - minecraft.font.lineHeight * 0.75f,
-1
(int)(centerY + size/2f - minecraft.font.lineHeight * 0.75f),
-1,
false
);
}
@ -41,34 +42,31 @@ public abstract class GenericRenderer implements JoystickRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size) {
RenderSystem.setShaderTexture(0, BUTTON_TEXTURE);
RenderSystem.setShaderColor(1, 1, 1, 1);
poseStack.pushPose();
poseStack.translate(x, centerY, 0);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size) {
graphics.pose().pushPose();
graphics.pose().translate(x, centerY, 0);
float scale = (float) size / 22f;
poseStack.scale(scale, scale, 1);
poseStack.translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
graphics.pose().scale(scale, scale, 1);
graphics.pose().translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
GuiComponent.blit(poseStack, 0, 0, 0, 0, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE);
graphics.blit(BUTTON_TEXTURE, 0, 0, 0, 0, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE);
poseStack.popPose();
graphics.pose().popPose();
super.render(poseStack, x, centerY, size);
super.render(graphics, x, centerY, size);
return new DrawSize(size, size);
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size, boolean down) {
return this.render(poseStack, x, centerY, size);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size, boolean down) {
return this.render(graphics, x, centerY, size);
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, boolean down) {
return this.render(poseStack, x, centerY, DEFAULT_SIZE);
public DrawSize render(GuiGraphics graphics, int x, int centerY, boolean down) {
return this.render(graphics, x, centerY, DEFAULT_SIZE);
}
}
@ -80,28 +78,25 @@ public abstract class GenericRenderer implements JoystickRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size, JoystickAxisBind.AxisDirection direction) {
RenderSystem.setShaderTexture(0, AXIS_TEXTURE);
RenderSystem.setShaderColor(1, 1, 1, 1);
poseStack.pushPose();
poseStack.translate(x, centerY, 0);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size, JoystickAxisBind.AxisDirection direction) {
graphics.pose().pushPose();
graphics.pose().translate(x, centerY, 0);
float scale = (float) size / 22f;
poseStack.scale(scale, scale, 1);
poseStack.translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
graphics.pose().scale(scale, scale, 1);
graphics.pose().translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
GuiComponent.blit(
poseStack,
graphics.blit(
AXIS_TEXTURE,
0, 0,
direction.ordinal() * DEFAULT_SIZE, 0,
DEFAULT_SIZE, DEFAULT_SIZE,
DEFAULT_SIZE * JoystickAxisBind.AxisDirection.values().length, DEFAULT_SIZE
);
poseStack.popPose();
graphics.pose().popPose();
super.render(poseStack, x, centerY, size);
super.render(graphics, x, centerY, size);
return new DrawSize(size, size);
}
@ -115,28 +110,25 @@ public abstract class GenericRenderer implements JoystickRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size, JoystickState.HatState hatState) {
RenderSystem.setShaderTexture(0, HAT_TEXTURE);
RenderSystem.setShaderColor(1, 1, 1, 1);
poseStack.pushPose();
poseStack.translate(x, centerY, 0);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size, JoystickState.HatState hatState) {
graphics.pose().pushPose();
graphics.pose().translate(x, centerY, 0);
float scale = (float) size / 22f;
poseStack.scale(scale, scale, 1);
poseStack.translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
graphics.pose().scale(scale, scale, 1);
graphics.pose().translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
GuiComponent.blit(
poseStack,
graphics.blit(
HAT_TEXTURE,
0, 0,
hatState.ordinal() * DEFAULT_SIZE, 0,
DEFAULT_SIZE, DEFAULT_SIZE,
DEFAULT_SIZE * JoystickState.HatState.values().length, DEFAULT_SIZE
);
poseStack.popPose();
graphics.pose().popPose();
super.render(poseStack, x, centerY, size);
super.render(graphics, x, centerY, size);
return new DrawSize(size, size);
}

View File

@ -4,45 +4,46 @@ import com.mojang.blaze3d.vertex.PoseStack;
import dev.isxander.controlify.bindings.JoystickAxisBind;
import dev.isxander.controlify.controller.joystick.JoystickState;
import dev.isxander.controlify.gui.DrawSize;
import net.minecraft.client.gui.GuiGraphics;
public interface JoystickRenderer {
int DEFAULT_SIZE = 22;
DrawSize render(PoseStack poseStack, int x, int centerY, int size);
DrawSize render(GuiGraphics graphics, int x, int centerY, int size);
interface Button extends JoystickRenderer {
DrawSize render(PoseStack poseStack, int x, int centerY, int size, boolean down);
DrawSize render(GuiGraphics graphics, int x, int centerY, int size, boolean down);
default DrawSize render(PoseStack poseStack, int x, int centerY, boolean down) {
return render(poseStack, x, centerY, DEFAULT_SIZE, down);
default DrawSize render(GuiGraphics graphics, int x, int centerY, boolean down) {
return render(graphics, x, centerY, DEFAULT_SIZE, down);
}
default DrawSize render(PoseStack poseStack, int x, int centerY, int size) {
return render(poseStack, x, centerY, size, false);
default DrawSize render(GuiGraphics graphics, int x, int centerY, int size) {
return render(graphics, x, centerY, size, false);
}
}
interface Axis extends JoystickRenderer {
DrawSize render(PoseStack poseStack, int x, int centerY, int size, JoystickAxisBind.AxisDirection direction);
DrawSize render(GuiGraphics graphics, int x, int centerY, int size, JoystickAxisBind.AxisDirection direction);
default DrawSize render(PoseStack poseStack, int x, int centerY, JoystickAxisBind.AxisDirection direction) {
return render(poseStack, x, centerY, DEFAULT_SIZE, direction);
default DrawSize render(GuiGraphics graphics, int x, int centerY, JoystickAxisBind.AxisDirection direction) {
return render(graphics, x, centerY, DEFAULT_SIZE, direction);
}
default DrawSize render(PoseStack poseStack, int x, int centerY, int size) {
return render(poseStack, x, centerY, size, JoystickAxisBind.AxisDirection.POSITIVE);
default DrawSize render(GuiGraphics graphics, int x, int centerY, int size) {
return render(graphics, x, centerY, size, JoystickAxisBind.AxisDirection.POSITIVE);
}
}
interface Hat extends JoystickRenderer {
DrawSize render(PoseStack poseStack, int x, int centerY, int size, JoystickState.HatState state);
DrawSize render(GuiGraphics graphics, int x, int centerY, int size, JoystickState.HatState state);
default DrawSize render(PoseStack poseStack, int x, int centerY, JoystickState.HatState state) {
return render(poseStack, x, centerY, DEFAULT_SIZE, state);
default DrawSize render(GuiGraphics graphics, int x, int centerY, JoystickState.HatState state) {
return render(graphics, x, centerY, DEFAULT_SIZE, state);
}
default DrawSize render(PoseStack poseStack, int x, int centerY, int size) {
return render(poseStack, x, centerY, size, JoystickState.HatState.CENTERED);
default DrawSize render(GuiGraphics graphics, int x, int centerY, int size) {
return render(graphics, x, centerY, size, JoystickState.HatState.CENTERED);
}
}
}

View File

@ -1,13 +1,10 @@
package dev.isxander.controlify.controller.joystick.render;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.isxander.controlify.bindings.JoystickAxisBind;
import dev.isxander.controlify.controller.joystick.JoystickState;
import dev.isxander.controlify.gui.DrawSize;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
public abstract class ThemedRenderer {
@ -27,20 +24,17 @@ public abstract class ThemedRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size, boolean down) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShaderColor(1, 1, 1, 1);
poseStack.pushPose();
poseStack.translate(x, centerY, 0);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size, boolean down) {
graphics.pose().pushPose();
graphics.pose().translate(x, centerY, 0);
float scale = (float) size / 22f;
poseStack.scale(scale, scale, 1);
poseStack.translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
graphics.pose().scale(scale, scale, 1);
graphics.pose().translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
GuiComponent.blit(poseStack, 0, 0, 0, 0, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE);
graphics.blit(texture, 0, 0, 0, 0, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE);
poseStack.popPose();
graphics.pose().popPose();
return new DrawSize(size, size);
}
@ -55,26 +49,23 @@ public abstract class ThemedRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size, JoystickAxisBind.AxisDirection direction) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShaderColor(1, 1, 1, 1);
poseStack.pushPose();
poseStack.translate(x, centerY, 0);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size, JoystickAxisBind.AxisDirection direction) {
graphics.pose().pushPose();
graphics.pose().translate(x, centerY, 0);
float scale = (float) size / 22f;
poseStack.scale(scale, scale, 1);
poseStack.translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
graphics.pose().scale(scale, scale, 1);
graphics.pose().translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
GuiComponent.blit(
poseStack,
graphics.blit(
texture,
0, 0,
direction.ordinal() * DEFAULT_SIZE, 0,
DEFAULT_SIZE, DEFAULT_SIZE,
DEFAULT_SIZE * JoystickAxisBind.AxisDirection.values().length, DEFAULT_SIZE
);
poseStack.popPose();
graphics.pose().popPose();
return new DrawSize(size, size);
}
@ -89,26 +80,23 @@ public abstract class ThemedRenderer {
}
@Override
public DrawSize render(PoseStack poseStack, int x, int centerY, int size, JoystickState.HatState hatState) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShaderColor(1, 1, 1, 1);
poseStack.pushPose();
poseStack.translate(x, centerY, 0);
public DrawSize render(GuiGraphics graphics, int x, int centerY, int size, JoystickState.HatState hatState) {
graphics.pose().pushPose();
graphics.pose().translate(x, centerY, 0);
float scale = (float) size / 22f;
poseStack.scale(scale, scale, 1);
poseStack.translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
graphics.pose().scale(scale, scale, 1);
graphics.pose().translate(0f, -DEFAULT_SIZE / scale / 2f, 0);
GuiComponent.blit(
poseStack,
graphics.blit(
texture,
0, 0,
hatState.ordinal() * DEFAULT_SIZE, 0,
DEFAULT_SIZE, DEFAULT_SIZE,
DEFAULT_SIZE * JoystickState.HatState.values().length, DEFAULT_SIZE
);
poseStack.popPose();
graphics.pose().popPose();
return new DrawSize(size, size);
}