|
|
0 W: P7 \- h3 q& U# n' c0 H
行,这个怎么样
( S0 x. a+ S6 D9 J% g7 `6 S; T- package com.xhg78999.mtrfac.render;
/ K; T* h8 z8 Q, ?4 K& R
8 a3 E; a5 p7 _+ r4 _( ~& w2 ~8 G- import com.mojang.blaze3d.vertex.PoseStack;5 f7 y( J" o" w% ~' Z
- import com.mojang.blaze3d.vertex.VertexConsumer;+ O& T+ Y; }5 W- ~) Y
- import net.minecraft.client.renderer.RenderType;( d# `! [! K: x& b6 n2 `6 T
- import net.minecraft.resources.ResourceLocation; D+ e2 J8 J& A d: f0 i+ W2 T
. f ~6 h" h+ m) K% {- import java.util.*;5 Z& S. |! y, f- q0 h
$ k/ \0 _! K) R9 [+ d- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(9 b" }1 ?8 ` F- {5 I
- & r! l0 f4 N3 @1 J/ u Z' b
- public class LineRender{% q4 W: z$ f8 l/ ?
- private final PoseStack pose;
4 j" o! d) T% C4 e - private final MultiBufferSource source;
+ }, |1 |- |+ |4 k) B3 i# N1 f5 C - private static final Map<String, RenderType> CACHE_A = new HashMap<>();1 [4 J$ k% p6 k9 P
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
; H2 P- x. h: m8 _ - , ~1 b g( _9 p `5 J: F
- 9 G( D2 M7 ]5 o5 f& ^- t$ x! z
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
, T. c9 h3 {6 w - if(x1 == x2 && y1 == y2 && z1 == z2){* M8 T9 H+ `6 g# ~
- return;
! a( G$ w$ s) D2 l' y1 V - }
: Q$ C8 g0 A" L7 c/ A$ u. A - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
% `5 |- r5 O. ?" g* C8 A - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");7 w5 \' d/ v" D6 \
- }! Z( i/ t6 c0 q n! f- c: h |
- pose.pushPose();
: g _- `( q2 l$ t - final int newLight = convertLight(6);
( X- m2 s+ y: n. q: f - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
3 n$ t5 x9 r6 c: y: G - final float lineHeightSmall = (y2 - y1);- A' T3 v* n1 h& M8 ^. j3 p
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);6 v+ ]4 b# P( @/ @8 @% _9 W+ c
- pose.popPose();9 j" p4 n, R7 v+ l P) d3 J) u
- }. \2 D" h# K( R5 {' K- @* P9 c
- 3 s: b. m8 W0 {& W2 V! h. P
- private RenderType getLayers(String texture, int light) {
. M6 Z+ y9 A5 p/ J9 G - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 q2 ?; J4 k; S+ o! `" s; Z0 ^ - }
& \2 E2 t7 V- w' n% L+ g& j. _$ H
% c- H; q( ~) n- private RenderType getLightTexture(ResourceLocation texture) {7 G7 F$ M- A+ q7 e( @/ z# [* B
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);$ W% q k5 `( p# G. m7 m1 Y
- }& I! a: u, ~: w* u4 m
- 8 K: |' i+ J1 l" Q) L
- private RenderType getTexture(ResourceLocation texture) {
! e. J7 m' i, ~0 W# @% N - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
4 r2 G l6 _/ d( r! ?- c/ {: v - }( j; M X2 u. E
6 A% O6 Y( ~7 n! p0 Z- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
- J4 r% S, ~5 ]" f - if (cache.containsKey(identifier)) {% o2 N; u7 r) r. k
- return cache.get(identifier);
3 T% L, ~; g1 b6 Z - } else {
) u+ A! U4 `) z- Q5 d - final RenderType renderLayer = supplier.get();0 v1 O2 o- L2 e
- cache.put(identifier, renderLayer);
7 x& b7 ]& i2 ~6 X# s) O - return renderLayer;
5 c& ?# N1 t/ V) o! K. C6 |/ c8 z - }: s, i% J! l4 P" \& r/ H
- }
* z1 Z0 x2 q3 g/ n: ? - }
复制代码 |
|