|
|
+ C0 N# |1 p' a: p- B行,这个怎么样
8 F& P! @4 I: Q- package com.xhg78999.mtrfac.render;
1 q% D- C$ d3 J# b9 ]% c7 M. a
5 |+ m& z' g: l8 B7 Q8 Z" e- import com.mojang.blaze3d.vertex.PoseStack;
6 p3 e' g4 q& \7 U5 Q - import com.mojang.blaze3d.vertex.VertexConsumer;+ l( `! J- k% w; P& M% b7 O3 }
- import net.minecraft.client.renderer.RenderType;
P2 M7 g) K5 D# ^6 g: R - import net.minecraft.resources.ResourceLocation;
" {, e$ n3 u& ~! [: m# Y# K- y - Q0 W F& c6 s6 e5 h, {
- import java.util.*;
; w Z1 d$ W q" ~1 c$ D
! W- i- A( J8 r! |4 u- b: c0 R- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
/ t% x+ ~8 X% @- y6 R" q% _ i" } - $ {: W$ [9 R: a
- public class LineRender{3 w& |1 d' m; a# [ u! A
- private final PoseStack pose;
: o. U: _8 s; Z - private final MultiBufferSource source; x D% H9 T, \1 c- Q
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
1 X" z; {, v8 m' ?$ I5 C" a) p5 ^3 j) E# l - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();2 a" w" j) P, c' @
6 ]+ a' {% Z0 H+ Q6 l, t# c
3 R) p& }' O" J) I* P" k- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
~' I& a, m- U5 M" p( a6 ~# p - if(x1 == x2 && y1 == y2 && z1 == z2){
3 I. L$ K! s+ L @4 I - return;
6 x: j# c/ X" r9 c- Q# u - }
$ J4 G$ g, ^. D$ }8 r( x$ k5 y - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
! i+ i( f- T3 W- w - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
% _+ o% F8 d# G. @0 l/ o - }% F1 x6 v' v$ b$ X/ |. y
- pose.pushPose();, w; M9 [- U( V" ?( q
- final int newLight = convertLight(6);
- v' b& P! c* B; w% @. X - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
8 ~: {3 H% Q3 \2 K3 g9 x - final float lineHeightSmall = (y2 - y1);) l1 \; \( d) q1 _ Q: C& a
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);! S4 l: r8 Y8 e X
- pose.popPose();
: c' v3 f; K0 i1 X) X! O - }: m$ l% a) c' U$ ?0 i9 V
* m% R+ [; D4 t+ X4 g- private RenderType getLayers(String texture, int light) {/ u) L/ a# {. K0 E9 Q9 Z1 U( M, m
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
C" q& K7 g: z4 o5 U# C( } - }
& M0 w# U- z8 ^+ O - % \! D, b8 i: P% A+ u( r; r& n
- private RenderType getLightTexture(ResourceLocation texture) {
# v a }4 r: q5 w+ E# P - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);5 v5 b H+ X/ N( ?
- }1 a- P6 [5 Z- N+ \- f7 O
- 2 n. V0 m& L- s4 E3 f D! t: `
- private RenderType getTexture(ResourceLocation texture) {
' B. a- L$ q) c - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
+ ]+ z0 F/ G1 z) o1 ]2 @* ]6 y# F - }
$ C0 ?+ C" ?4 r8 J! I( b - 9 e7 P/ d0 }" g ]6 W9 C8 p9 \
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {3 v/ B v0 Y* ^5 C# i4 f8 V+ R
- if (cache.containsKey(identifier)) {
1 ?# C/ c+ n, D2 } - return cache.get(identifier);
. J9 k1 N4 ^* ^2 Z' |+ F/ ]' B2 ? - } else {9 _( j* J* J& f6 `/ g8 v
- final RenderType renderLayer = supplier.get();
$ X9 o5 z6 V5 F - cache.put(identifier, renderLayer);) R% G2 f# l* |! V) f0 L2 i
- return renderLayer;6 h& |! r( f* T
- }
" K( Z$ |7 S b9 F' Z/ J - }- F# ?( N9 S# ^( g' b7 \/ f* a
- }
复制代码 |
|