|
|
- g3 _; k) t# N R7 u行,这个怎么样
3 E/ e; J& ^. k# E i6 y. H; _+ e- package com.xhg78999.mtrfac.render;
+ q0 ]' D' `7 O
1 u- K6 l1 e7 I: V* [- import com.mojang.blaze3d.vertex.PoseStack;8 F: Y. H) g$ F0 ~9 L/ O$ M
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 e+ i( L- R9 _4 K. g9 n - import net.minecraft.client.renderer.RenderType;7 @/ |/ `' o+ d& `" M$ \
- import net.minecraft.resources.ResourceLocation;7 Y5 a$ ~' k0 S7 R# b" J
- & Q' Q8 _, r! I$ E+ v( U0 N
- import java.util.*;
" o2 |. e" h+ E
" `# }9 U g* Q8 w/ E- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(/ r" d: o m8 J) b+ s) f! ^$ p
( a' r7 w+ e W/ v# A- public class LineRender{7 Z& m3 c( e+ t7 A8 F4 Z3 Y: l
- private final PoseStack pose;7 }# T& U% t W% O
- private final MultiBufferSource source;7 D) c+ I! c) ]' I- P5 `: @7 D
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();0 Y5 d/ U* N$ [7 d/ U9 Z- m) c
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();% o. ?0 J0 p. c
- C* v4 Y6 G: n0 A
- , T) Q# a9 S' j3 a% ~: `& l1 x
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
) s5 q9 l: i$ o) J* ]8 g) t) L - if(x1 == x2 && y1 == y2 && z1 == z2){- |+ o) N* h( C( K
- return;
0 g1 s7 Z) b* B' g - }! _# I9 c9 [: h) t2 Q4 |$ O6 U. {
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 i, I, P+ [" K$ ^% n - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ b# y/ r% S2 Q! p: } - }. Q3 v; s: q7 {- p
- pose.pushPose();
' ?& W2 V6 g) ]1 W6 _/ | - final int newLight = convertLight(6);
3 P! S* O% A. E$ n! u0 l - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 t0 @5 b: c8 n
- final float lineHeightSmall = (y2 - y1);
& J$ C& [" Q S8 `8 ?! P. y# {; C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
4 D( e$ x* c$ G- X$ i - pose.popPose();: [+ y( I$ x" e* g; X* ]1 _, S4 h
- }7 u& x5 U* u: m1 l+ O) l
v$ [( M' D5 J# O- k7 p- private RenderType getLayers(String texture, int light) {0 M5 Y. ?' e" `6 t2 W, q/ ^
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
2 X$ W, S* b O% x - }1 a% E5 ?% ^, y, B8 I- Y+ A- y2 {
( e3 N4 \/ K0 i. p- private RenderType getLightTexture(ResourceLocation texture) {5 O. C% `. c2 ~ H
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
* f9 i" b: m& E - }: ?- Z" r8 w' P& w- I
6 P4 y& M5 }& l% x7 h1 W0 o1 v- private RenderType getTexture(ResourceLocation texture) {- t3 S- t0 L5 A3 z3 N, O1 E
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
. S. B* {3 ?5 H8 L: \3 } - }
. _; T$ o6 W2 N9 d! A( i# B
3 I! f7 i' I* V5 H, t- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 w% A' l9 F7 M* {: l - if (cache.containsKey(identifier)) {
" P+ \" `7 J- z6 N/ l - return cache.get(identifier);
, f- z4 r( W( v! S6 Q - } else {
+ Z; N: q& O7 p - final RenderType renderLayer = supplier.get();
) A* |2 h e/ P! ]/ X# w - cache.put(identifier, renderLayer);
3 Q1 C8 N9 T* ]4 x - return renderLayer;# M& C P$ Y# `. j7 |7 w
- }
2 w, Q: e1 N+ a% s7 @ - }( k" m4 ~; O0 U/ A( Y
- }
复制代码 |
|