Advertisement
Vaerys_Dawn

Missing Texture ;-;

Mar 12th, 2021
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.14 KB | None | 0 0
  1. public class RenderBeeHive extends TileEntityRenderer<TieredBeehiveTileEntity> {
  2.  
  3.     public static final ResourceLocation TIER_1_OVERLAY = new ResourceLocation(ResourcefulBees.MOD_ID, "textures/block/bee_nest/tier_overlay/tier_1.png");
  4.     public static final ResourceLocation TIER_2_OVERLAY = new ResourceLocation(ResourcefulBees.MOD_ID, "textures/block/bee_nest/tier_overlay/tier_2.png");
  5.     public static final ResourceLocation TIER_3_OVERLAY = new ResourceLocation(ResourcefulBees.MOD_ID, "textures/block/bee_nest/tier_overlay/tier_3.png");
  6.     public static final ResourceLocation TIER_4_OVERLAY = new ResourceLocation(ResourcefulBees.MOD_ID, "textures/block/bee_nest/tier_overlay/tier_4.png");
  7.  
  8.     public RenderBeeHive(TileEntityRendererDispatcher dispatcher) {
  9.         super(dispatcher);
  10.         Minecraft.getInstance().textureManager.register(PlayerContainer.BLOCK_ATLAS, new SimpleTexture(RenderBeeHive.TIER_1_OVERLAY));
  11.         Minecraft.getInstance().textureManager.register(PlayerContainer.BLOCK_ATLAS, new SimpleTexture(RenderBeeHive.TIER_2_OVERLAY));
  12.         Minecraft.getInstance().textureManager.register(PlayerContainer.BLOCK_ATLAS, new SimpleTexture(RenderBeeHive.TIER_3_OVERLAY));
  13.         Minecraft.getInstance().textureManager.register(PlayerContainer.BLOCK_ATLAS, new SimpleTexture(RenderBeeHive.TIER_4_OVERLAY));
  14.     }
  15.  
  16.     @Override
  17.     public void render(TieredBeehiveTileEntity tile, float partialTick, @NotNull MatrixStack matrix, @NotNull IRenderTypeBuffer renderer, int light, int overlayLight) {
  18.         ResourceLocation location = getLocation(tile);
  19.         if (location == null) return;
  20.         IVertexBuilder builder = renderer.getBuffer(Atlases.translucentCullBlockSheet());
  21.         Vector3f start = new Vector3f(-0.0001f, -0.0001f, -0.0001f);
  22.         Vector3f end = new Vector3f(1.0001f, 1.0001f, 1.0001f);
  23.         CubeModel model = new CubeModel(start, end);
  24.         model.setTextures(location);
  25.         RenderCuboid.INSTANCE.renderCube(model, matrix, builder, -1, light, overlayLight);
  26.     }
  27.  
  28.     private static ResourceLocation getLocation(TieredBeehiveTileEntity tile) {
  29.         switch (tile.getTier()) {
  30.             case 1:
  31.                 return TIER_1_OVERLAY;
  32.             case 2:
  33.                 return TIER_2_OVERLAY;
  34.             case 3:
  35.                 return TIER_3_OVERLAY;
  36.             case 4:
  37.                 return TIER_4_OVERLAY;
  38.             default:
  39.                 return null;
  40.         }
  41.     }
  42. }
  43.  
  44. public class CubeModel {
  45.  
  46.     private final Vector3f start;
  47.     private final Vector3f end;
  48.     public final TextureAtlasSprite[] sprites = new TextureAtlasSprite[6];
  49.  
  50.     public CubeModel(Vector3f start, Vector3f end) {
  51.         this.start = start;
  52.         this.end = end;
  53.     }
  54.  
  55.     public void setTextures(ResourceLocation texture) {
  56.         TextureAtlasSprite sprite = getSprite(texture);
  57.         this.sprites[0] = sprite;
  58.         this.sprites[1] = sprite;
  59.         this.sprites[2] = sprite;
  60.         this.sprites[3] = sprite;
  61.         this.sprites[4] = sprite;
  62.         this.sprites[5] = sprite;
  63.     }
  64.  
  65.     public static TextureAtlasSprite getSprite(ResourceLocation spriteLocation) {
  66.         return Minecraft.getInstance().getTextureAtlas(PlayerContainer.BLOCK_ATLAS).apply(spriteLocation);
  67.     }
  68.  
  69.     public Vector3f getSize() {
  70.         return new Vector3f(this.getEnd().x()- this.getStart().x(), this.getEnd().y()- this.getStart().y(), this.getEnd().z()- this.getStart().z());
  71.     }
  72.  
  73.     public Vector3f getStart() {
  74.         return start;
  75.     }
  76.  
  77.     public Vector3f getEnd() {
  78.         return end;
  79.     }
  80. }
  81.  
  82. public class RenderCuboid {
  83.     public static final RenderCuboid INSTANCE = new RenderCuboid();
  84.     private static final Vector3f VEC_ZERO = new Vector3f(0.0F, 0.0F, 0.0F);
  85.  
  86.  
  87.     private static Vector3f withValue(Vector3f vector, Axis axis, float value) {
  88.         if (axis == Axis.X) {
  89.             return new Vector3f(value, vector.y(), vector.z());
  90.         } else if (axis == Axis.Y) {
  91.             return new Vector3f(vector.x(), value, vector.z());
  92.         } else if (axis == Axis.Z) {
  93.             return new Vector3f(vector.x(), vector.y(), value);
  94.         } else {
  95.             throw new CustomException("Was given a null axis! That was probably not intentional, consider this a bug! (Vector = " + vector + ")");
  96.         }
  97.     }
  98.  
  99.     public static double getValue(Vector3f vector, Axis axis) {
  100.         if (axis == Axis.X) {
  101.             return vector.x();
  102.         } else if (axis == Axis.Y) {
  103.             return vector.y();
  104.         } else if (axis == Axis.Z) {
  105.             return vector.z();
  106.         } else {
  107.             throw new CustomException("Was given a null axis! That was probably not intentional, consider this a bug! (Vector = " + vector + ")");
  108.         }
  109.     }
  110.  
  111.     public static float getRed(int color) {
  112.         return (float) (color >> 16 & 255) / 255.0F;
  113.     }
  114.  
  115.     public static float getGreen(int color) {
  116.         return (float) (color >> 8 & 255) / 255.0F;
  117.     }
  118.  
  119.     public static float getBlue(int color) {
  120.         return (float) (color & 255) / 255.0F;
  121.     }
  122.  
  123.     public static float getAlpha(int color) {
  124.         return (float) (color >> 24 & 255) / 255.0F;
  125.     }
  126.  
  127.     public void renderCube(CubeModel cube, MatrixStack matrix, IVertexBuilder buffer, int argb, int light, int overlay) {
  128.         float red = getRed(argb);
  129.         float green = getGreen(argb);
  130.         float blue = getBlue(argb);
  131.         float alpha = getAlpha(argb);
  132.         Vector3f size = cube.getSize();
  133.         matrix.pushPose();
  134.         matrix.translate(cube.getStart().x(), cube.getStart().y(), cube.getStart().z());
  135.         MatrixStack.Entry lastMatrix = matrix.last();
  136.         Matrix4f matrix4f = lastMatrix.pose();
  137.         Matrix3f normal = lastMatrix.normal();
  138.         Direction[] directions = Direction.values();
  139.  
  140.         for (Direction direction : directions) {
  141.             Direction face = direction;
  142.             int ordinal = face.ordinal();
  143.             TextureAtlasSprite sprite = cube.sprites[ordinal];
  144.             if (sprite != null) {
  145.                 Axis u = face.getAxis() == Axis.X ? Axis.Z : Axis.X;
  146.                 Axis v = face.getAxis() == Axis.Y ? Axis.Z : Axis.Y;
  147.                 float other = face.getAxisDirection() == Direction.AxisDirection.POSITIVE ? (float) getValue(size, face.getAxis()) : 0.0F;
  148.                 face = face.getAxisDirection() == Direction.AxisDirection.NEGATIVE ? face : face.getOpposite();
  149.                 Direction opposite = face.getOpposite();
  150.                 float minU = sprite.getU0();
  151.                 float maxU = sprite.getU1();
  152.                 float minV = sprite.getV1();
  153.                 float maxV = sprite.getV0();
  154.                 double sizeU = getValue(size, u);
  155.                 double sizeV = getValue(size, v);
  156.                 for (int uIndex = 0; (double) uIndex < sizeU; ++uIndex) {
  157.                     float[] baseUV = new float[]{minU, maxU, minV, maxV};
  158.                     double addU = 1.0D;
  159.                     if ((double) uIndex + addU > sizeU) {
  160.                         addU = sizeU - (double) uIndex;
  161.                         baseUV[1] = baseUV[0] + (baseUV[1] - baseUV[0]) * (float) addU;
  162.                     }
  163.                     for (int vIndex = 0; (double) vIndex < sizeV; ++vIndex) {
  164.                         float[] uv = Arrays.copyOf(baseUV, 4);
  165.                         double addV = 1.0D;
  166.                         if ((double) vIndex + addV > sizeV) {
  167.                             addV = sizeV - (double) vIndex;
  168.                             uv[3] = uv[2] + (uv[3] - uv[2]) * (float) addV;
  169.                         }
  170.                         float[] xyz = new float[]{(float) uIndex, (float) ((double) uIndex + addU), (float) vIndex, (float) ((double) vIndex + addV)};
  171.                         this.renderPoint(matrix4f, normal, buffer, face, u, v, other, uv, xyz, true, false, red, green, blue, alpha, light, overlay);
  172.                         this.renderPoint(matrix4f, normal, buffer, face, u, v, other, uv, xyz, true, true, red, green, blue, alpha, light, overlay);
  173.                         this.renderPoint(matrix4f, normal, buffer, face, u, v, other, uv, xyz, false, true, red, green, blue, alpha, light, overlay);
  174.                         this.renderPoint(matrix4f, normal, buffer, face, u, v, other, uv, xyz, false, false, red, green, blue, alpha, light, overlay);
  175.                         this.renderPoint(matrix4f, normal, buffer, opposite, u, v, other, uv, xyz, false, false, red, green, blue, alpha, light, overlay);
  176.                         this.renderPoint(matrix4f, normal, buffer, opposite, u, v, other, uv, xyz, false, true, red, green, blue, alpha, light, overlay);
  177.                         this.renderPoint(matrix4f, normal, buffer, opposite, u, v, other, uv, xyz, true, true, red, green, blue, alpha, light, overlay);
  178.                         this.renderPoint(matrix4f, normal, buffer, opposite, u, v, other, uv, xyz, true, false, red, green, blue, alpha, light, overlay);
  179.                     }
  180.                 }
  181.             }
  182.         }
  183.  
  184.         matrix.popPose();
  185.     }
  186.  
  187.     private void renderPoint(Matrix4f matrix4f, Matrix3f normal, IVertexBuilder buffer, Direction face, Axis u, Axis v, float other, float[] uv, float[] xyz, boolean minU, boolean minV, float red, float green, float blue, float alpha, int light, int overlay) {
  188.         int uArray = minU ? 0 : 1;
  189.         int vArray = minV ? 2 : 3;
  190.         Vector3f vertex = withValue(VEC_ZERO, u, xyz[uArray]);
  191.         vertex = withValue(vertex, v, xyz[vArray]);
  192.         vertex = withValue(vertex, face.getAxis(), other);
  193.         Vector3i normalForFace = face.getNormal();
  194.         float adjustment = 2.5F;
  195.         Vector3f norm = new Vector3f((float) normalForFace.getX() + adjustment, (float) normalForFace.getY() + adjustment, (float) normalForFace.getZ() + adjustment);
  196.         norm.normalize();
  197.         buffer.vertex(matrix4f, vertex.x(), vertex.y(), vertex.z()).color(red, green, blue, alpha).uv(uv[uArray], uv[vArray]).overlayCoords(overlay).uv2(light).normal(normal, norm.x(), norm.y(), norm.z()).endVertex();
  198.     }
  199.  
  200.     private static class CustomException extends RuntimeException {
  201.         public CustomException(String message) {
  202.             super(message);
  203.         }
  204.     }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement