|
|
3 @7 E3 I# C- Z& y行,这个怎么样, K& W) e2 G4 B* S1 Q6 h+ {
- package com.xhg78999.mtrfac.render;
& a/ c5 O- W K0 l0 S - : k, u) x4 `0 @
- import com.mojang.blaze3d.vertex.PoseStack;
4 H6 a1 x( `+ K! D) k - import com.mojang.blaze3d.vertex.VertexConsumer;
" L+ T4 U z6 O: j8 {- H" \/ M1 }/ p7 X - import net.minecraft.client.renderer.RenderType;
; s/ _" h; v! {3 K+ w. ]) c$ |9 r* e* ~ - import net.minecraft.resources.ResourceLocation;3 W8 V3 p8 f" O& E' |
- # i+ y; ~3 c. }" S# ^# G! ~
- import java.util.*;
~3 J/ z; T* [3 l+ b - 3 Q% g$ L/ O; E1 W
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
, E0 x; ^/ f9 [ - 8 a8 d5 I- ]6 ]( I- c) x7 n3 L
- public class LineRender{
' Y5 w# H4 u3 ]* Z3 W7 r - private final PoseStack pose;) L: v+ n9 C) @/ Z7 H- q
- private final MultiBufferSource source;
; q- z/ ^# @9 j8 f4 J J - private static final Map<String, RenderType> CACHE_A = new HashMap<>();+ f" v4 O# A, j6 s- m" Y+ S
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();9 m Q9 H3 v1 X5 G/ m
- $ t( X/ A+ v+ S) @9 H# ]" A
- 2 j: }% z3 `* S. J" |
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
7 r: {5 u: |7 H6 o( k% J$ R5 [ - if(x1 == x2 && y1 == y2 && z1 == z2){
! p( z* T! q& O! ] - return;1 C& J+ M9 l, j& E
- }9 c+ z# Z) N1 y6 @" z7 p" o, ~
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
" T( D1 }$ I/ L+ _/ P* D! A7 L4 ^ - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
7 o' T+ j( Z7 n; [ - }7 i! c# E! m* N# W4 r B2 w1 ]
- pose.pushPose();6 ?8 Z8 n3 t6 g$ h+ h6 T: O
- final int newLight = convertLight(6);
* Y0 D3 C9 Q. p& e - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
( c/ S. z- r9 V$ Z$ x$ L5 x - final float lineHeightSmall = (y2 - y1);8 g- {. ^! c: c) C& X* c
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
6 k* \1 |. x: g - pose.popPose();
1 v5 F2 K$ T( s( |6 W - }/ l* }( J& T% F7 o
- % d( A% b' |- T8 E1 X( R
- private RenderType getLayers(String texture, int light) {
" y, N! r5 U* f: X- M8 b - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 l# n8 z2 G" W- `( z - }
, m/ M' y9 ~6 _( L( q- ^
! V: y" _7 {; ~) t8 j- private RenderType getLightTexture(ResourceLocation texture) {6 n0 \2 v1 a* y0 }
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);3 J* x7 L% m e' c y# ^/ ~
- }
, K5 _( U; v1 P3 D8 t, D5 o7 T2 Y
|8 a; ]! q( _- y Q* `! n- private RenderType getTexture(ResourceLocation texture) {( o* t- H8 q- H, Z" n y
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);
8 j9 b; c, A* p8 e: i4 t" l - }
+ \/ H2 s0 |- z# j
X% M% @0 Z% x2 ^5 B$ O$ [- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
3 w5 V0 E& b- X1 F( h) W; s0 B3 ~ - if (cache.containsKey(identifier)) {
) |: ~2 Z/ r( M - return cache.get(identifier);+ f/ F5 k- T+ i
- } else {7 T* c7 u# L7 d- {# I0 ~$ d
- final RenderType renderLayer = supplier.get();
( q5 d _ T; F- ? - cache.put(identifier, renderLayer);
k+ d8 y9 R' C/ c - return renderLayer;
o+ r0 R" h' k: U) V/ v! z( J - }
! d5 b2 {( f! n9 H1 f - }
5 \0 j5 O4 ]. u% T- D - }
复制代码 |
|