Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Forge] Update to Minecraft 1.20.4 #189

Open
wants to merge 3 commits into
base: forge-1.19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.19-forge-2'
version = '1.20.1-forge-1'
group = 'net.torocraft'
archivesBaseName = 'torohealth'

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
mappings channel: 'official', version: '1.19'
mappings channel: 'official', version: '1.20.1'
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

runs {
client {
Expand Down Expand Up @@ -65,7 +66,7 @@ minecraft {
sourceSets.main.resources { srcDir 'src/generated/resources' }

dependencies {
minecraft 'net.minecraftforge:forge:1.19-41.0.100'
minecraft 'net.minecraftforge:forge:1.20.1-47.2.1'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
import net.minecraftforge.client.event.RenderLevelStageEvent;
Expand Down Expand Up @@ -42,13 +43,14 @@ private static void entityRender(
private static void renderParticles(RenderLevelStageEvent event) {
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES) {
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
ParticleRenderer.renderParticles(event.getPoseStack(), camera);
HealthBarRenderer.renderInWorld(event.getPartialTick(), event.getPoseStack(), camera);
MultiBufferSource bufferSource = event.getLevelRenderer().renderBuffers.bufferSource();
ParticleRenderer.renderParticles(event.getPoseStack(), camera, bufferSource);
HealthBarRenderer.renderInWorld(event.getPartialTick(), event.getPoseStack(), bufferSource, camera);
}
}

private static void playerTick(PlayerTickEvent event) {
if (!event.player.level.isClientSide) {
if (!event.player.level().isClientSide) {
return;
}
ToroHealthClient.HUD.setEntity(
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

import com.mojang.math.Axis;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -23,6 +27,9 @@
import net.torocraft.torohealth.config.Config.Mode;
import net.torocraft.torohealth.util.EntityUtil;
import net.torocraft.torohealth.util.EntityUtil.Relation;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

public class HealthBarRenderer {
Expand Down Expand Up @@ -71,7 +78,7 @@ public static void prepareRenderInWorld(LivingEntity entity) {

}

public static void renderInWorld(float partialTick, PoseStack matrix, Camera camera) {
public static void renderInWorld(float partialTick, PoseStack matrix, MultiBufferSource bufferSource, Camera camera) {

Minecraft client = Minecraft.getInstance();

Expand Down Expand Up @@ -110,11 +117,11 @@ public static void renderInWorld(float partialTick, PoseStack matrix, Camera cam

matrix.pushPose();
matrix.translate(x - camX, (y + height) - camY, z - camZ);
matrix.mulPose(Vector3f.YP.rotationDegrees(-camera.getYRot()));
matrix.mulPose(Vector3f.XP.rotationDegrees(camera.getXRot()));
matrix.mulPose(Axis.YP.rotationDegrees(-camera.getYRot()));
matrix.mulPose(Axis.XP.rotationDegrees(camera.getXRot()));
matrix.scale(-scaleToGui, -scaleToGui, scaleToGui);

render(matrix, entity, 0, 0, FULL_SIZE, true);
render(matrix, entity, bufferSource, 0, 0, FULL_SIZE, true);

matrix.popPose();
}
Expand All @@ -124,7 +131,7 @@ public static void renderInWorld(float partialTick, PoseStack matrix, Camera cam
renderedEntities.clear();
}

public static void render(PoseStack matrix, LivingEntity entity, double x, double y,
public static void render(PoseStack matrix, LivingEntity entity, MultiBufferSource bufferSource, double x, double y,
float width, boolean inWorld) {

Relation relation = EntityUtil.determineRelation(entity);
Expand All @@ -147,15 +154,14 @@ public static void render(PoseStack matrix, LivingEntity entity, double x, doubl

if (!inWorld) {
if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.CUMULATIVE)) {
drawDamageNumber(matrix, state.lastDmgCumulative, x, y, width);
drawDamageNumber(matrix, bufferSource, state.lastDmgCumulative, x, y, width);
} else if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.LAST)) {
drawDamageNumber(matrix, state.lastDmg, x, y, width);
drawDamageNumber(matrix, bufferSource, state.lastDmg, x, y, width);
}
}
}

public static void drawDamageNumber(PoseStack matrix, int dmg, double x, double y,
float width) {
public static void drawDamageNumber(PoseStack matrix, MultiBufferSource bufferSource, int dmg, double x, double y, float width) {
int i = Math.abs(Math.round(dmg));
if (i == 0) {
return;
Expand All @@ -164,11 +170,15 @@ public static void drawDamageNumber(PoseStack matrix, int dmg, double x, double
Minecraft minecraft = Minecraft.getInstance();
int sw = minecraft.font.width(s);
int color = dmg < 0 ? ToroHealth.CONFIG.particle.healColor : ToroHealth.CONFIG.particle.damageColor;
minecraft.font.draw(matrix, s, (int) (x + (width / 2) - sw), (int) y + 5, color);

minecraft.font.drawInBatch(
s, (float) (x + (width / 2) - sw), (float) y + 5, color, false,
matrix.last().pose(), bufferSource,
Font.DisplayMode.NORMAL, 0, 0);
}

private static void drawBar(Matrix4f matrix4f, double x, double y, float width, float percent,
int color, int zOffset, boolean inWorld) {
int color, int zOffset, boolean inWorld) {
float c = 0.00390625F;
int u = 0;
int v = 6 * 5 * 2 + 5;
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/net/torocraft/torohealth/bars/ParticleRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import com.mojang.math.Axis;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
import net.torocraft.torohealth.ToroHealth;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;

public class ParticleRenderer {

public static void renderParticles(PoseStack matrix, Camera camera) {
public static void renderParticles(PoseStack matrix, Camera camera, MultiBufferSource bufferSource) {
for (BarParticle p : BarStates.PARTICLES) {
renderParticle(matrix, p, camera);
renderParticle(matrix, p, camera, bufferSource);
}
}

private static void renderParticle(PoseStack matrix, BarParticle particle, Camera camera) {
private static void renderParticle(PoseStack matrix, BarParticle particle, Camera camera, MultiBufferSource bufferSource) {
double distanceSquared = camera.getPosition().distanceToSqr(particle.x, particle.y, particle.z);
if (distanceSquared > ToroHealth.CONFIG.particle.distanceSquared) {
return;
Expand All @@ -41,8 +44,8 @@ private static void renderParticle(PoseStack matrix, BarParticle particle, Camer

matrix.pushPose();
matrix.translate(x - camX, y - camY, z - camZ);
matrix.mulPose(Vector3f.YP.rotationDegrees(-camera.getYRot()));
matrix.mulPose(Vector3f.XP.rotationDegrees(camera.getXRot()));
matrix.mulPose(Axis.YP.rotationDegrees(-camera.getYRot()));
matrix.mulPose(Axis.XP.rotationDegrees(camera.getXRot()));
matrix.scale(-scaleToGui, -scaleToGui, scaleToGui);

RenderSystem.setShader(GameRenderer::getPositionColorShader);
Expand All @@ -51,7 +54,7 @@ private static void renderParticle(PoseStack matrix, BarParticle particle, Camer
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE,
GL11.GL_ZERO);

HealthBarRenderer.drawDamageNumber(matrix, particle.damage, 0, 0, 10);
HealthBarRenderer.drawDamageNumber(matrix, bufferSource, particle.damage, 0, 0, 10);

RenderSystem.disableBlend();

Expand Down
34 changes: 17 additions & 17 deletions src/main/java/net/torocraft/torohealth/display/BarDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -15,9 +17,9 @@ public class BarDisplay {
private static final ResourceLocation ICON_TEXTURES =
new ResourceLocation("textures/gui/icons.png");
private final Minecraft mc;
private final GuiComponent gui;
private final Screen gui;

public BarDisplay(Minecraft mc, GuiComponent gui) {
public BarDisplay(Minecraft mc, Screen gui) {
this.mc = mc;
this.gui = gui;
}
Expand All @@ -26,48 +28,46 @@ private String getEntityName(LivingEntity entity) {
return entity.getDisplayName().getString();
}

public void draw(PoseStack matrix, LivingEntity entity) {
public void draw(GuiGraphics guiGraphics, LivingEntity entity) {
int xOffset = 0;

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, ICON_TEXTURES);
RenderSystem.enableBlend();

HealthBarRenderer.render(matrix, entity, 63, 14, 130, false);
HealthBarRenderer.render(guiGraphics.pose(), entity, guiGraphics.bufferSource(), 63, 14, 130, false);
String name = getEntityName(entity);
int healthMax = Mth.ceil(entity.getMaxHealth());
int healthCur = Math.min(Mth.ceil(entity.getHealth()), healthMax);
String healthText = healthCur + "/" + healthMax;
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

GuiComponent.drawString(matrix, mc.font, name, xOffset, (int) 2, 16777215);
guiGraphics.drawString(mc.font, name, xOffset, (int) 2, 16777215);

mc.font.drawShadow(matrix, name, xOffset, 2, 16777215);
guiGraphics.drawString(mc.font, name, xOffset, 2, 16777215);
xOffset += mc.font.width(name) + 5;

renderHeartIcon(matrix, xOffset, (int) 1);
renderHeartIcon(guiGraphics, xOffset, (int) 1);
xOffset += 10;

mc.font.drawShadow(matrix, healthText, xOffset, 2, 0xe0e0e0);
guiGraphics.drawString(mc.font, healthText, xOffset, 2, 0xe0e0e0);
xOffset += mc.font.width(healthText) + 5;

int armor = entity.getArmorValue();// getArmor();

if (armor > 0) {
renderArmorIcon(matrix, xOffset, (int) 1);
renderArmorIcon(guiGraphics, xOffset, (int) 1);
xOffset += 10;
mc.font.drawShadow(matrix, entity.getArmorValue() + "", xOffset, 2, 0xe0e0e0);
guiGraphics.drawString(mc.font, entity.getArmorValue() + "", xOffset, 2, 0xe0e0e0);
}
}

private void renderArmorIcon(PoseStack matrix, int x, int y) {
RenderSystem.setShaderTexture(0, ICON_TEXTURES);
gui.blit(matrix, x, y, 34, 9, 9, 9);
private void renderArmorIcon(GuiGraphics matrix, int x, int y) {
matrix.blit(ICON_TEXTURES, x, y, 34, 9, 9, 9);
}

private void renderHeartIcon(PoseStack matrix, int x, int y) {
RenderSystem.setShaderTexture(0, ICON_TEXTURES);
gui.blit(matrix, x, y, 16 + 36, 0, 9, 9);
private void renderHeartIcon(GuiGraphics matrix, int x, int y) {
matrix.blit(ICON_TEXTURES, x, y, 16 + 36, 0, 9, 9);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
Expand All @@ -13,6 +12,8 @@
import net.minecraft.world.entity.animal.Chicken;
import net.minecraft.world.entity.monster.Ghast;
import net.minecraft.world.entity.npc.Villager;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class EntityDisplay {

Expand Down Expand Up @@ -82,10 +83,9 @@ public static void drawEntity(PoseStack matrixStack2, int x, int y, int size, fl
matrixStack2.pushPose();
matrixStack2.translate(0.0D, 0.0D, 1000.0D);
matrixStack2.scale((float) size, (float) size, (float) size);
Quaternion quaternion = Vector3f.ZP.rotationDegrees(180.0F);
Quaternion quaternion2 = Vector3f.XP.rotationDegrees(g * 20.0F);
quaternion.mul(quaternion2);
matrixStack2.mulPose(quaternion);
Quaternionf quaternion = Axis.ZP.rotationDegrees(180.0F);
Quaternionf quaternion2 = Axis.XP.rotationDegrees(g * 20.0F);
matrixStack2.mulPose(quaternion.mul(quaternion2));
float h = entity.yBodyRot; // bodyYaw;
float i = entity.getYRot(); // getYaw();
float j = entity.getXRot(); // getPitch();
Expand All @@ -99,8 +99,7 @@ public static void drawEntity(PoseStack matrixStack2, int x, int y, int size, fl
Lighting.setupForEntityInInventory();
EntityRenderDispatcher entityrenderdispatcher =
Minecraft.getInstance().getEntityRenderDispatcher();
quaternion2.conj();
entityrenderdispatcher.overrideCameraOrientation(quaternion2);
entityrenderdispatcher.overrideCameraOrientation(quaternion2.conjugate());
entityrenderdispatcher.setRenderShadow(false);
MultiBufferSource.BufferSource immediate =
Minecraft.getInstance().renderBuffers().bufferSource();
Expand Down
Loading