|
|
+ d$ p' R* g. ?9 T' Z
行,这个怎么样
) O* ?* n p3 }7 a5 J- package com.xhg78999.mtrfac.render;
/ G( S2 e L( F
/ K7 ]. ] v1 r7 D* `- import com.mojang.blaze3d.vertex.PoseStack;3 r/ j! n7 X% _2 \
- import com.mojang.blaze3d.vertex.VertexConsumer;
6 F6 F$ o2 a- @+ u4 `: R8 H0 j- O - import net.minecraft.client.renderer.RenderType;
1 C( a' T8 l1 p4 J" s - import net.minecraft.resources.ResourceLocation;! r2 u# A& D" A9 c* }, H
/ K t3 ~8 m, f- import java.util.*;
# e# F6 k- ~" X. o. S) K# _ - / W. @6 _8 P* S9 G4 d; M8 x
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
8 `$ J% x* `0 @' p' I3 n
0 r3 G! ~# y) F$ w- public class LineRender{9 r! P& k9 C7 X/ l- O' T9 L1 @
- private final PoseStack pose;, ~8 ~9 g1 V* C* x( ~0 d
- private final MultiBufferSource source;
! U9 k+ o5 X% Z0 H& t* l! V - private static final Map<String, RenderType> CACHE_A = new HashMap<>();6 p# R4 [' X8 V) v
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
8 S8 v& W" I2 S
6 P S) @$ A5 k0 N0 x- 4 U0 [( W) Q8 L- v: e7 ~
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
+ [7 O6 C( S! g6 ~ - if(x1 == x2 && y1 == y2 && z1 == z2){
O1 @( W2 B* Y5 h4 ]) _ - return;8 r- g9 Q5 | ^: T0 D! n
- }
) o5 M1 }% r' V/ U, `& v$ h - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
/ q1 m B# X" O2 g - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");1 \+ q: c% D8 M( J
- }$ a- _9 f' r0 p! ^+ J
- pose.pushPose();
/ q9 t0 F O: x2 [, W% [' k/ f2 B+ Y& Q - final int newLight = convertLight(6);
% x" A7 [' ]/ L1 ] - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));, ~) I: M4 y) {
- final float lineHeightSmall = (y2 - y1);3 j# `! E( q8 `1 C* H+ N6 F% j
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( Z+ W D1 c( d) U8 i! m' r4 X: I6 f - pose.popPose();- L8 C% h" C- J4 I9 C T7 C: `0 d% [5 I
- }
0 |9 }0 k# |+ I1 x$ }0 z! P/ u
" e, O: y9 \3 D( K2 ?% \1 V- private RenderType getLayers(String texture, int light) {
. k0 I8 t1 g$ s5 J4 E# i) a" e* p. R - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
4 v# n! o, P6 E' u( p( e v - }
0 H4 C0 q. T1 X' {, ]. i
$ n- o* l; i k v/ K% Z- private RenderType getLightTexture(ResourceLocation texture) {
; f( Q+ q3 i* B$ x) J; S - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
# R4 v; g. m8 N. y, M - }6 k. r0 t! R' a1 v) T) U
: B4 d/ F* ~5 r. q. c8 }% O8 ?! e- private RenderType getTexture(ResourceLocation texture) {
( {1 ^$ I: `$ q' n8 j1 c - return this.cache(texture, () -> entityCutout(texture), CACHE_B);% k3 r: b9 m1 a- j4 A. ]2 T5 T! w
- }
" {+ m3 Z" O y. x4 A y) D
7 J8 ], u, q* j) Z; D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, M' j# F' y+ N) D, f - if (cache.containsKey(identifier)) {6 Z" Z$ h8 g, i$ o4 d) f, I! M
- return cache.get(identifier);3 M4 b+ S9 s! x& {5 ^5 p
- } else {# b4 Z2 r& D8 N2 ~" N
- final RenderType renderLayer = supplier.get();
1 K6 Y( r8 ]/ M4 L0 o- e9 ^ - cache.put(identifier, renderLayer);
# l4 @4 P3 r- c; m$ t - return renderLayer;
' ?; N& k$ u* Z) z# a z - }
# h% q# ]' M* D$ h$ Y# h# k - }
3 j- u) x8 \# I! E - }
复制代码 |
|