|
|
' U4 n' R5 L3 h) c行,这个怎么样
t% c7 y' \, j' f9 V- @* O- package com.xhg78999.mtrfac.render;
! R8 O2 }' o7 y/ L& M+ u9 V
9 z2 f% ]4 F8 U4 D, h2 t, v- import com.mojang.blaze3d.vertex.PoseStack;
. @3 y/ S; r, j8 B+ _* a$ | - import com.mojang.blaze3d.vertex.VertexConsumer;% i8 u6 `! p) s# `2 N; r
- import net.minecraft.client.renderer.RenderType;% Y4 o' e! p* C% ~) l
- import net.minecraft.resources.ResourceLocation;/ b3 U; e( b: D! M
" J4 W9 T, K- D- import java.util.*; U# k+ h+ K! E4 G- o7 h
- : T; T! y d3 u' z" r0 l
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ T! j6 u0 X/ n: m/ D
% J- B: I! ]9 {6 k- public class LineRender{. A* F$ ?1 k- z
- private final PoseStack pose;# R2 X+ O* B2 a7 Z
- private final MultiBufferSource source;4 M/ J' _3 v, T+ p3 T+ T
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
, ?: B! [* ^# F7 j) q. ^3 h - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
$ l7 {( T9 a X" N
; A" |, \4 B& ], }6 H; A
- o1 B; `3 C' y5 {- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){8 y9 g, p6 d6 {3 n$ T/ s/ H. x' l
- if(x1 == x2 && y1 == y2 && z1 == z2){9 F; G6 x0 n' }
- return;! _! r* O# _1 @% v+ X. q% d
- }
8 N5 \; h) `0 q, ^5 [& y1 q2 ^ - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
1 i5 S; [% F* v# z h - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");- W% R0 M1 l- c3 R8 Y
- }
& q5 y+ |5 U" J1 B5 z - pose.pushPose();
8 I. J% c" c( { - final int newLight = convertLight(6);) d: b2 }8 r+ W) @; S0 g- p
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
5 N6 u4 K) g$ F6 o. B2 [6 k - final float lineHeightSmall = (y2 - y1);- {- I( T. c' V8 Z
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& A& j- [% Q6 z4 q( r) V" v2 j
- pose.popPose();3 N" f% d2 u' B( |: t2 H
- }
4 ]2 i8 }0 g7 \# F - % ^0 G. J8 q2 t" t( K
- private RenderType getLayers(String texture, int light) {
5 K" K4 ?+ K/ I9 Z* Y* O! \$ U - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
8 b1 U% \. t9 y, [) w - }
! x1 D# S/ H: p. J4 G
; U- v0 v- T( h9 |- private RenderType getLightTexture(ResourceLocation texture) {
" G& T* }7 L" u1 @6 {, O- L! z - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
1 ^( D% x- K% c. M% e - }
3 F5 c _7 B0 \5 w0 D - # Y! e }: d: k \' @
- private RenderType getTexture(ResourceLocation texture) {
$ w! M/ y( T3 `( `6 I - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
& J5 X2 o& O/ E' R7 Q4 N& | - }
8 X1 G" G, N; n+ w! z" [
* W1 j9 S% _2 ]) E$ S/ D- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {, Y/ P$ `! K( E# c2 T5 H) ]
- if (cache.containsKey(identifier)) {% N4 C4 B4 n$ G: B
- return cache.get(identifier);
6 ], l6 f. S+ Z7 b) F - } else {
+ d! D: X, A' Z. J u$ b - final RenderType renderLayer = supplier.get();8 e3 ^8 ~6 [$ K, j5 d+ v
- cache.put(identifier, renderLayer);* O# s* k( Y+ l! S( U Q
- return renderLayer;
3 L' @4 K9 ~+ r: O" `- W - }* Q) m E" b3 W! A9 h. Y
- }
# I; I# W3 ]! \ - }
复制代码 |
|