I am looking to create the Minecraft Bedrock's Actions and Stuff enchantment outline (photo for reference) as a mod. I was wondering how I can set up the code to
use a shader when it detects a handheld item. I was attempting to create a framebuffer for it, but I am not really sure what I am doing (esp for 1.21.5). Here is what I got so far if anyone can help (questions in code below, but any help is greatly appreciated)!
@Shadow @Final private MinecraftClient client;
@Unique
private static int
width = MinecraftClient.getInstance().getWindow().getFramebufferWidth(),
height = MinecraftClient.getInstance().getWindow().getFramebufferHeight();
@Unique
private static final SimpleFramebuffer enchantedItemFBO = new SimpleFramebuffer("enchanted_fbo", width, height, true);
@Inject(method = "renderItem(" +
"FLnet/minecraft/client/util/math/MatrixStack;" +
"Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;" +
"Lnet/minecraft/client/network/ClientPlayerEntity;I)V",
at = @At("HEAD"))
private void beforeRender(
float tickProgress,
MatrixStack matrices,
VertexConsumerProvider.Immediate vertexConsumers,
ClientPlayerEntity player, int light,
CallbackInfo ci
) {
ItemStack MainHand = player.getMainHandStack();
ItemStack OffHand = player.getOffHandStack();
if ((MainHand != null && MainHand.hasGlint()) ||
(OffHand != null && OffHand.hasGlint())) {
enchantedItemFBO.initFbo(width, height);
RenderSystem.getDevice().createCommandEncoder().createRenderPass(colorAttachment, OptionalInt.empty());
//TODO: HOW DO I MAKE IT READ .vsh / .fsh / .glsl file (in the correct order) here.
// 1. Is this the right method to inject? Will this work while the item is swinging?
// 2. Is at = @At("HEAD") the right one?
// 3. I read somewhere that WorldRenderEvents.AFTER_ENTITIES.register to be used but I am not sure.
}
}