From 8212d39d95fc27890aae394e97a2bf7815581535 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 16 May 2020 09:57:06 +0200 Subject: [PATCH] Ported superglue entityrenderer --- .../com/simibubi/create/config/CClient.java | 2 - .../foundation/utility/AngleHelper.java | 11 ++ .../contraptions/glue/SuperGlueRenderer.java | 95 ++++++++++-------- .../textures/entity/super_glue/ghostly.png | Bin 367 -> 0 bytes 4 files changed, 65 insertions(+), 43 deletions(-) delete mode 100644 src/main/resources/assets/create/textures/entity/super_glue/ghostly.png diff --git a/src/main/java/com/simibubi/create/config/CClient.java b/src/main/java/com/simibubi/create/config/CClient.java index 9d8a451aa..718a2b33d 100644 --- a/src/main/java/com/simibubi/create/config/CClient.java +++ b/src/main/java/com/simibubi/create/config/CClient.java @@ -12,8 +12,6 @@ public class CClient extends ConfigBase { public ConfigFloat fanParticleDensity = f(.5f, 0, 1, "fanParticleDensity"); public ConfigBool rainbowDebug = b(true, "enableRainbowDebug", "Show colourful debug information while the F3-Menu is open."); - public ConfigBool showHiddenSuperGlue = - b(false, "showHiddenSuperGlue", "Show indications for hidden glue between blocks while holding the item."); @Override public String getName() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java b/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java index 580c4d3cb..62e672da3 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java @@ -1,9 +1,20 @@ package com.simibubi.create.foundation.utility; +import com.mojang.blaze3d.matrix.MatrixStack; + +import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; public class AngleHelper { + + @OnlyIn(Dist.CLIENT) + public static void applyRotation(Direction direction, MatrixStack ms) { + ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(direction))); + ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(AngleHelper.verticalAngle(direction))); + } public static float horizontalAngle(Direction facing) { float angle = facing.getHorizontalAngle(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java index e6569e874..ee0762d5e 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java @@ -1,23 +1,27 @@ package com.simibubi.create.modules.contraptions.components.contraptions.glue; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.matrix.MatrixStack.Entry; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllItems; import com.simibubi.create.Create; -import com.simibubi.create.config.AllConfigs; +import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -25,10 +29,11 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class SuperGlueRenderer extends EntityRenderer { private ResourceLocation regular = new ResourceLocation(Create.ID, "textures/entity/super_glue/slime.png"); - private ResourceLocation ghostly = new ResourceLocation(Create.ID, "textures/entity/super_glue/ghostly.png"); private Vec3d[] quad1; private Vec3d[] quad2; + private float[] u = { 0, 1, 1, 0 }; + private float[] v = { 0, 0, 1, 1 }; public SuperGlueRenderer(EntityRendererManager renderManager) { super(renderManager); @@ -37,55 +42,65 @@ public class SuperGlueRenderer extends EntityRenderer { @Override public ResourceLocation getEntityTexture(SuperGlueEntity entity) { - return isVisible(entity) ? regular : ghostly; + return regular; } - @Override // TODO what are these floats for? + @Override public void render(SuperGlueEntity entity, float p_225623_2_, float p_225623_3_, MatrixStack ms, - IRenderTypeBuffer buffer, int light) { + IRenderTypeBuffer buffer, int light) { super.render(entity, p_225623_2_, p_225623_3_, ms, buffer, light); - IVertexBuilder builder = buffer.getBuffer(RenderType.getEntityCutout(getEntityTexture(entity))); PlayerEntity player = Minecraft.getInstance().player; boolean visible = isVisible(entity); boolean holdingGlue = AllItems.SUPER_GLUE.typeOf(player.getHeldItemMainhand()) - || AllItems.SUPER_GLUE.typeOf(player.getHeldItemOffhand()); - holdingGlue = holdingGlue && AllConfigs.CLIENT.showHiddenSuperGlue.get(); + || AllItems.SUPER_GLUE.typeOf(player.getHeldItemOffhand()); if (!visible && !holdingGlue) return; - -// GlStateManager.pushMatrix(); TODO find equivalent -// GlStateManager.translated(x, y, z); -// GlStateManager.rotated(AngleHelper.horizontalAngle(facing), 0, 1, 0); -// GlStateManager.rotated(AngleHelper.verticalAngle(facing), 1, 0, 0); -// if (!visible) { -// GlStateManager.color4f(1, 1, 1, 0.375f); -// GlStateManager.enableBlend(); -// GlStateManager.disableDepthTest(); -// } - // TODO use quad1 & quad2 to render the glue texture + IVertexBuilder builder = buffer.getBuffer(RenderType.getEntityCutout(getEntityTexture(entity))); + light = getBrightnessForRender(entity); + Direction face = entity.getFacingDirection(); + + ms.push(); + AngleHelper.applyRotation(face, ms); + Entry peek = ms.peek(); -// GlStateManager.disableBlend(); -// GlStateManager.enableDepthTest(); -// GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); -// GlStateManager.popMatrix(); + Vec3d[][] quads = { quad1, quad2 }; + for (Vec3d[] quad : quads) { + for (int i = 0; i < 4; i++) { + Vec3d vertex = quad[i]; + builder.vertex(peek.getModel(), (float) vertex.x, (float) vertex.y, (float) vertex.z) + .color(255, 255, 255, 255) + .texture(u[i], v[i]) + .overlay(OverlayTexture.DEFAULT_UV) + .light(light) + .normal(peek.getNormal(), face.getXOffset(), face.getYOffset(), face.getZOffset()) + .endVertex(); + } + face = face.getOpposite(); + } + ms.pop(); } private boolean isVisible(SuperGlueEntity entity) { if (!entity.isAlive()) return false; BlockPos pos = entity.hangingPosition; - BlockPos pos2 = pos.offset(entity.getFacingDirection().getOpposite()); - return !SuperGlueEntity.isValidFace(entity.world, pos2, entity.getFacingDirection()) || !SuperGlueEntity.isValidFace(entity.world, pos, entity.getFacingDirection().getOpposite()); + BlockPos pos2 = pos.offset(entity.getFacingDirection() + .getOpposite()); + return !SuperGlueEntity.isValidFace(entity.world, pos2, entity.getFacingDirection()) + || !SuperGlueEntity.isValidFace(entity.world, pos, entity.getFacingDirection() + .getOpposite()); } private void initQuads() { Vec3d diff = new Vec3d(Direction.SOUTH.getDirectionVec()); - Vec3d extension = diff.normalize().scale(1 / 32f - 1 / 128f); + Vec3d extension = diff.normalize() + .scale(1 / 32f - 1 / 128f); Vec3d plane = VecHelper.planeByNormal(diff); - Axis axis = Direction.getFacingFromVector(diff.x, diff.y, diff.z).getAxis(); + Axis axis = Direction.getFacingFromVector(diff.x, diff.y, diff.z) + .getAxis(); Vec3d start = Vec3d.ZERO.subtract(extension); Vec3d end = Vec3d.ZERO.add(extension); @@ -103,21 +118,19 @@ public class SuperGlueRenderer extends EntityRenderer { Vec3d a4 = plane.add(start); Vec3d b4 = plane.add(end); - quad1 = new Vec3d[] { a1, a2, a3, a4 }; - quad2 = new Vec3d[] { b1, b2, b3, b4 }; + quad1 = new Vec3d[] { a2, a3, a4, a1 }; + quad2 = new Vec3d[] { b3, b2, b1, b4 }; + } -// PositionTextureVertex v11 = new PositionTextureVertex(a1, 1, 0); -// PositionTextureVertex v12 = new PositionTextureVertex(a2, 1, 1); -// PositionTextureVertex v13 = new PositionTextureVertex(a3, 0, 1); -// PositionTextureVertex v14 = new PositionTextureVertex(a4, 0, 0); -// -// PositionTextureVertex v21 = new PositionTextureVertex(b1, 1, 0); -// PositionTextureVertex v22 = new PositionTextureVertex(b2, 1, 1); -// PositionTextureVertex v23 = new PositionTextureVertex(b3, 0, 1); -// PositionTextureVertex v24 = new PositionTextureVertex(b4, 0, 0); -// -// quad1 = new TexturedQuad(new PositionTextureVertex[] { v14, v11, v12, v13 }, 0, 0, 16, 16, 16, 16); -// quad2 = new TexturedQuad(new PositionTextureVertex[] { v21, v24, v23, v22 }, 0, 0, 16, 16, 16, 16); + private int getBrightnessForRender(SuperGlueEntity entity) { + BlockPos blockpos = entity.getHangingPosition(); + BlockPos blockpos2 = blockpos.offset(entity.getFacingDirection() + .getOpposite()); + + World world = entity.getEntityWorld(); + int light = world.isBlockPresent(blockpos) ? WorldRenderer.getLightmapCoordinates(world, blockpos) : 15; + int light2 = world.isBlockPresent(blockpos2) ? WorldRenderer.getLightmapCoordinates(world, blockpos2) : 15; + return Math.max(light, light2); } } diff --git a/src/main/resources/assets/create/textures/entity/super_glue/ghostly.png b/src/main/resources/assets/create/textures/entity/super_glue/ghostly.png deleted file mode 100644 index 8a2efeeca5f116ac9515a6a5318f5c4095451377..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 367 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1en1B<7NV~B=h_qjQm#0Bo``lcXv zPP&8r;#_utSWP__M}a%bJ|A+i%3XLttnR_Y6sLPnQYHFlzLfsG`CsyH-Ge5+dvv%> zJ{s`cG3kBrdY9k1iPKYGW|VQ9`>b;R`$?0@nG1AI+sw(o?RLB{V3Nv|WtyU{g%fM` z9_eOKW_NT*l&E^tZ;reX9OW*evo_W2C>&qKG@%YfGR~XVeFXTC2