|
|
+ a3 R$ ~& L, F! k5 o% i- o行,这个怎么样3 l! y) p% Q% e
- package com.xhg78999.mtrfac.render;4 a1 A& r# Z3 X, P
; S5 L$ A, G# l& r8 f/ O w- import com.mojang.blaze3d.vertex.PoseStack;* ~" _9 R; s6 u- ?1 Y
- import com.mojang.blaze3d.vertex.VertexConsumer;5 O# t- I' z9 x! U% Q1 B v
- import net.minecraft.client.renderer.RenderType;
( U# Q G0 `2 Z1 S4 z5 M% y6 X% M - import net.minecraft.resources.ResourceLocation;% q# M" p1 Z( N$ B2 q) ?
0 T3 W& q, @$ {* {7 D- import java.util.*;( z2 ^) E' ?/ w! s' l0 m( f! s/ c" y
- : r" c) y1 q! y
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
& F8 M- _3 {& z - $ J# r5 f, O7 T/ r& V9 J0 K
- public class LineRender{+ B7 _; F1 O! x$ I6 f+ u
- private final PoseStack pose;
. I) D+ X: i0 ^, n - private final MultiBufferSource source;+ e& @/ p1 g+ X A- X
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();( r$ o. v. }# R# A0 z8 n0 i& ^
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
1 V" S( ^0 k, m$ m - % G8 ?& \- o w2 R
7 W8 Q5 a+ ~7 b( z- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
. c; P+ R$ _5 D: v4 Y - if(x1 == x2 && y1 == y2 && z1 == z2){$ h0 {% t* E+ y; F. H
- return;) h6 Q% E, X v0 K% N) f
- }! J4 g0 g* Q" K9 L p; z5 a- |; Z
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){9 R) U' s, i4 J9 Z) i
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");) r/ i- h/ Q( M; u6 V3 r$ R6 w! W
- }
$ R' b" @2 H& N: p - pose.pushPose();
! I# {" X7 G# Y$ I# H4 g( _ - final int newLight = convertLight(6);
% V9 j6 G t( T5 |% ^ U$ y - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));+ t$ n% a9 s. H/ e8 d, u
- final float lineHeightSmall = (y2 - y1);
; l5 h8 {7 G) j2 D/ c$ ~8 `: P( C - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
, {+ H5 f4 v1 `# s o; q - pose.popPose();
, _9 K0 J' Z+ z! O - }' g# s1 W6 _. q; _) B
/ V6 P' y& K- X T8 i9 J1 i- private RenderType getLayers(String texture, int light) {3 i" s/ _( K$ N% v
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
+ O. y, t/ `6 t - }5 P8 P3 W e1 Z* e
- 1 s0 Z- V6 M+ P( @
- private RenderType getLightTexture(ResourceLocation texture) {/ z$ ~% y( }- v7 Z
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);2 |9 H! F4 u# A; v& n8 ]) q
- }
: x# p3 x& Y: F" Z# Q
6 D' w1 t' {; T4 w5 B9 i- private RenderType getTexture(ResourceLocation texture) {
9 A2 }* j1 x1 O1 h! R - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
- _; B6 `( l# }" _ - }% T* s& G2 H7 l" m
- * y3 c4 d+ c! B
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {5 l r1 A/ Z7 G: H) ~5 v
- if (cache.containsKey(identifier)) {
7 Y$ O H- u7 D! ^. Y - return cache.get(identifier);5 O& g7 v' ~- d! Y5 L4 u- e
- } else {
4 k2 R9 O# u. r" v - final RenderType renderLayer = supplier.get();
2 }$ V9 [! A: Y4 {# ] - cache.put(identifier, renderLayer);, u5 r) F, w3 k, O- v8 o9 z
- return renderLayer;% t6 C: o, H4 N5 w7 K
- }. r4 t M. y8 v0 g% S$ v; q* r& Y
- }
! W+ F7 t' X- `* }+ f, | - }
复制代码 |
|