|
|
# y& v6 O; M. v. v
行,这个怎么样0 ?6 @5 y4 q$ ^3 M q0 L
- package com.xhg78999.mtrfac.render;' u: U' S$ t& x2 ?0 ~
% w+ e% p0 M4 B# X/ L* f- import com.mojang.blaze3d.vertex.PoseStack; k2 v" G$ v' u
- import com.mojang.blaze3d.vertex.VertexConsumer;
2 s, } c& t. ^6 ~ - import net.minecraft.client.renderer.RenderType;
) W" A# c2 S( ]' U) I - import net.minecraft.resources.ResourceLocation;
- z* q% ]' _; ?% b# q' g' ?
3 w9 b0 A! B8 Y5 l1 Y- import java.util.*;
: O8 K' ]! }0 O. Q
; H- E, I$ C9 w0 c, k8 M- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
: b" I, R+ e% A5 d
" q, U/ w3 b" H5 [5 e- public class LineRender{
* w0 q7 h. Y v8 l0 x: O - private final PoseStack pose;- O. P3 j& I' D+ J3 I, m3 R6 s
- private final MultiBufferSource source;% Q0 o4 U, [& ?( u5 e+ n
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();9 X" m' B3 v$ T
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();: |( W: {5 V/ P
- j: i! v% o5 m: R
9 q7 B6 P7 k3 L% J8 u' D# n- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
- m2 w$ }% A, S- Y- I% Z - if(x1 == x2 && y1 == y2 && z1 == z2){2 p6 B* n. t: i" k; R2 i
- return;
& n% R2 Z* A9 {' G! e2 H. G' Z5 n) k* Q - }
?' H+ ?9 E, L- S - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
3 J6 k4 r! A0 C& p' I2 A - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");* S4 J+ o I$ C4 E) J$ z
- }
4 v# F, Z' U* F5 j# k - pose.pushPose();! u0 K+ E1 ^0 [* N
- final int newLight = convertLight(6);
+ Q$ {# i! I- C b2 [' K - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
& Z" |+ Y6 o) Y- H H% D0 } - final float lineHeightSmall = (y2 - y1);9 K+ P" y; f' l
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
+ P1 [5 S$ m" b - pose.popPose();# m% h1 p6 B. }2 z6 T( H$ k
- }
2 q1 w& n+ x' [& w: b
' m( W/ Z x8 C' W3 |2 m7 \- private RenderType getLayers(String texture, int light) {
3 {5 ~, U3 a( u - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
0 f* v2 Z1 r4 r" c: N8 A - }
$ a9 X( M3 s4 y$ _
+ d C0 l8 }! e7 o+ f" b1 J8 O- private RenderType getLightTexture(ResourceLocation texture) {
( P( W% ^- j4 X, N% i2 n- \" d2 g @ - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);; c8 j* ]# {% S' O% W; Z4 w- e, [
- }& D/ c! q7 f1 P, q
- # p, U: f" P% S* c4 T; s
- private RenderType getTexture(ResourceLocation texture) {: I& S6 Z" s e" ?2 s F: @, F i
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);- T- P8 y$ ]% O+ e1 @' V9 J. {
- }
2 T; X. T3 j8 |" B& z1 k0 \8 N4 @ - 7 _0 H) y- c# M0 a
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {$ W3 i$ r+ J/ |1 ~; T
- if (cache.containsKey(identifier)) {
8 |- f+ f# p. G; q - return cache.get(identifier);# Z) e$ S/ n% `* J
- } else {
& X" l# D2 H) c8 A) @ - final RenderType renderLayer = supplier.get();2 b6 d, r9 v E2 d$ [2 M
- cache.put(identifier, renderLayer);
( ^" w, F2 |* |- t& E - return renderLayer;
5 C- W* [1 G, a: \7 o W( @ - }' _4 _* O# W5 `# x+ A. B0 i
- }# W3 f; V8 u! D5 ?
- }
复制代码 |
|