diff --git a/build.gradle.kts b/build.gradle.kts index 4d8df0a..be1901e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 @@ -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") } } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c213996..4075c7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 @@ -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 \ No newline at end of file +deps.fabricApi=0.103.2+1.21.2 +deps.clothConfig=16.0.131 +deps.modMenu=12.0.0-alpha.1 \ No newline at end of file diff --git a/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRenderDispatcherMixin.java b/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRenderDispatcherMixin.java new file mode 100644 index 0000000..45a82ed --- /dev/null +++ b/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRenderDispatcherMixin.java @@ -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 void shouldRender(E entity, Frustum frustum, double x, double y, double z, CallbackInfoReturnable 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 void highlightSpecial(E entity, double x, double y, double z, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, EntityRenderer 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(); + } +} \ No newline at end of file diff --git a/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRendererMixin.java b/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRendererMixin.java index 16fa40c..5b3b65f 100644 --- a/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRendererMixin.java +++ b/src/main/java/me/shurik/bettersuggestions/client/mixin/EntityRendererMixin.java @@ -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 { - private ItemRenderer suggestions$itemRenderer; - private EntityRenderDispatcher suggestions$dispatcher; +// private ItemRenderer suggestions$itemRenderer; +// private EntityRenderDispatcher suggestions$dispatcher; // constructor - @Inject(method = "", at = @At("RETURN")) - void constructor(EntityRendererFactory.Context ctx, CallbackInfo info) { - this.suggestions$itemRenderer = ctx.getItemRenderer(); - this.suggestions$dispatcher = ctx.getRenderDispatcher(); - } +// @Inject(method = "", 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) @@ -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( state, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) +// @Inject(method = "render", at = @At("HEAD")) +// void render(S state, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { +// +// } } \ No newline at end of file diff --git a/src/main/java/me/shurik/bettersuggestions/client/render/SpecialRenderer.java b/src/main/java/me/shurik/bettersuggestions/client/render/SpecialRenderer.java index 6c46ec1..12b3dd6 100644 --- a/src/main/java/me/shurik/bettersuggestions/client/render/SpecialRenderer.java +++ b/src/main/java/me/shurik/bettersuggestions/client/render/SpecialRenderer.java @@ -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; @@ -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) { @@ -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); } } \ No newline at end of file diff --git a/src/main/java/me/shurik/bettersuggestions/client/render/entity/MarkerEntityRenderer.java b/src/main/java/me/shurik/bettersuggestions/client/render/entity/MarkerEntityRenderer.java new file mode 100644 index 0000000..ce7e7fe --- /dev/null +++ b/src/main/java/me/shurik/bettersuggestions/client/render/entity/MarkerEntityRenderer.java @@ -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 { + protected MarkerEntityRenderer(EntityRendererFactory.Context context) { + super(context); + } + + @Override + public MarkerEntityRenderState getRenderState() { + return MarkerEntityRenderState.INSTANCE; + } +} diff --git a/src/main/java/me/shurik/bettersuggestions/client/render/state/MarkerEntityRenderState.java b/src/main/java/me/shurik/bettersuggestions/client/render/state/MarkerEntityRenderState.java new file mode 100644 index 0000000..02dd826 --- /dev/null +++ b/src/main/java/me/shurik/bettersuggestions/client/render/state/MarkerEntityRenderState.java @@ -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(); +} diff --git a/src/main/resources/better-suggestions.client.mixins.json b/src/main/resources/better-suggestions.client.mixins.json index 37915b5..ff53c37 100644 --- a/src/main/resources/better-suggestions.client.mixins.json +++ b/src/main/resources/better-suggestions.client.mixins.json @@ -9,6 +9,7 @@ "ChatScreenMixin", "ClientCommandSourceMixin", "ClientPlayNetworkHandlerMixin", + "EntityRenderDispatcherMixin", "EntityRendererMixin", "LanguageManagerMixin", "MinecraftClientMixin",