Skip to content

Commit

Permalink
Partially ported to 24w36a
Browse files Browse the repository at this point in the history
  • Loading branch information
shurik204 committed Sep 11, 2024
1 parent 8231cd6 commit b1dfa63
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 94 deletions.
12 changes: 4 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

plugins {
id("fabric-loom") version "1.6-SNAPSHOT" // Fabric Loom
id("fabric-loom") version "1.7-SNAPSHOT" // Fabric Loom
id("io.github.p03w.machete") version "1.1.4" // Build jar compression
id("me.modmuss50.mod-publish-plugin") version "0.4.5" // Mod publishing

Expand Down Expand Up @@ -165,13 +165,9 @@ tasks {
}
}

// Fix machete compression
getAllTasks(true).forEach {
for (task in it.value) {
// All publishing tasks depend on the remapJar task. But also metadata generation.
if (task.name.startsWith("publish") || task.name == "generateMetadataFileForJarPublication") {
task.dependsOn("optimizeOutputsOfRemapJar")
}
configureEach {
if (name.startsWith("publish") || name == "generateMetadataFileForJarPublication") {
dependsOn("optimizeOutputsOfRemapJar")
}
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ org.gradle.parallel=true

# Main properties
mod.java=21
mod.minecraft=1.21
mod.minecraft=24w36a
mod.loader=0.15.11
mod.yarn=1.21+build.1
mod.yarn=24w36a+build.6

# Mod properties
mod.group=me.shurik
Expand All @@ -15,6 +15,6 @@ mod.name=Better Suggestions
mod.description=Makes Minecraft command suggestions more useful.

# Dependencies
deps.fabricApi=0.100.3+1.21
deps.clothConfig=15.0.127
deps.modMenu=11.0.0
deps.fabricApi=0.103.2+1.21.2
deps.clothConfig=16.0.131
deps.modMenu=12.0.0-alpha.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package me.shurik.bettersuggestions.client.mixin;

import me.shurik.bettersuggestions.client.access.ClientEntityDataAccessor;
import net.minecraft.client.render.Frustum;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MarkerEntity;
import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.entity.decoration.InteractionEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.RotationAxis;
import org.joml.Quaternionf;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EntityRenderDispatcher.class)
public abstract class EntityRenderDispatcherMixin {
@Shadow @Final private ItemRenderer itemRenderer;
@Shadow public abstract Quaternionf getRotation();

@Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true)
private <E extends Entity> void shouldRender(E entity, Frustum frustum, double x, double y, double z, CallbackInfoReturnable<Boolean> info) {
if (entity instanceof MarkerEntity || entity instanceof AreaEffectCloudEntity || entity instanceof DisplayEntity) {
info.setReturnValue(true);
}
}

@Inject(method = "render(Lnet/minecraft/entity/Entity;DDDFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/client/render/entity/EntityRenderer;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderer;render(Lnet/minecraft/client/render/entity/state/EntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"))
private <E extends Entity, S extends EntityRenderState> void highlightSpecial(E entity, double x, double y, double z, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, EntityRenderer<? super E, S> renderer, CallbackInfo ci) {
if (((ClientEntityDataAccessor)entity).isHighlighted()) {
switch (entity) {
case MarkerEntity marker ->
suggestions$renderItem(Items.STRUCTURE_VOID.getDefaultStack(), light, matrices, vertexConsumers, entity);
case AreaEffectCloudEntity aec ->
suggestions$renderItem(Items.LINGERING_POTION.getDefaultStack(), light, matrices, vertexConsumers, entity);
case InteractionEntity interaction -> suggestions$renderItem(Items.PISTON.getDefaultStack(), light, matrices, vertexConsumers, entity);
case DisplayEntity display -> suggestions$renderItem(Items.ITEM_FRAME.getDefaultStack(), light, matrices, vertexConsumers, entity);
// TODO: properly fix rendering
// case DisplayEntity display -> SpecialRendererQueue.addEntity(entity);
// case InteractionEntity interaction -> SpecialRendererQueue.addEntity(entity);
default -> {}
}
}
}

private void suggestions$renderItem(ItemStack item, int light, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Entity entity) {
matrices.push();
matrices.multiply(this.getRotation());
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F));
this.itemRenderer.renderItem(item, ModelTransformationMode.GROUND, light, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, entity.getWorld(), entity.getId());
matrices.pop();
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
package me.shurik.bettersuggestions.client.mixin;

import me.shurik.bettersuggestions.client.render.SpecialRendererQueue;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import me.shurik.bettersuggestions.client.access.ClientEntityDataAccessor;
import net.minecraft.client.render.Frustum;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MarkerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.RotationAxis;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* Render markers and area effect clouds as items.
*/
@Mixin(EntityRenderer.class)
public class EntityRendererMixin<T extends Entity> {
private ItemRenderer suggestions$itemRenderer;
private EntityRenderDispatcher suggestions$dispatcher;
// private ItemRenderer suggestions$itemRenderer;
// private EntityRenderDispatcher suggestions$dispatcher;

// constructor
@Inject(method = "<init>", at = @At("RETURN"))
void constructor(EntityRendererFactory.Context ctx, CallbackInfo info) {
this.suggestions$itemRenderer = ctx.getItemRenderer();
this.suggestions$dispatcher = ctx.getRenderDispatcher();
}
// @Inject(method = "<init>", at = @At("RETURN"))
// void constructor(EntityRendererFactory.Context ctx, CallbackInfo info) {
// this.suggestions$itemRenderer = ctx.getItemRenderer();
// this.suggestions$dispatcher = ctx.getRenderDispatcher();
// }

// public boolean shouldRender(T entity, Frustum frustum, double x, double y, double z)
@Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true)
Expand All @@ -47,25 +33,9 @@ void shouldRender(T entity, Frustum frustum, double x, double y, double z, Callb
}
}

// public void render(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light)
@Inject(method = "render", at = @At("HEAD"))
void render(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) {
if (((ClientEntityDataAccessor)entity).isHighlighted()) {
if (entity instanceof MarkerEntity) {
renderItem(Items.STRUCTURE_VOID.getDefaultStack(), light, matrices, vertexConsumers, entity);
} else if (entity instanceof AreaEffectCloudEntity) {
renderItem(Items.LINGERING_POTION.getDefaultStack(), light, matrices, vertexConsumers, entity);
} else {
SpecialRendererQueue.addEntity(entity);
}
}
}

private void renderItem(ItemStack item, int light, MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity) {
matrices.push();
matrices.multiply(this.suggestions$dispatcher.getRotation());
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F));
this.suggestions$itemRenderer.renderItem(item, ModelTransformationMode.GROUND, light, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, entity.getWorld(), entity.getId());
matrices.pop();
}
// public void render(<S extends EntityRenderState> state, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light)
// @Inject(method = "render", at = @At("HEAD"))
// <S extends EntityRenderState> void render(S state, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.entity.decoration.InteractionEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import org.joml.Vector4f;
import org.lwjgl.opengl.GL11;
Expand Down Expand Up @@ -37,16 +38,17 @@ private static FullContext setupContext(WorldRenderContext context, Vec3d pos) {
private static void finishRendering(FullContext context) {
context.matrices.pop();

RenderSystem.setShader(GameRenderer::getPositionColorProgram);
RenderSystem.enableBlend();
RenderSystem.disableCull();
RenderSystem.depthFunc(GL11.GL_ALWAYS);
try (ShaderProgram shader = RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR)) {
RenderSystem.enableBlend();
RenderSystem.disableCull();
RenderSystem.depthFunc(GL11.GL_ALWAYS);

BufferRenderer.drawWithGlobalProgram(context.bufferBuilder.end());
BufferRenderer.draw(context.bufferBuilder.end());

RenderSystem.depthFunc(GL11.GL_LEQUAL);
RenderSystem.enableCull();
RenderSystem.disableBlend();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
RenderSystem.enableCull();
RenderSystem.disableBlend();
}
}

public static void renderEntityHighlight(Entity entity, Vector4f color, WorldRenderContext worldContext) {
Expand All @@ -58,40 +60,41 @@ public static void renderEntityHighlight(Entity entity, Vector4f color, WorldRen
}

public static void renderBlockHighlight(BlockPos pos, Vector4f color, WorldRenderContext worldContext) {
FullContext context = setupContext(worldContext, pos);
// Box box = new Box(-0.5d, 0, -0.5d, 0.5d, 1, 0.5d);

WorldRenderer.renderFilledBox(context.matrices, context.bufferBuilder, -0.5d, 0, -0.5d, 0.5d, 1, 0.5d, color.x, color.y, color.z, color.w);
finishRendering(context);
// FullContext context = setupContext(worldContext, pos);
//
// VertexRendering.drawFilledBox(context.matrices, context.bufferBuilder, -0.05d, 0d, -0.05d, 0.05d, 0.1d, 0.05d, color.x, color.y, color.z, color.w);
//
// finishRendering(context);
}

public static void renderPositionHighlight(Vec3d pos, Vector4f color, WorldRenderContext worldContext) {
FullContext context = setupContext(worldContext, pos);

context.matrices.translate(0F, -0.05F, 0F);
WorldRenderer.renderFilledBox(context.matrices, context.bufferBuilder, -0.05d, 0d, -0.05d, 0.05d, 0.1d, 0.05d, color.x, color.y, color.z, color.w);
finishRendering(context);
// FullContext context = setupContext(worldContext, pos);
//
// context.matrices.translate(0F, -0.05F, 0F);
//// DebugRenderer.drawBox(context.matrices, worldContext.consumers(), -0.05d, 0d, -0.05d, 0.05d, 0.1d, 0.05d, color.x, color.y, color.z, color.w);
// VertexRendering.drawFilledBox(context.matrices, context.bufferBuilder, -0.05d, 0d, -0.05d, 0.05d, 0.1d, 0.05d, color.x, color.y, color.z, color.w);
// finishRendering(context);
}

public static void interactionHighlight(InteractionEntity interaction, Vector4f color, WorldRenderContext worldContext) {
FullContext context = setupContext(worldContext, interaction);
Box box = interaction.getBoundingBox();

// getLengthX
double halfX = (box.maxX - box.minX) / 2;
// getLengthZ
double halfZ = (box.maxZ - box.minZ) / 2;

WorldRenderer.renderFilledBox(context.matrices, context.bufferBuilder, -halfX, 0, -halfZ, halfX, box.maxY - box.minY, halfZ, color.x, color.y, color.z, color.w);
finishRendering(context);
// FullContext context = setupContext(worldContext, interaction);
// Box box = interaction.getBoundingBox();
//
// // getLengthX
// double halfX = (box.maxX - box.minX) / 2;
// // getLengthZ
// double halfZ = (box.maxZ - box.minZ) / 2;
//
// VertexRendering.drawFilledBox(context.matrices, context.bufferBuilder, -0.05d, 0d, -0.05d, 0.05d, 0.1d, 0.05d, color.x, color.y, color.z, color.w);
// finishRendering(context);
}

public static void displayEntityHighlight(DisplayEntity interaction, Vector4f color, WorldRenderContext worldContext) {
FullContext context = setupContext(worldContext, interaction);

context.matrices.translate(0F, -0.2F, 0F);
WorldRenderer.renderFilledBox(context.matrices, context.bufferBuilder, -0.2d, 0d, -0.2d, 0.2d, 0.4d, 0.2d, color.x, color.y, color.z, color.w);

finishRendering(context);
// FullContext context = setupContext(worldContext, interaction);
//
// context.matrices.translate(0F, -0.2F, 0F);
// VertexRendering.drawBox(context.matrices, context.bufferBuilder, -0.2d, 0d, -0.2d, 0.2d, 0.4d, 0.2d, color.x, color.y, color.z, color.w);
//
// finishRendering(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package me.shurik.bettersuggestions.client.render.entity;

import me.shurik.bettersuggestions.client.render.state.MarkerEntityRenderState;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.entity.MarkerEntity;

public class MarkerEntityRenderer extends EntityRenderer<MarkerEntity, MarkerEntityRenderState> {
protected MarkerEntityRenderer(EntityRendererFactory.Context context) {
super(context);
}

@Override
public MarkerEntityRenderState getRenderState() {
return MarkerEntityRenderState.INSTANCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.shurik.bettersuggestions.client.render.state;

import net.minecraft.client.render.entity.state.EntityRenderState;

public class MarkerEntityRenderState extends EntityRenderState {
public static final MarkerEntityRenderState INSTANCE = new MarkerEntityRenderState();
}
1 change: 1 addition & 0 deletions src/main/resources/better-suggestions.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ChatScreenMixin",
"ClientCommandSourceMixin",
"ClientPlayNetworkHandlerMixin",
"EntityRenderDispatcherMixin",
"EntityRendererMixin",
"LanguageManagerMixin",
"MinecraftClientMixin",
Expand Down

0 comments on commit b1dfa63

Please sign in to comment.