Better scaling

This commit is contained in:
kirillsaint 2023-07-07 17:00:26 +06:00
parent 104454503e
commit 86195e8791
8 changed files with 147 additions and 42 deletions

View File

@ -5,6 +5,7 @@ import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.entity.layers.LayerRenderer; import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.item.ItemStack;
import net.silentclient.client.Client; import net.silentclient.client.Client;
import net.silentclient.client.blc.BlcGlStateManager; import net.silentclient.client.blc.BlcGlStateManager;
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt; import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
@ -43,7 +44,8 @@ public class AbstractShieldRenderer extends ModelBase implements LayerRenderer<A
if (playerRenderer.getMainModel().bipedLeftArm.rotateAngleX != 0.0F) { if (playerRenderer.getMainModel().bipedLeftArm.rotateAngleX != 0.0F) {
GlStateManager.rotate(playerRenderer.getMainModel().bipedLeftArm.rotateAngleX * (180F / (float) Math.PI), 1.0F, 0.0F, 0.0F); GlStateManager.rotate(playerRenderer.getMainModel().bipedLeftArm.rotateAngleX * (180F / (float) Math.PI), 1.0F, 0.0F, 0.0F);
} }
applyArmTransformations(((AbstractClientPlayerExt) entity).silent$getShield().getModel(), entity.isSneaking(), entity.getSkinType().equals("slim")); ItemStack chestplate = entity.getCurrentArmor(2);
applyArmTransformations(((AbstractClientPlayerExt) entity).silent$getShield().getModel(), entity.isSneaking(), entity.getSkinType().equals("slim"), chestplate != null);
double d = getShieldScale(((AbstractClientPlayerExt) entity).silent$getShield().getModel()); double d = getShieldScale(((AbstractClientPlayerExt) entity).silent$getShield().getModel());
BlcGlStateManager.a(d, d, d); BlcGlStateManager.a(d, d, d);
BlcGlStateManager.k(); BlcGlStateManager.k();
@ -61,37 +63,49 @@ public class AbstractShieldRenderer extends ModelBase implements LayerRenderer<A
public double getShieldScale(String model) { public double getShieldScale(String model) {
if(model.equals("roundshield") || model.equals("hexagon_shield") || model.equals("shield_dollar")) { if(model.equals("roundshield") || model.equals("hexagon_shield") || model.equals("shield_dollar")) {
return 0.125; return 0.100;
} }
return 0.009; return 0.007;
} }
private void applyArmTransformations(String model, boolean paramBoolean1, boolean paramBoolean2) { private void applyArmTransformations(String model, boolean paramBoolean1, boolean paramBoolean2, boolean chestplate) {
switch(model) { switch(model) {
case "shield": case "shield":
GlStateManager.translate(0.33, 0.2, 0); GlStateManager.translate(0.33, 0.45, 0.38);
BlcGlStateManager.b(180.0f, 0.0f, 1.0f, 1.0f); BlcGlStateManager.b(180.0f, 0.0f, 1.0f, 1.0f);
BlcGlStateManager.b(-180.0f, 1.0f, 0.0f, 0.0f); BlcGlStateManager.b(-90.0f, 1.0f, 0.0f, 0.0f);
BlcGlStateManager.b(-90.0f, 0.0f, 1.0f, 0.0f); BlcGlStateManager.b(-90.0f, 0.0f, 1.0f, 0.0f);
BlcGlStateManager.b(paramBoolean1 ? -0.5799999833106995 : -0.4000000059604645, paramBoolean1 ? -0.42 : -0.5, paramBoolean2 ? 0.13700000524520874 : 0.2); BlcGlStateManager.b(paramBoolean1 ? -0.5799999833106995 : -0.4000000059604645, paramBoolean1 ? -0.42 : -0.5, paramBoolean2 ? 0.13700000524520874 : 0.2);
if(chestplate) {
GlStateManager.translate(0, 0, 0.055 + (paramBoolean2 ? 0.055 : 0));
}
break; break;
case "roundshield": case "roundshield":
GlStateManager.translate(0.33, 0.2, 0); GlStateManager.translate(0.33, 0.35, 0);
BlcGlStateManager.b(-90.0F, 0.0F, 1.0F, 0.0F); BlcGlStateManager.b(-90.0F, 0.0F, 1.0F, 0.0F);
BlcGlStateManager.b(paramBoolean1 ? -0.10000000149011612D : 0.0D, paramBoolean1 ? 0.45D : 0.25D, paramBoolean2 ? -0.1399999964237213D : -0.2D); BlcGlStateManager.b(paramBoolean1 ? -0.10000000149011612D : 0.0D, paramBoolean1 ? 0.45D : 0.25D, paramBoolean2 ? -0.1399999964237213D : -0.2D);
BlcGlStateManager.b(180.0F, 0.0F, 0.0F, 1.0F); BlcGlStateManager.b(180.0F, 0.0F, 0.0F, 1.0F);
if(chestplate) {
GlStateManager.translate(0, 0, -0.06 + (paramBoolean2 ? -0.055 : 0));
}
break; break;
case "hexagon_shield": case "hexagon_shield":
GlStateManager.translate(0.75F, 0.2, 0); GlStateManager.translate(0.75F, 0.35, 0);
BlcGlStateManager.b(90.0F, 0.0F, 1.0F, 0.0F); BlcGlStateManager.b(90.0F, 0.0F, 1.0F, 0.0F);
BlcGlStateManager.b(paramBoolean1 ? 0.2 : 0, paramBoolean1 ? 0.45D : 0.25D, (paramBoolean2 ? -0.28D : -0.2D) + (paramBoolean1 ? -0.02 : 0)); BlcGlStateManager.b(paramBoolean1 ? 0.2 : 0, paramBoolean1 ? 0.45D : 0.25D, (paramBoolean2 ? -0.28D : -0.2D) + (paramBoolean1 ? -0.02 : 0));
BlcGlStateManager.b(180.0F, 0.0F, 0.0F, 1.0F); BlcGlStateManager.b(180.0F, 0.0F, 0.0F, 1.0F);
if(chestplate) {
GlStateManager.translate(0, 0, -0.06 + (paramBoolean2 ? -0.055 : 0));
}
break; break;
case "shield_dollar": case "shield_dollar":
GlStateManager.translate(0.70F, 0.2, 0); GlStateManager.translate(0.70F, 0.35, 0);
BlcGlStateManager.b(90.0F, 0.0F, 1.0F, 0.0F); BlcGlStateManager.b(90.0F, 0.0F, 1.0F, 0.0F);
BlcGlStateManager.b(paramBoolean1 ? 0.2 : 0, paramBoolean1 ? 0.45D : 0.25D, (paramBoolean2 ? -0.265D : -0.2D) + (paramBoolean1 ? -0.02 : 0)); BlcGlStateManager.b(paramBoolean1 ? 0.2 : 0, paramBoolean1 ? 0.45D : 0.25D, (paramBoolean2 ? -0.265D : -0.2D) + (paramBoolean1 ? -0.02 : 0));
BlcGlStateManager.b(180.0F, 0.0F, 0.0F, 1.0F); BlcGlStateManager.b(180.0F, 0.0F, 0.0F, 1.0F);
if(chestplate) {
GlStateManager.translate(0, 0, 0.06 + (paramBoolean2 ? 0.055 : 0));
}
break; break;
} }
} }

View File

@ -96,11 +96,26 @@ public class HUDConfigScreen extends GuiScreen {
if(((ModDraggable) m).isHovered(mouseX, mouseY, scaledresolution) || ((ModDraggable) m).isDragging()) { if(((ModDraggable) m).isHovered(mouseX, mouseY, scaledresolution) || ((ModDraggable) m).isDragging()) {
cursorType = MouseCursorHandler.CursorType.MOVE; cursorType = MouseCursorHandler.CursorType.MOVE;
} }
((ModDraggable) m).renderEditing(mouseX, mouseY, scaledresolution, debug, this); if(((ModDraggable) m).getCornerScalingType() == CornerScalingType.BOTTOM_RIGHT || ((ModDraggable) m).cornerDotHovered(mouseX, mouseY, CornerScalingType.BOTTOM_RIGHT)) {
cursorType = MouseCursorHandler.CursorType.NESW_RESIZE;
}
if(((ModDraggable) m).isDragging()) { if(((ModDraggable) m).isDragging()) {
((ModDraggable) m).setPos(new ScreenPosition(mouseX + ((ModDraggable) m).getDraggingX(), mouseY + ((ModDraggable) m).getDraggingY())); ((ModDraggable) m).setPos(new ScreenPosition(mouseX + ((ModDraggable) m).getDraggingX(), mouseY + ((ModDraggable) m).getDraggingY()));
} }
if(((ModDraggable) m).getCornerScalingType() != null && ((ModDraggable) m).getCornerScalingType() != CornerScalingType.NONE) {
Setting setting = Client.getInstance().getSettingsManager().getSettingByName(m, "Scale");
float scale = 0;
scale = mouseY / (((ModDraggable) m).getPos().getAbsoluteY() + (((ModDraggable) m).getCornerY(((ModDraggable) m).getCornerScalingType()) * ((ModDraggable) m).getScale()));
scale = scale - 1;
scale = setting.getValFloat() + scale;
if(scale <= setting.getMax() && scale >= setting.getMin()) {
setting.setValDouble(scale);
}
}
((ModDraggable) m).renderEditing(mouseX, mouseY, scaledresolution, debug, this);
} }
} }
@ -193,11 +208,6 @@ public class HUDConfigScreen extends GuiScreen {
} }
} }
@Override
protected void mouseClickMove(int x, int y, int button, long time) {
super.mouseClickMove(x, y, button, time);
}
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
MenuBlurUtils.unloadBlur(); MenuBlurUtils.unloadBlur();
@ -216,6 +226,7 @@ public class HUDConfigScreen extends GuiScreen {
for(Mod m : Client.getInstance().getModInstances().getMods()) { for(Mod m : Client.getInstance().getModInstances().getMods()) {
if(m instanceof ModDraggable) { if(m instanceof ModDraggable) {
((ModDraggable) m).setDragging(false); ((ModDraggable) m).setDragging(false);
((ModDraggable) m).setCornerScalingType(CornerScalingType.NONE);
} }
} }
} }
@ -226,6 +237,10 @@ public class HUDConfigScreen extends GuiScreen {
ScaledResolution scaledResolution = new ScaledResolution(mc); ScaledResolution scaledResolution = new ScaledResolution(mc);
for(Mod m : Client.getInstance().getModInstances().getMods()) { for(Mod m : Client.getInstance().getModInstances().getMods()) {
if(m.isEnabled() && m instanceof ModDraggable) { if(m.isEnabled() && m instanceof ModDraggable) {
if(((ModDraggable) m).cornerDotHovered(mouseX, mouseY, CornerScalingType.BOTTOM_RIGHT)) {
((ModDraggable) m).setCornerScalingType(CornerScalingType.BOTTOM_RIGHT);
break;
}
boolean hovered = ((ModDraggable) m).isHovered(mouseX, mouseY, scaledResolution); boolean hovered = ((ModDraggable) m).isHovered(mouseX, mouseY, scaledResolution);
if(hovered) { if(hovered) {
@ -249,4 +264,12 @@ public class HUDConfigScreen extends GuiScreen {
public boolean doesGuiPauseGame() { public boolean doesGuiPauseGame() {
return true; return true;
} }
public enum CornerScalingType {
NONE,
TOP_LEFT,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT
}
} }

View File

@ -2,6 +2,7 @@ package net.silentclient.client.mods;
import java.awt.Color; import java.awt.Color;
import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.mixin.accessors.GuiAccessor; import net.silentclient.client.mixin.accessors.GuiAccessor;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -31,7 +32,7 @@ public abstract class ModDraggable extends Mod implements IRenderer {
private int draggingX, draggingY; private int draggingX, draggingY;
public SimpleAnimation editOpacityAnimation = new SimpleAnimation(0.0F); private HUDConfigScreen.CornerScalingType cornerScalingType;
public ModDraggable(String name, ModCategory category, String icon) { public ModDraggable(String name, ModCategory category, String icon) {
super(name, category, icon); super(name, category, icon);
@ -136,6 +137,7 @@ public abstract class ModDraggable extends Mod implements IRenderer {
if((this.getScaledHeight() + y) > scaledresolution.getScaledHeight()) { if((this.getScaledHeight() + y) > scaledresolution.getScaledHeight()) {
y = (int) (y - ((this.getScaledHeight() + y) - scaledresolution.getScaledHeight())); y = (int) (y - ((this.getScaledHeight() + y) - scaledresolution.getScaledHeight()));
} }
pos = ScreenPosition.fromAbsolute(x, y);
if(debug) { if(debug) {
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
int debugX = (int) (x + this.getScaledWidth()) + 1; int debugX = (int) (x + this.getScaledWidth()) + 1;
@ -158,6 +160,10 @@ public abstract class ModDraggable extends Mod implements IRenderer {
Client.getInstance().getSilentFontRenderer().drawString(debugX, debugY + 24, "height: " + (int) this.getScaledHeight(), 6, SilentFontRenderer.FontType.TITLE); Client.getInstance().getSilentFontRenderer().drawString(debugX, debugY + 24, "height: " + (int) this.getScaledHeight(), 6, SilentFontRenderer.FontType.TITLE);
ColorUtils.setColor(-1); ColorUtils.setColor(-1);
Client.getInstance().getSilentFontRenderer().drawString(debugX, debugY + 30, "dragging: " + this.isDragging(), 6, SilentFontRenderer.FontType.TITLE); Client.getInstance().getSilentFontRenderer().drawString(debugX, debugY + 30, "dragging: " + this.isDragging(), 6, SilentFontRenderer.FontType.TITLE);
ColorUtils.setColor(-1);
Client.getInstance().getSilentFontRenderer().drawString(debugX, debugY + 36, "cursor: " + Client.getInstance().getMouseCursorHandler().getCurrentCursor(), 6, SilentFontRenderer.FontType.TITLE);
ColorUtils.setColor(-1);
Client.getInstance().getSilentFontRenderer().drawString(debugX, debugY + 42, "corner: " + (pos.getAbsoluteX() + (getCornerX(HUDConfigScreen.CornerScalingType.BOTTOM_RIGHT) * getScale())) + ", " + (pos.getAbsoluteY() + (getCornerY(HUDConfigScreen.CornerScalingType.BOTTOM_RIGHT) * getScale())), 6, SilentFontRenderer.FontType.TITLE);
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
ColorUtils.setColor(-1); ColorUtils.setColor(-1);
@ -166,10 +172,60 @@ public abstract class ModDraggable extends Mod implements IRenderer {
GlStateManager.scale(this.getScale(), this.getScale(), this.getScale()); GlStateManager.scale(this.getScale(), this.getScale(), this.getScale());
this.renderDummy(pos); this.renderDummy(pos);
boolean hovered = this.isHovered(mouseX, mouseY, scaledresolution); boolean hovered = this.isHovered(mouseX, mouseY, scaledresolution);
this.drawHollowRect(0, 0, this.getWidth(), this.getHeight(), hovered || this.isDragging() ? new Color(245, 188, 0).getRGB() : -1, instance); int hoverColor = new Color(245, 188, 0).getRGB();
this.drawHollowRect(0, 0, this.getWidth(), this.getHeight(), hovered || this.isDragging() ? hoverColor : -1, instance);
this.drawCornerDot(mouseX, mouseY, HUDConfigScreen.CornerScalingType.BOTTOM_RIGHT);
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
private void drawCornerDot(int mouseX, int mouseY, HUDConfigScreen.CornerScalingType cornerType) {
int color = -1;
if(this.cornerDotHovered(mouseX, mouseY, cornerType)) {
color = new Color(245, 188, 0).getRGB();
}
RenderUtil.drawRoundedRect(getCornerX(cornerType), getCornerY(cornerType), getCornerX(cornerType) + 3, getCornerY(cornerType) + 3, 3, color);
}
public int getCornerX(HUDConfigScreen.CornerScalingType cornerType) {
int x = 0;
switch (cornerType) {
case TOP_LEFT:
case BOTTOM_LEFT:
x = -1;
break;
case TOP_RIGHT:
case BOTTOM_RIGHT:
x = this.getWidth() - 1;
break;
}
return x;
}
public int getCornerY(HUDConfigScreen.CornerScalingType cornerType) {
int y = 0;
switch (cornerType) {
case TOP_LEFT:
case TOP_RIGHT:
y = -1;
break;
case BOTTOM_LEFT:
case BOTTOM_RIGHT:
y = this.getHeight() - 1;
break;
}
return y;
}
public boolean cornerDotHovered(int mouseX, int mouseY, HUDConfigScreen.CornerScalingType cornerType) {
return MouseUtils.isInside(mouseX, mouseY, pos.getAbsoluteX() + (getCornerX(cornerType) * getScale()), pos.getAbsoluteY() + (getCornerY(cornerType) * getScale()), 3 * getScale(), 3 * getScale());
}
private void drawHollowRect(int x, int y, int w, int h, int color, Gui instance) { private void drawHollowRect(int x, int y, int w, int h, int color, Gui instance) {
((GuiAccessor) instance).silent$drawHorizontalLine(x, x + w, y, color); ((GuiAccessor) instance).silent$drawHorizontalLine(x, x + w, y, color);
((GuiAccessor) instance).silent$drawHorizontalLine(x, x + w, y + h, color); ((GuiAccessor) instance).silent$drawHorizontalLine(x, x + w, y + h, color);
@ -257,4 +313,12 @@ public abstract class ModDraggable extends Mod implements IRenderer {
public void setHide(boolean hide) { public void setHide(boolean hide) {
this.hide = hide; this.hide = hide;
} }
public HUDConfigScreen.CornerScalingType getCornerScalingType() {
return cornerScalingType;
}
public void setCornerScalingType(HUDConfigScreen.CornerScalingType cornerScalingType) {
this.cornerScalingType = cornerScalingType;
}
} }

View File

@ -108,6 +108,10 @@ public class MouseCursorHandler {
} }
} }
public CursorType getCurrentCursor() {
return currentCursor;
}
public enum CursorType public enum CursorType
{ {
NORMAL, NORMAL,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB