|
|
$ m* I+ _: k4 }8 v# @, T- R! V3 _" S5 q行,这个怎么样
" m6 K3 m2 X& U9 a9 X- package com.xhg78999.mtrfac.render;
( P! {' k% F8 ~8 |7 p: a" X3 y - - m* K4 r) m: G+ c& o
- import com.mojang.blaze3d.vertex.PoseStack;
5 V- s9 j5 M' ~* p; H! J' E - import com.mojang.blaze3d.vertex.VertexConsumer;
$ J" Y; V) f' m% U8 \! u - import net.minecraft.client.renderer.RenderType;/ H# l# l' \/ ^0 T, N7 n
- import net.minecraft.resources.ResourceLocation;
# r4 y6 s% K. s/ u0 J
6 h/ @' n% R) k w- import java.util.*;. m, s9 Y" t3 x0 ?
- 6 O" l2 j: p' C$ J
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(3 z o% x. l" e( T
5 f9 X Z9 S# H: s$ P L6 k' E- public class LineRender{" m1 ]7 o8 _ T* B- C+ a+ J
- private final PoseStack pose;, a6 A/ A! E( c4 k
- private final MultiBufferSource source;
/ g. W+ N+ I* H% B - private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 l# z8 R! g9 Z6 s# P
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();6 K L. z5 e: d
- . A6 Y6 b) x' a8 ^- h' k
- 5 d, H2 c9 a, A4 h7 \+ R
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){1 ]; n! T k+ A$ m T+ e
- if(x1 == x2 && y1 == y2 && z1 == z2){
; ^5 ~ b. y' w* G" }1 } - return;8 g" M: F# |+ f
- }! t5 Q2 x4 p$ d
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){7 z$ `* K4 B) f9 u* H" I: P
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ {" b' r3 `, L2 S; ?2 [7 C3 C& D$ ~( D - }
j; E5 u) E! S: `2 p - pose.pushPose();
9 I' r( u" ?, X, C$ F- E! p# p$ { - final int newLight = convertLight(6);% v- L' p- x# s+ ]" f: }- J; e
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));& Q9 d) t! p+ N- n1 b$ J- q
- final float lineHeightSmall = (y2 - y1);
6 N9 U, S9 `# L+ I' q - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);& b( T' i' y) Q) h# _
- pose.popPose();+ _# E3 h# L8 Q ] P8 A4 f' \
- }
- }& Z$ X( H N/ O3 P. p2 w n
+ v! [1 `6 p( ?- private RenderType getLayers(String texture, int light) {; A7 N- C) N( Y1 `" x% H
- return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
3 _. C8 y8 f- N& m - } o. v1 Y/ ]2 o! g C W) r8 O
0 G! F M& r9 u X4 ^% M& Q- private RenderType getLightTexture(ResourceLocation texture) {
/ \/ `: G. z+ H - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
: l5 R( P. x* g2 a% s1 }- N, Z - }$ W; n( ], x$ k @; X4 v4 s* F# b. E
- % A7 [+ f7 n7 [. q; R( H
- private RenderType getTexture(ResourceLocation texture) {
R( q& d ]! V% a/ ^- B) s8 a - return this.cache(texture, () -> entityCutout(texture), CACHE_B);2 G/ p+ L r6 T& d' ]
- }2 h. B8 u! Y' k! H# ~" I
/ M) l& z& Z9 w- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {8 d9 Q# r6 S1 f6 i: A3 Y4 w9 v4 C
- if (cache.containsKey(identifier)) {# ^$ l# b3 h% `! U' ^
- return cache.get(identifier);4 O! k8 c+ _" C' y* `+ ^& M
- } else {5 Z) L5 h* }& \( X1 `
- final RenderType renderLayer = supplier.get();
1 o$ I+ ~! l! o- ~2 @2 }5 V - cache.put(identifier, renderLayer); u) Q. Y5 J1 k# t$ t
- return renderLayer;9 f5 J' y b2 q
- }6 C3 h+ p+ S* T/ O( z; L
- }$ G; L& r5 o4 f0 [2 r4 s* \7 i) y* a
- }
复制代码 |
|