|
|
# T+ g1 q7 y2 D0 A) S3 i行,这个怎么样
! g9 z% `+ F/ T4 q( l% U+ `1 L- package com.xhg78999.mtrfac.render;
& R6 V& S$ m% a: z: _( c3 D - 8 \3 a; \2 n/ Q1 z z
- import com.mojang.blaze3d.vertex.PoseStack;
5 W% @( \; U; K7 R& l - import com.mojang.blaze3d.vertex.VertexConsumer;
S# m% M9 }5 O9 v2 b- i# { - import net.minecraft.client.renderer.RenderType;
+ z; ~: ]! _4 u( y2 B1 v - import net.minecraft.resources.ResourceLocation;
( t0 R; J8 Z9 q4 z' g- I+ J- h9 ^. U - 6 H+ w+ ~$ J# b0 o* \
- import java.util.*;
0 Y+ V( N ?* G& \ - 8 k, a- ]' B6 u( c8 K
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
~5 i1 g! x" S) r6 U
5 H2 h- V4 L6 ?7 q- public class LineRender{- m; Z3 t5 n( a8 k6 h' @
- private final PoseStack pose;* Q( o) T2 w% R5 u' \
- private final MultiBufferSource source;
, _2 y/ N C3 z$ b0 z% q - private static final Map<String, RenderType> CACHE_A = new HashMap<>();$ U! Q r$ v7 o k4 h
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();* t T+ U/ x/ F
4 a8 v$ d9 X9 s5 g2 A8 D8 B
% l! D7 E1 m( t% {2 J+ J- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
: U% ?3 z& q( c0 E( p) k9 k9 e T - if(x1 == x2 && y1 == y2 && z1 == z2){
8 t: O0 g4 e" z: u+ H5 Y! J2 ~ - return;
4 J% t! C' n0 ^' D8 w. n - }
2 k. w0 F$ w# }& ?7 L I( D* I7 X - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 x0 Q# H; y8 b! L. m; w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");, g5 Z9 [6 z: B9 I4 S
- }# q; P$ }$ }% e$ m
- pose.pushPose();
) c1 }. J& f) m6 G9 j8 f6 V - final int newLight = convertLight(6);
& Y8 m& ^/ d4 h" B0 I - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));* G" A! Q4 v+ x
- final float lineHeightSmall = (y2 - y1);1 D; O* u1 K) C
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
; n* K8 |; v* G8 ^. I9 e6 X - pose.popPose();
% h3 P5 @6 p+ P0 h% r - }, J5 }$ o v( J# D
5 v+ C2 z A% G l& N- private RenderType getLayers(String texture, int light) {1 p1 V; j0 l M: P
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));, ^, ]. A5 T4 ] i' L# j' j" M/ v* `
- }
+ u. q; N' I# W - % |! q: P+ ?$ z' O
- private RenderType getLightTexture(ResourceLocation texture) {
* I: d+ M- L: ~) A7 n4 r. B - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
% H F9 L7 v- r& ^6 ?" \ - }
+ d3 P( h& f" l0 ^ x% Y' g; l
3 e. T v/ S; T3 w$ N& U O. e- private RenderType getTexture(ResourceLocation texture) {9 Y, Y: z' \' I/ j, k6 `
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
0 |1 O5 w, F: ^9 M* M2 L - }1 x2 @" e$ d' |4 [
6 ` x- H4 m7 L6 U- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
; q5 D- e. ]% U% ^. P; g - if (cache.containsKey(identifier)) {* j3 q1 j' l' @& t+ K* J
- return cache.get(identifier);1 A0 ]* }. f! G8 A. Z. ^' k
- } else {; v8 V; }% Y% e' P' r3 P& d8 F
- final RenderType renderLayer = supplier.get();
/ j0 i* t5 X& z1 a$ A - cache.put(identifier, renderLayer);
2 K2 V, b# D% b) D4 }& g - return renderLayer;7 T+ Y+ r& \, l# d* x
- }- b* K, `: P& t% t: n h# ~, z
- }
, D; \ K$ }" _' F* F - }
复制代码 |
|