Skip to content

Commit

Permalink
Partially revert "Update to 1.20 (MeteorDevelopment#3708)"
Browse files Browse the repository at this point in the history
This partially reverts commit 531155c.
  • Loading branch information
Moondarker committed Feb 28, 2024
1 parent d946b0a commit dabcdff
Show file tree
Hide file tree
Showing 69 changed files with 648 additions and 501 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
package meteordevelopment.meteorclient.events.render;

import meteordevelopment.meteorclient.utils.Utils;
import net.minecraft.client.gui.DrawContext;

public class Render2DEvent {
private static final Render2DEvent INSTANCE = new Render2DEvent();

public DrawContext drawContext;
public int screenWidth, screenHeight;
public double frameTime;
public float tickDelta;

public static Render2DEvent get(DrawContext drawContext, int screenWidth, int screenHeight, float tickDelta) {
INSTANCE.drawContext = drawContext;
public static Render2DEvent get(int screenWidth, int screenHeight, float tickDelta) {
INSTANCE.screenWidth = screenWidth;
INSTANCE.screenHeight = screenHeight;
INSTANCE.frameTime = Utils.frameTime;
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/meteordevelopment/meteorclient/gui/WidgetScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import meteordevelopment.meteorclient.utils.misc.CursorStyle;
import meteordevelopment.meteorclient.utils.misc.input.Input;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -244,8 +243,8 @@ public boolean charTyped(char chr, int keyCode) {
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (!Utils.canUpdate()) renderBackground(context, mouseX, mouseY, delta);
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
if (!Utils.canUpdate()) renderBackground(matrices);

double s = mc.getWindow().getScaleFactor();
mouseX *= s;
Expand All @@ -259,22 +258,20 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
// Apply projection without scaling
Utils.unscaledProjection();

onRenderBefore(context, delta);
onRenderBefore(delta);

RENDERER.theme = theme;
theme.beforeRender();

RENDERER.begin(context);
RENDERER.begin(matrices);
RENDERER.setAlpha(animProgress);
root.render(RENDERER, mouseX, mouseY, delta / 20);
RENDERER.setAlpha(1);
RENDERER.end();
RENDERER.end(matrices);

boolean tooltip = RENDERER.renderTooltip(context, mouseX, mouseY, delta / 20);
boolean tooltip = RENDERER.renderTooltip(mouseX, mouseY, delta / 20, matrices);

if (debug) {
MatrixStack matrices = context.getMatrices();

DEBUG_RENDERER.render(root, matrices);
if (tooltip) DEBUG_RENDERER.render(RENDERER.tooltipWidget, matrices);
}
Expand All @@ -291,7 +288,7 @@ protected void runAfterRenderTasks() {
}
}

protected void onRenderBefore(DrawContext drawContext, float delta) {}
protected void onRenderBefore(float delta) {}

@Override
public void resize(MinecraftClient client, int width, int height) {
Expand Down Expand Up @@ -320,7 +317,10 @@ public void removed() {
Input.setCursorStyle(CursorStyle.Default);

loopWidgets(root, widget -> {
if (widget instanceof WTextBox textBox && textBox.isFocused()) textBox.setFocused(false);
if (widget instanceof WTextBox textBox) {

if (textBox.isFocused()) textBox.setFocused(false);
}
});

MeteorClient.EVENT_BUS.unsubscribe(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
import meteordevelopment.meteorclient.utils.misc.MeteorIdentifier;
import meteordevelopment.meteorclient.utils.misc.Pool;
import meteordevelopment.meteorclient.utils.render.ByteTexture;
import meteordevelopment.meteorclient.utils.render.RenderUtils;
import meteordevelopment.meteorclient.utils.render.color.Color;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;

Expand Down Expand Up @@ -60,7 +58,7 @@ public class GuiRenderer {
public WWidget tooltipWidget;
private double tooltipAnimProgress;

private DrawContext drawContext;
private MatrixStack matrices;

public static GuiTexture addTexture(Identifier id) {
return TEXTURE_PACKER.add(id);
Expand All @@ -78,15 +76,17 @@ public static void init() {
TEXTURE = TEXTURE_PACKER.pack();
}

public void begin(DrawContext drawContext) {
this.drawContext = drawContext;
public void begin(MatrixStack matrices) {
this.matrices = matrices;

GL.enableBlend();
GL.enableScissorTest();
scissorStart(0, 0, getWindowWidth(), getWindowHeight());
}

public void end() {
public void end(MatrixStack matrices) {
this.matrices = matrices;

scissorEnd();

for (Runnable task : postTasks) task.run();
Expand All @@ -104,24 +104,24 @@ public void endRender() {
r.end();
rTex.end();

r.render(drawContext.getMatrices());
r.render(matrices);

GL.bindTexture(TEXTURE.getGlId());
rTex.render(drawContext.getMatrices());
rTex.render(matrices);

// Normal text
theme.textRenderer().begin(theme.scale(1));
for (TextOperation text : texts) {
if (!text.title) text.run(textPool);
}
theme.textRenderer().end(drawContext.getMatrices());
theme.textRenderer().end(matrices);

// Title text
theme.textRenderer().begin(theme.scale(1.25));
for (TextOperation text : texts) {
if (text.title) text.run(textPool);
}
theme.textRenderer().end(drawContext.getMatrices());
theme.textRenderer().end(matrices);

texts.clear();
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public void scissorEnd() {
scissorPool.free(scissor);
}

public boolean renderTooltip(DrawContext drawContext, double mouseX, double mouseY, double delta) {
public boolean renderTooltip(double mouseX, double mouseY, double delta, MatrixStack matrices) {
tooltipAnimProgress += (tooltip != null ? 1 : -1) * delta * 14;
tooltipAnimProgress = MathHelper.clamp(tooltipAnimProgress, 0, 1);

Expand All @@ -171,9 +171,9 @@ public boolean renderTooltip(DrawContext drawContext, double mouseX, double mous

setAlpha(tooltipAnimProgress);

begin(drawContext);
begin(matrices);
tooltipWidget.render(this, mouseX, mouseY, delta);
end();
end(matrices);

setAlpha(1);

Expand Down Expand Up @@ -231,18 +231,14 @@ public void texture(double x, double y, double width, double height, double rota
rTex.end();

texture.bind();
rTex.render(drawContext.getMatrices());
rTex.render(matrices);
});
}

public void post(Runnable task) {
scissorStack.peek().postTasks.add(task);
}

public void item(ItemStack itemStack, int x, int y, float scale, boolean overlay) {
RenderUtils.drawItem(drawContext, itemStack, x, y, scale, overlay);
}

public void absolutePost(Runnable task) {
postTasks.add(task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import meteordevelopment.meteorclient.systems.hud.Hud;
import meteordevelopment.meteorclient.systems.hud.screens.HudEditorScreen;
import meteordevelopment.meteorclient.utils.misc.NbtUtils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.nbt.NbtCompound;

Expand Down Expand Up @@ -73,8 +72,8 @@ public void initWidgets() {
}

@Override
protected void onRenderBefore(DrawContext drawContext, float delta) {
HudEditorScreen.renderElements(drawContext);
protected void onRenderBefore(float delta) {
HudEditorScreen.renderElements();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
package meteordevelopment.meteorclient.gui.widgets;

import meteordevelopment.meteorclient.gui.renderer.GuiRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;

import static meteordevelopment.meteorclient.MeteorClient.mc;

public class WItem extends WWidget {
private static final MatrixStack MATRICES = new MatrixStack();

protected ItemStack itemStack;

public WItem(ItemStack itemStack) {
Expand All @@ -28,7 +33,15 @@ protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, doub
if (!itemStack.isEmpty()) {
renderer.post(() -> {
double s = theme.scale(2);
renderer.item(itemStack, (int) x, (int) y, (float) s, true);

MATRICES.push();
MATRICES.scale((float) s, (float) s, 1);
MATRICES.translate(x / s, y / s, 0);

mc.getItemRenderer().renderGuiItemIcon(MATRICES, itemStack, 0, 0);
mc.getItemRenderer().renderGuiItemOverlay(MATRICES, mc.textRenderer, itemStack, 0, 0);

MATRICES.pop();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private String getStringToAppend() {
StatusEffectInstance effect = effects.get(0);
if (effect.getAmplifier() > 0) str += effect.getAmplifier() + 1 + " ";

str += "(" + StatusEffectUtil.getDurationText(effect, 1).getString() + ")";
str += "(" + StatusEffectUtil.durationToString(effect, 1).getString() + ")";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import meteordevelopment.meteorclient.systems.modules.misc.BetterBeacons;
import net.minecraft.block.entity.BeaconBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.ingame.BeaconScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.BeaconScreenHandler;
Expand Down Expand Up @@ -57,9 +58,9 @@ private void changeButtons(CallbackInfo ci) {
}

@Inject(method = "drawBackground", at = @At("TAIL"))
private void onDrawBackground(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo ci) {
private void onDrawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY, CallbackInfo ci) {
if (!Modules.get().get(BetterBeacons.class).isActive()) return;
//this will clear the background from useless pyramid graphics
context.fill(x + 10, y + 7, x + 220, y + 98, 0xFF212121);
DrawableHelper.fill(matrices,this.x+10,this.y+7,this.x+220,this.y+98, 0xFF212121);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@Mixin(BlockCollisionSpliterator.class)
public class BlockCollisionSpliteratorMixin {
@Redirect(method = "computeNext", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"))
@Redirect(method = "computeNext()Lnet/minecraft/util/shape/VoxelShape;", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"))
private VoxelShape onComputeNextCollisionBox(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
VoxelShape shape = state.getCollisionShape(world, pos, context);

Expand Down
Loading

0 comments on commit dabcdff

Please sign in to comment.