From cf54cc2b137f712ba2ece842bf56512e92fca4cb Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 15 Jan 2020 15:58:11 -0600 Subject: [PATCH] More work, fix gaia head tesrFix gaia head tesr --- .../api/item/AccessoryRenderHelper.java | 2 +- .../client/core/helper/IconHelper.java | 86 ------------------ .../client/core/helper/RenderHelper.java | 10 +- .../render/entity/RenderCorporeaSpark.java | 31 +++---- .../client/render/entity/RenderSparkBase.java | 89 ++++++++---------- .../render/tile/RenderTileGaiaHead.java | 91 +++++++++++++++---- .../render/tile/RenderTileTinyPotato.java | 2 +- .../botania/common/block/ModBlocks.java | 6 ++ .../botania/common/item/ItemTwigWand.java | 39 +++++++- .../vazkii/botania/common/item/ModItems.java | 2 - .../equipment/bauble/ItemFlightTiara.java | 49 ++++------ 11 files changed, 200 insertions(+), 207 deletions(-) diff --git a/src/main/java/vazkii/botania/api/item/AccessoryRenderHelper.java b/src/main/java/vazkii/botania/api/item/AccessoryRenderHelper.java index 1977158fc..486fe307f 100644 --- a/src/main/java/vazkii/botania/api/item/AccessoryRenderHelper.java +++ b/src/main/java/vazkii/botania/api/item/AccessoryRenderHelper.java @@ -12,7 +12,7 @@ public final class AccessoryRenderHelper { * Rotates the render for a bauble correctly if the player is sneaking. */ public static void rotateIfSneaking(LivingEntity player) { - if(player.shouldRenderSneaking()) + if(player.isCrouching()) applySneakingRotation(); } diff --git a/src/main/java/vazkii/botania/client/core/helper/IconHelper.java b/src/main/java/vazkii/botania/client/core/helper/IconHelper.java index 1598caa69..7a298c300 100644 --- a/src/main/java/vazkii/botania/client/core/helper/IconHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/IconHelper.java @@ -31,90 +31,4 @@ public final class IconHelper { buffer.vertex(mat, x + width, y, 0).color(1, 1, 1, alpha).texture(icon.getMaxU(), icon.getMinV()).light(fullbright).endVertex(); buffer.vertex(mat, x, y, 0).color(1, 1, 1, alpha).texture(icon.getMinU(), icon.getMinV()).light(fullbright).endVertex(); } - - // todo 1.15 remove this and just render real generated models added using addSpecialModel - /** - * Renders a sprite from the spritesheet with depth, like a "builtin/generated" item model. - * Adapted from ItemRenderer.renderItemIn2D, 1.7.10 - */ - @Deprecated - public static void renderIconIn3D(Tessellator tess, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, int width, int height, float thickness) { - /* - BufferBuilder wr = tess.getBuffer(); - wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - wr.pos(0.0D, 0.0D, 0.0D).tex(p_78439_1_, p_78439_4_).normal(0, 0, 1).endVertex(); - wr.pos(1.0D, 0.0D, 0.0D).tex(p_78439_3_, p_78439_4_).normal(0, 0, 1).endVertex(); - wr.pos(1.0D, 1.0D, 0.0D).tex(p_78439_3_, p_78439_2_).normal(0, 0, 1).endVertex(); - wr.pos(0.0D, 1.0D, 0.0D).tex(p_78439_1_, p_78439_2_).normal(0, 0, 1).endVertex(); - tess.draw(); - wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - wr.pos(0.0D, 1.0D, 0.0F - thickness).tex(p_78439_1_, p_78439_2_).normal(0, 0, -1).endVertex(); - wr.pos(1.0D, 1.0D, 0.0F - thickness).tex(p_78439_3_, p_78439_2_).normal(0, 0, -1).endVertex(); - wr.pos(1.0D, 0.0D, 0.0F - thickness).tex(p_78439_3_, p_78439_4_).normal(0, 0, -1).endVertex(); - wr.pos(0.0D, 0.0D, 0.0F - thickness).tex(p_78439_1_, p_78439_4_).normal(0, 0, -1).endVertex(); - tess.draw(); - float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / width; - float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / height; - wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - int k; - float f7; - float f8; - - for (k = 0; k < width; ++k) - { - f7 = (float)k / (float)width; - f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; - wr.pos(f7, 0.0D, 0.0F - thickness).tex(f8, p_78439_4_).normal(-1, 0, 0).endVertex(); - wr.pos(f7, 0.0D, 0.0D).tex(f8, p_78439_4_).normal(-1, 0, 0).endVertex(); - wr.pos(f7, 1.0D, 0.0D).tex(f8, p_78439_2_).normal(-1, 0, 0).endVertex(); - wr.pos(f7, 1.0D, 0.0F - thickness).tex(f8, p_78439_2_).normal(-1, 0, 0).endVertex(); - } - - tess.draw(); - wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - float f9; - - for (k = 0; k < width; ++k) - { - f7 = (float)k / (float)width; - f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; - f9 = f7 + 1.0F / width; - wr.pos(f9, 1.0D, 0.0F - thickness).tex(f8, p_78439_2_).normal(1, 0, 0).endVertex(); - wr.pos(f9, 1.0D, 0.0D).tex(f8, p_78439_2_).normal(1, 0, 0).endVertex(); - wr.pos(f9, 0.0D, 0.0D).tex(f8, p_78439_4_).normal(1, 0, 0).endVertex(); - wr.pos(f9, 0.0D, 0.0F - thickness).tex(f8, p_78439_4_).normal(1, 0, 0).endVertex(); - } - - tess.draw(); - wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - - for (k = 0; k < height; ++k) - { - f7 = (float)k / (float)height; - f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; - f9 = f7 + 1.0F / height; - wr.pos(0.0D, f9, 0.0D).tex(p_78439_1_, f8).normal(0, 1, 0).endVertex(); - wr.pos(1.0D, f9, 0.0D).tex(p_78439_3_, f8).normal(0, 1, 0).endVertex(); - wr.pos(1.0D, f9, 0.0F - thickness).tex(p_78439_3_, f8).normal(0, 1, 0).endVertex(); - wr.pos(0.0D, f9, 0.0F - thickness).tex(p_78439_1_, f8).normal(0, 1, 0).endVertex(); - } - - tess.draw(); - wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); - - for (k = 0; k < height; ++k) - { - f7 = (float)k / (float)height; - f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; - wr.pos(1.0D, f7, 0.0D).tex(p_78439_3_, f8).normal(0, -1, 0).endVertex(); - wr.pos(0.0D, f7, 0.0D).tex(p_78439_1_, f8).normal(0, -1, 0).endVertex(); - wr.pos(0.0D, f7, 0.0F - thickness).tex(p_78439_1_, f8).normal(0, -1, 0).endVertex(); - wr.pos(1.0D, f7, 0.0F - thickness).tex(p_78439_3_, f8).normal(0, -1, 0).endVertex(); - } - - tess.draw(); - */ - - } - } \ No newline at end of file diff --git a/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java b/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java index 586062736..c795b085e 100644 --- a/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/RenderHelper.java @@ -29,6 +29,7 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import org.lwjgl.opengl.GL11; import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.client.lib.LibResources; +import vazkii.botania.common.item.equipment.bauble.ItemFlightTiara; import java.util.Arrays; import java.util.List; @@ -43,6 +44,7 @@ public final class RenderHelper { public static final RenderType LINE_4; public static final RenderType LINE_5; public static final RenderType LINE_8; + public static final RenderType SPARK; public static final RenderType LIGHT_RELAY; public static final RenderType SPINNING_CUBE; public static final RenderType SPINNING_CUBE_GHOST; @@ -51,6 +53,7 @@ public final class RenderHelper { public static final RenderType MANA_POOL_WATER; public static final RenderType TERRA_PLATE; public static final RenderType ENCHANTER; + public static final RenderType HALO; // todo 1.15 AT's for necessary fields static { @@ -82,8 +85,9 @@ public final class RenderHelper { glState = RenderType.State.builder().lineWidth(new RenderState.LineState(OptionalDouble.of(8))).layering(projectionLayering).transparency(translucentTransparency).writeMaskState(colorMask).build(false); LINE_8 = RenderType.of(LibResources.PREFIX_MOD + "line_8", DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 64, glState); - glState = RenderType.State.builder().texture(mipmapBlockAtlasTexture).transparency(translucentTransparency).alpha(new RenderState.AlphaState(0.05F)).build(true); + glState = RenderType.State.builder().texture(mipmapBlockAtlasTexture).transparency(translucentTransparency).alpha(new RenderState.AlphaState(0.05F)).lightmap(enableLightmap).build(true); // todo 1.15: need normals? + SPARK = RenderType.of(LibResources.PREFIX_MOD + "spark", DefaultVertexFormats.POSITION_COLOR_TEXTURE_LIGHT, GL11.GL_QUADS, 256, glState); LIGHT_RELAY = new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.HALO, null, RenderType.of(LibResources.PREFIX_MOD + "light_relay", DefaultVertexFormats.POSITION_COLOR_TEXTURE_LIGHT, GL11.GL_QUADS, 64, glState)); glState = RenderType.State.builder().texture(new RenderState.TextureState()).build(false); @@ -102,6 +106,10 @@ public final class RenderHelper { MANA_POOL_WATER = new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.MANA_POOL, null, ICON_OVERLAY); TERRA_PLATE = new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.TERRA_PLATE, null, ICON_OVERLAY); ENCHANTER = new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.ENCHANTER_RUNE, null, ICON_OVERLAY); + + RenderState.TextureState haloTexture = new RenderState.TextureState(ItemFlightTiara.textureHalo, false, true); + glState = RenderType.State.builder().texture(haloTexture).transparency(translucentTransparency).cull(disableCull).shadeModel(smoothShade).build(true); + HALO = new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.HALO, null, RenderType.of(LibResources.PREFIX_MOD + "halo", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 64, glState)); } public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) { diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java b/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java index 88279601b..41cb3a5f5 100644 --- a/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java +++ b/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java @@ -10,9 +10,12 @@ */ package vazkii.botania.client.render.entity; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -34,7 +37,7 @@ public class RenderCorporeaSpark extends RenderSparkBase { } @Override - public void renderCallback(EntityCorporeaSpark entity, float pticks) { + public void renderCallback(EntityCorporeaSpark entity, float pticks, MatrixStack ms, IRenderTypeBuffer buffers) { int time = entity.getItemDisplayTicks(); if(time == 0) return; @@ -45,16 +48,13 @@ public class RenderCorporeaSpark extends RenderSparkBase { if(stack.isEmpty()) return; - GlStateManager.pushMatrix(); - GlStateManager.rotatef(90F, 1F, 0F, 0F); + ms.push(); + ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90)); float scalef = 1F / 6F; - GlStateManager.scalef(scalef, scalef, scalef); - GlStateManager.enableBlend(); - GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + ms.scale(scalef, scalef, scalef); GlStateManager.color4f(1F, 1F, 1F, absTime / 10); - GlStateManager.translatef(0F, 0F, -2F + (time < 0 ? -absTime : absTime) / 6); + ms.translate(0F, 0F, -2F + (time < 0 ? -absTime : absTime) / 6); - Minecraft.getInstance().textureManager.bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); TextureAtlasSprite icon = Minecraft.getInstance().getItemRenderer().getItemModelWithOverrides(stack, entity.world, null).getParticleTexture(); if(icon != null) { @@ -70,20 +70,19 @@ public class RenderCorporeaSpark extends RenderSparkBase { int shift = pieces / 2; float scale = 1F / pieces * 3F; - GlStateManager.scalef(scale, scale, 1F); + ms.scale(scale, scale, 1F); for(int i = -shift; i < shift; i++) { - GlStateManager.translatef(gap * i, 0F, 0F); + ms.translate(gap * i, 0F, 0F); for(int j = -shift; j < shift; j++) { - GlStateManager.translatef(0F, gap * j, 0F); - IconHelper.renderIconIn3D(Tessellator.getInstance(), minU + stepU * (i + shift), minV + stepV * (j + shift + 1), minU + stepU * (i + shift + 1), minV + stepV * (j + shift), icon.getWidth() / pieces, icon.getHeight() / pieces, 1F / 8F); - GlStateManager.translatef(0F, -gap * j, 0F); + ms.translate(0F, gap * j, 0F); + // todo 1.15 do this another way IconHelper.renderIconIn3D(Tessellator.getInstance(), minU + stepU * (i + shift), minV + stepV * (j + shift + 1), minU + stepU * (i + shift + 1), minV + stepV * (j + shift), icon.getWidth() / pieces, icon.getHeight() / pieces, 1F / 8F); + ms.translate(0F, -gap * j, 0F); } - GlStateManager.translatef(-gap * i, 0F, 0F); + ms.translate(-gap * i, 0F, 0F); } } - GlStateManager.disableBlend(); - GlStateManager.popMatrix(); + ms.pop(); } } diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java b/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java index 9c84e1a9d..cd685a34f 100644 --- a/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java +++ b/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java @@ -10,7 +10,11 @@ */ package vazkii.botania.client.render.entity; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.vertex.IVertexBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; @@ -20,6 +24,7 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.client.core.handler.MiscellaneousIcons; +import vazkii.botania.client.core.helper.RenderHelper; import vazkii.botania.client.core.proxy.ClientProxy; import vazkii.botania.common.entity.EntitySparkBase; @@ -34,75 +39,55 @@ public abstract class RenderSparkBase extends EntityR } @Override - public void doRender(@Nonnull T tEntity, double par2, double par4, double par6, float par8, float par9) { + public void render(@Nonnull T tEntity, float yaw, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int light) { TextureAtlasSprite iicon = getBaseIcon(tEntity); - GlStateManager.pushMatrix(); - GlStateManager.translated(par2, par4, par6); - GlStateManager.enableRescaleNormal(); - GlStateManager.enableBlend(); - GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.alphaFunc(GL11.GL_GREATER, 0.05F); - - double time = ClientTickHandler.ticksInGame + par9; - time += new Random(tEntity.getEntityId()).nextInt(); + ms.push(); + double time = ClientTickHandler.ticksInGame + partialTicks + new Random(tEntity.getEntityId()).nextInt(); float a = 0.1F + (tEntity.isInvisible() ? 0 : 1) * 0.8F; - GlStateManager.color4f(1F, 1F, 1F, (0.7F + 0.3F * (float) (Math.sin(time / 5.0) + 0.5) * 2) * a); + int alpha = (int) ((0.7F + 0.3F * (float) (Math.sin(time / 5.0) + 0.5) * 2) * a * 255.0F); + int iconColor = 0xFFFFFF | (alpha << 24); float scale = 0.75F + 0.1F * (float) Math.sin(time / 10); - GlStateManager.scalef(scale, scale, scale); - bindEntityTexture(tEntity); - Tessellator tessellator = Tessellator.getInstance(); + ms.scale(scale, scale, scale); - GlStateManager.pushMatrix(); - float r = 180.0F - renderManager.playerViewY; - GlStateManager.rotatef(r, 0.0F, 1.0F, 0.0F); - GlStateManager.rotatef(-renderManager.playerViewX, 1F, 0F, 0F); - renderIcon(tessellator, iicon); + IVertexBuilder buffer = buffers.getBuffer(RenderHelper.SPARK); + ms.push(); + ms.multiply(renderManager.getRotation()); + renderIcon(ms, buffer, iicon, iconColor); - GlStateManager.pushMatrix(); - GlStateManager.translatef(-0.02F + (float) Math.sin(time / 20) * 0.2F, 0.24F + (float) Math.cos(time / 20) * 0.2F, 0.005F); - GlStateManager.scalef(0.2F, 0.2F, 0.2F); - colorStar(tEntity, a); - renderIcon(tessellator, MiscellaneousIcons.INSTANCE.corporeaIconStar); - GlStateManager.popMatrix(); + ms.push(); + ms.translate(-0.02F + (float) Math.sin(time / 20) * 0.2F, 0.24F + (float) Math.cos(time / 20) * 0.2F, 0.005F); + ms.scale(0.2F, 0.2F, 0.2F); + int starColor = tEntity.getNetwork().colorValue | ((int) (a * 255.0F) << 24); + renderIcon(ms, buffer, MiscellaneousIcons.INSTANCE.corporeaIconStar, starColor); + ms.pop(); TextureAtlasSprite spinningIcon = getSpinningIcon(tEntity); if (spinningIcon != null) { - GlStateManager.translatef(-0.02F + (float) Math.sin(time / 20) * -0.2F, 0.24F + (float) Math.cos(time / 20) * -0.2F, 0.005F); - GlStateManager.scalef(0.2F, 0.2F, 0.2F); - renderIcon(tessellator, spinningIcon); + ms.translate(-0.02F + (float) Math.sin(time / 20) * -0.2F, 0.24F + (float) Math.cos(time / 20) * -0.2F, 0.005F); + ms.scale(0.2F, 0.2F, 0.2F); + renderIcon(ms, buffer, spinningIcon, iconColor); } - GlStateManager.popMatrix(); - GlStateManager.color4f(1F, 1F, 1F, 1F); - renderCallback(tEntity, par9); + ms.pop(); + renderCallback(tEntity, partialTicks, ms, buffers); - GlStateManager.disableBlend(); - GlStateManager.disableRescaleNormal(); - GlStateManager.popMatrix(); + ms.pop(); } protected TextureAtlasSprite getBaseIcon(T entity) { return MiscellaneousIcons.INSTANCE.sparkWorldIcon; } - private void colorStar(T entity, float a) { - int hex = entity.getNetwork().colorValue; - int r = (hex & 0xFF0000) >> 16; - int g = (hex & 0xFF00) >> 8; - int b = hex & 0xFF; - GlStateManager.color4f(r / 255F, g / 255F, b / 255F, a); - } - @Nullable protected TextureAtlasSprite getSpinningIcon(T entity) { return null; } - protected void renderCallback(T entity, float pticks) {} + protected void renderCallback(T entity, float pticks, MatrixStack ms, IRenderTypeBuffer buffers) {} @Nonnull @Override @@ -110,7 +95,7 @@ public abstract class RenderSparkBase extends EntityR return AtlasTexture.LOCATION_BLOCKS_TEXTURE; } - private void renderIcon(Tessellator tess, TextureAtlasSprite icon) { + private void renderIcon(MatrixStack ms, IVertexBuilder buffer, TextureAtlasSprite icon, int color) { float f = icon.getMinU(); float f1 = icon.getMaxU(); float f2 = icon.getMinV(); @@ -118,13 +103,17 @@ public abstract class RenderSparkBase extends EntityR float f4 = 1.0F; float f5 = 0.5F; float f6 = 0.25F; + int fullbright = 0xF000F0; + int a = (color >> 24) & 0xFF; + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = color & 0xFF; - tess.getBuffer().begin(GL11.GL_QUADS, ClientProxy.POSITION_TEX_LMAP_NORMAL); - tess.getBuffer().pos(0.0F - f5, 0.0F - f6, 0.0D).tex(f, f3).lightmap(240, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); - tess.getBuffer().pos(f4 - f5, 0.0F - f6, 0.0D).tex(f1, f3).lightmap(240, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); - tess.getBuffer().pos(f4 - f5, f4 - f6, 0.0D).tex(f1, f2).lightmap(240, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); - tess.getBuffer().pos(0.0F - f5, f4 - f6, 0.0D).tex(f, f2).lightmap(240, 240).normal(0.0F, 1.0F, 0.0F).endVertex(); - tess.draw(); + Matrix4f mat = ms.peek().getModel(); + buffer.vertex(mat, 0.0F - f5, 0.0F - f6, 0.0F).color(r, g, b, a).texture(f, f3).light(fullbright).endVertex(); + buffer.vertex(mat, f4 - f5, 0.0F - f6, 0.0F).color(r, g, b, a).texture(f1, f3).light(fullbright).endVertex(); + buffer.vertex(mat, f4 - f5, f4 - f6, 0.0F).color(r, g, b, a).texture(f1, f2).light(fullbright).endVertex(); + buffer.vertex(mat, 0.0F - f5, f4 - f6, 0.0F).color(r, g, b, a).texture(f, f2).light(fullbright).endVertex(); } } diff --git a/src/main/java/vazkii/botania/client/render/tile/RenderTileGaiaHead.java b/src/main/java/vazkii/botania/client/render/tile/RenderTileGaiaHead.java index f329abd1e..8d1c44e8d 100644 --- a/src/main/java/vazkii/botania/client/render/tile/RenderTileGaiaHead.java +++ b/src/main/java/vazkii/botania/client/render/tile/RenderTileGaiaHead.java @@ -11,12 +11,23 @@ package vazkii.botania.client.render.tile; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; +import net.minecraft.block.AbstractSkullBlock; +import net.minecraft.block.BlockState; import net.minecraft.block.SkullBlock; +import net.minecraft.block.WallSkullBlock; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.model.GenericHeadModel; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.entity.Entity; import net.minecraft.entity.boss.WitherEntity; import net.minecraft.entity.boss.dragon.EnderDragonEntity; @@ -25,37 +36,42 @@ import net.minecraft.entity.monster.SkeletonEntity; import net.minecraft.entity.monster.WitherSkeletonEntity; import net.minecraft.entity.monster.ZombieEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.tileentity.SkullTileEntity; import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import vazkii.botania.client.core.helper.ShaderHelper; +import vazkii.botania.client.core.helper.ShaderWrappedRenderLayer; import vazkii.botania.client.render.entity.RenderDoppleganger; import vazkii.botania.common.block.BlockGaiaHead; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Map; public class RenderTileGaiaHead extends SkullTileEntityRenderer { - private SkullTileEntityRenderer original = null; + private static final Map MODELS = ObfuscationReflectionHelper.getPrivateValue(SkullTileEntityRenderer.class, null, "field_199358_e"); + private static final Map SKINS = ObfuscationReflectionHelper.getPrivateValue(SkullTileEntityRenderer.class, null, "field_199357_d"); public RenderTileGaiaHead(TileEntityRendererDispatcher manager) { super(manager); } @Override - public void render(float x, float y, float z, @Nullable Direction facing, float rotationIn, SkullBlock.ISkullType type, @Nullable GameProfile profile, int destroyStage, float animationProgress) { - // we overwrite the vanilla `instance` singleton in setRendererDispatcher, so call back to the original one if type isn't gaia - if (type != BlockGaiaHead.GAIA_TYPE) { - original.render(x, y, z, facing, rotationIn, type, profile, destroyStage, animationProgress); - return; - } + public void render(@Nullable SkullTileEntity skull, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int light, int overlay) { + // [VanillaCopy] super, but null safe and call our own render method with appropriate overridden type and profile + float f = skull == null ? 0 : skull.getAnimationProgress(partialTicks); + BlockState blockstate = skull == null ? null : skull.getBlockState(); + boolean flag = blockstate != null && blockstate.getBlock() instanceof WallSkullBlock; + Direction direction = flag ? blockstate.get(WallSkullBlock.FACING) : null; + float f1 = 22.5F * (float)(flag ? (2 + direction.getHorizontalIndex()) * 4 : blockstate == null ? 0 : blockstate.get(SkullBlock.ROTATION)); - Minecraft mc = Minecraft.getInstance(); - Entity view = mc.getRenderViewEntity(); + Entity view = Minecraft.getInstance().getRenderViewEntity(); + SkullBlock.ISkullType type = SkullBlock.Types.PLAYER; + GameProfile profile = null; - profile = null; - - type = SkullBlock.Types.PLAYER; if(view instanceof PlayerEntity) { - profile = ((PlayerEntity) mc.getRenderViewEntity()).getGameProfile(); + profile = ((PlayerEntity) view).getGameProfile(); } else if (view instanceof SkeletonEntity) type = SkullBlock.Types.SKELETON; else if(view instanceof WitherSkeletonEntity) @@ -69,8 +85,51 @@ public class RenderTileGaiaHead extends SkullTileEntityRenderer { else if(view instanceof EnderDragonEntity) type = SkullBlock.Types.DRAGON; - ShaderHelper.useShader(ShaderHelper.BotaniaShader.DOPPLEGANGER, RenderDoppleganger.defaultCallback); - original.render(x, y, z, facing, rotationIn, type, profile, destroyStage, animationProgress); - ShaderHelper.releaseShader(); + gaiaRender(direction, f1, type, profile, f, ms, buffers, light); + } + + // [VanillaCopy] super, but calling our own method to get RenderType + private static void gaiaRender(@Nullable Direction facing, float rotation, SkullBlock.ISkullType type, @Nullable GameProfile profile, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int light) { + GenericHeadModel genericheadmodel = MODELS.get(type); + ms.push(); + if (facing == null) { + ms.translate(0.5D, 0.0D, 0.5D); + } else { + switch(facing) { + case NORTH: + ms.translate(0.5D, 0.25D, (double)0.74F); + break; + case SOUTH: + ms.translate(0.5D, 0.25D, (double)0.26F); + break; + case WEST: + ms.translate((double)0.74F, 0.25D, 0.5D); + break; + case EAST: + default: + ms.translate((double)0.26F, 0.25D, 0.5D); + } + } + + ms.scale(-1.0F, -1.0F, 1.0F); + IVertexBuilder ivertexbuilder = buffers.getBuffer(layerFor(type, profile)); + genericheadmodel.render(partialTicks, rotation, 0.0F); + genericheadmodel.render(ms, ivertexbuilder, light, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F); + ms.pop(); + } + + // [VanillaCopy] super but wrapped in a shader + private static RenderType layerFor(SkullBlock.ISkullType type, @Nullable GameProfile profile) { + RenderType base; + ResourceLocation resourcelocation = SKINS.get(type); + if (type == SkullBlock.Types.PLAYER && profile != null) { + Minecraft minecraft = Minecraft.getInstance(); + Map map = minecraft.getSkinManager().loadSkinFromCache(profile); + base = map.containsKey(MinecraftProfileTexture.Type.SKIN) ? RenderType.getEntityTranslucent(minecraft.getSkinManager().loadSkin(map.get(MinecraftProfileTexture.Type.SKIN), MinecraftProfileTexture.Type.SKIN)) : RenderType.getEntityCutoutNoCull(DefaultPlayerSkin.getDefaultSkin(PlayerEntity.getUUID(profile))); + } else { + base = RenderType.getEntityCutoutNoCull(resourcelocation); + } + + return new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.DOPPLEGANGER, RenderDoppleganger.defaultCallback, base); } } \ No newline at end of file diff --git a/src/main/java/vazkii/botania/client/render/tile/RenderTileTinyPotato.java b/src/main/java/vazkii/botania/client/render/tile/RenderTileTinyPotato.java index a93639584..64c894788 100644 --- a/src/main/java/vazkii/botania/client/render/tile/RenderTileTinyPotato.java +++ b/src/main/java/vazkii/botania/client/render/tile/RenderTileTinyPotato.java @@ -337,7 +337,7 @@ public class RenderTileTinyPotato extends TileEntityRenderer { ms.scale(1.5F, 1.5F, 1.5F); ms.translate(0F, -0.8F, 0F); ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90)); - ItemFlightTiara.renderHalo(null, partialTicks); + ItemFlightTiara.renderHalo(null, ms, buffers, partialTicks); } else if (name.equals("kingdaddydmac")) { ms.scale(0.5F, 0.5F, 0.5F); ms.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180)); diff --git a/src/main/java/vazkii/botania/common/block/ModBlocks.java b/src/main/java/vazkii/botania/common/block/ModBlocks.java index 49e951aa6..111cc1886 100644 --- a/src/main/java/vazkii/botania/common/block/ModBlocks.java +++ b/src/main/java/vazkii/botania/common/block/ModBlocks.java @@ -18,6 +18,7 @@ import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.item.DyeColor; import net.minecraft.item.Item; +import net.minecraft.item.Rarity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -97,6 +98,7 @@ import vazkii.botania.common.block.tile.string.TileRedStringDispenser; import vazkii.botania.common.block.tile.string.TileRedStringFertilizer; import vazkii.botania.common.block.tile.string.TileRedStringInterceptor; import vazkii.botania.common.block.tile.string.TileRedStringRelay; +import vazkii.botania.common.item.ItemGaiaHead; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.block.ItemBlockDreamwood; import vazkii.botania.common.item.block.ItemBlockElven; @@ -819,6 +821,8 @@ public final class ModBlocks { register(r, new ItemBlockMod(brewery, props), brewery.getRegistryName()); register(r, new ItemBlockMod(corporeaIndex, props), corporeaIndex.getRegistryName()); register(r, new ItemBlockMod(hourglass, props), hourglass.getRegistryName()); + Item head = new ItemGaiaHead(gaiaHead, gaiaHeadWall, ModItems.defaultBuilder().rarity(Rarity.UNCOMMON)); + register(r, head, gaiaHead.getRegistryName()); return null; } @@ -835,6 +839,8 @@ public final class ModBlocks { register(r, new ItemBlockMod(brewery, ModItems.defaultBuilder().setTEISR(() -> () -> new TEISR(ModBlocks.brewery, TileBrewery.TYPE))), brewery.getRegistryName()); register(r, new ItemBlockMod(corporeaIndex, ModItems.defaultBuilder().setTEISR(() -> () -> new TEISR(ModBlocks.corporeaIndex, TileCorporeaIndex.TYPE))), corporeaIndex.getRegistryName()); register(r, new ItemBlockMod(hourglass, ModItems.defaultBuilder().setTEISR(() -> () -> new TEISR(ModBlocks.hourglass, TileHourglass.TYPE))), hourglass.getRegistryName()); + Item head = new ItemGaiaHead(gaiaHead, gaiaHeadWall, ModItems.defaultBuilder().rarity(Rarity.UNCOMMON).setTEISR(() -> () -> new TEISR(ModBlocks.gaiaHead, TileGaiaHead.TYPE))); + register(r, head, gaiaHead.getRegistryName()); return null; } diff --git a/src/main/java/vazkii/botania/common/item/ItemTwigWand.java b/src/main/java/vazkii/botania/common/item/ItemTwigWand.java index e35cc365d..5fbb8baf6 100644 --- a/src/main/java/vazkii/botania/common/item/ItemTwigWand.java +++ b/src/main/java/vazkii/botania/common/item/ItemTwigWand.java @@ -233,8 +233,9 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem { if (prop.getName().equals("facing") && prop.getValueClass() == Direction.class) { IProperty facingProp = (IProperty) prop; - Direction newDir = old.get(facingProp).rotateAround(axis); - if (facingProp.getAllowedValues().contains(newDir)) { + Direction oldDir = old.get(facingProp); + Direction newDir = rotateAround(oldDir, axis); + if (oldDir != newDir && facingProp.getAllowedValues().contains(newDir)) { return old.with(facingProp, newDir); } } @@ -243,6 +244,40 @@ public class ItemTwigWand extends ItemMod implements ICoordBoundItem { return old.rotate(Rotation.CLOCKWISE_90); } + private static Direction rotateAround(Direction old, Direction.Axis axis) { + switch (axis) { + case X: { + switch (old) { + case DOWN: return Direction.SOUTH; + case SOUTH: return Direction.UP; + case UP: return Direction.NORTH; + case NORTH: return Direction.DOWN; + } + break; + } + case Y: { + switch (old) { + case NORTH: return Direction.EAST; + case EAST: return Direction.SOUTH; + case SOUTH: return Direction.WEST; + case WEST: return Direction.NORTH; + } + break; + } + case Z: { + switch (old) { + case DOWN: return Direction.WEST; + case WEST: return Direction.UP; + case UP: return Direction.EAST; + case EAST: return Direction.DOWN; + } + break; + } + } + + return old; + } + public static void doParticleBeamWithOffset(World world, BlockPos orig, BlockPos end) { Vec3d origOffset = world.getBlockState(orig).getOffset(world, orig); Vector3 vorig = new Vector3(orig.getX() + origOffset.getX() + 0.5, orig.getY() + origOffset.getY() + 0.5, orig.getZ() + origOffset.getZ() + 0.5); diff --git a/src/main/java/vazkii/botania/common/item/ModItems.java b/src/main/java/vazkii/botania/common/item/ModItems.java index ce7a296b9..40b810895 100644 --- a/src/main/java/vazkii/botania/common/item/ModItems.java +++ b/src/main/java/vazkii/botania/common/item/ModItems.java @@ -709,8 +709,6 @@ public final class ModItems { register(r, new ItemManaweaveArmor(EquipmentSlotType.LEGS, unstackable()), LibItemNames.MANAWEAVE_LEGS); register(r, new ItemManaweaveArmor(EquipmentSlotType.FEET, unstackable()), LibItemNames.MANAWEAVE_BOOTS); register(r, new ItemAutocraftingHalo(unstackable()), LibItemNames.AUTOCRAFTING_HALO); - Item head = new ItemGaiaHead(ModBlocks.gaiaHead, ModBlocks.gaiaHeadWall, defaultBuilder().rarity(Rarity.UNCOMMON)); - register(r, head, ModBlocks.gaiaHead.getRegistryName()); register(r, new ItemSextant(unstackable()), LibItemNames.SEXTANT); register(r, new ItemSpeedUpBelt(unstackable()), LibItemNames.SPEED_UP_BELT); register(r, new ItemBaubleBox(unstackable()), LibItemNames.BAUBLE_BOX); diff --git a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemFlightTiara.java b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemFlightTiara.java index f4cdbdb06..4e09f783e 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemFlightTiara.java +++ b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemFlightTiara.java @@ -18,6 +18,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.renderer.Atlases; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.model.IBakedModel; @@ -63,6 +64,7 @@ import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.item.ModItems; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -70,7 +72,7 @@ import java.util.List; public class ItemFlightTiara extends ItemBauble implements IManaUsingItem { private static final ResourceLocation textureHud = new ResourceLocation(LibResources.GUI_HUD_ICONS); - private static final ResourceLocation textureHalo = new ResourceLocation(LibResources.MISC_HALO); + public static final ResourceLocation textureHalo = new ResourceLocation(LibResources.MISC_HALO); private static final String TAG_VARIANT = "variant"; private static final String TAG_FLYING = "flying"; @@ -412,44 +414,27 @@ public class ItemFlightTiara extends ItemBauble implements IManaUsingItem { ms.pop(); if(meta == 1) - renderHalo(player, partialTicks); + renderHalo(player, ms, buffers, partialTicks); } } @OnlyIn(Dist.CLIENT) - public static void renderHalo(LivingEntity player, float partialTicks) { - GlStateManager.enableBlend(); - GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.shadeModel(GL11.GL_SMOOTH); - GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, 240, 240); - GlStateManager.disableLighting(); - GlStateManager.disableCull(); - GlStateManager.color4f(1F, 1F, 1F, 1F); - - Minecraft.getInstance().textureManager.bindTexture(textureHalo); - + public static void renderHalo(@Nullable LivingEntity player, MatrixStack ms, IRenderTypeBuffer buffers, float partialTicks) { if(player != null) AccessoryRenderHelper.translateToHeadLevel(player, partialTicks); - GlStateManager.translatef(0, 1.5F, 0); - GlStateManager.rotatef(30, 1, 0, -1); - GlStateManager.translatef(-0.1F, -0.5F, -0.1F); + ms.translate(0, 1.5F, 0); + ms.multiply(new Vector3f(1, 0, -1).getDegreesQuaternion(30)); + ms.translate(-0.1F, -0.5F, -0.1F); if(player != null) - GlStateManager.rotatef(player.ticksExisted + partialTicks, 0, 1, 0); - else GlStateManager.rotatef(Botania.proxy.getWorldElapsedTicks(), 0, 1, 0); - - Tessellator tes = Tessellator.getInstance(); - ShaderHelper.useShader(ShaderHelper.BotaniaShader.HALO); - tes.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); - tes.getBuffer().pos(-0.75, 0, -0.75).tex(0, 0).endVertex(); - tes.getBuffer().pos(-0.75, 0, 0.75).tex(0, 1).endVertex(); - tes.getBuffer().pos(0.75, 0, 0.75).tex(1, 1).endVertex(); - tes.getBuffer().pos(0.75, 0, -0.75).tex(1, 0).endVertex(); - tes.draw(); - ShaderHelper.releaseShader(); - - GlStateManager.enableLighting(); - GlStateManager.shadeModel(GL11.GL_FLAT); - GlStateManager.enableCull(); + ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(player.ticksExisted + partialTicks)); + else ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(Botania.proxy.getWorldElapsedTicks())); + + IVertexBuilder buffer = buffers.getBuffer(RenderHelper.HALO); + Matrix4f mat = ms.peek().getModel(); + buffer.vertex(mat, -0.75F, 0, -0.75F).texture(0, 0).endVertex(); + buffer.vertex(mat, -0.75F, 0, 0.75F).texture(0, 1).endVertex(); + buffer.vertex(mat, 0.75F, 0, 0.75F).texture(1, 1).endVertex(); + buffer.vertex(mat, 0.75F, 0, -0.75F).texture(1, 0).endVertex(); } @OnlyIn(Dist.CLIENT)