Ported superglue entityrenderer

This commit is contained in:
simibubi 2020-05-16 09:57:06 +02:00
parent d5ec1d6fef
commit 8212d39d95
4 changed files with 65 additions and 43 deletions

View file

@ -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() {

View file

@ -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();

View file

@ -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<SuperGlueEntity> {
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<SuperGlueEntity> {
@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<SuperGlueEntity> {
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);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 367 B