|
|
% o4 K! C# D# p/ \9 m行,这个怎么样1 i" e) h7 h8 M3 u( k, K6 J
- package com.xhg78999.mtrfac.render;$ r; {9 L' ]/ g9 L# }6 k
0 L* U% d- Y0 P8 s: w$ X' A8 `- import com.mojang.blaze3d.vertex.PoseStack;
! Q( b! w- u" o$ U6 u; z( r$ f+ y - import com.mojang.blaze3d.vertex.VertexConsumer; a4 g: i$ J* E. `7 g
- import net.minecraft.client.renderer.RenderType;
' A' p" L6 T/ V, H. O - import net.minecraft.resources.ResourceLocation;) X8 O% ?( j2 ?/ m8 q) V
4 {* `* q4 [; Y ~4 |3 B( z* f: g- import java.util.*;
# t% p2 b. e8 H9 H
; K( p6 e( ^/ ]1 e- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
2 N: s2 q6 o0 |- E% O5 M* ]% ` - & N% w! Z/ T+ Y0 ]1 L
- public class LineRender{
4 E* c1 d1 I, f8 S - private final PoseStack pose;
: F' Z% A' L/ {9 r - private final MultiBufferSource source;( j B1 o% U. c6 x
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' a) b% Z4 s7 E5 B' O& B1 `2 m - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
2 A- |. {+ p" t! c8 t8 Y! V - " |% k1 q4 R. w
6 q Y( k- S2 p9 c' @3 I3 q# j I& N- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
6 ?6 n7 Z. S8 w( E! U, ^9 C - if(x1 == x2 && y1 == y2 && z1 == z2){5 q/ _6 |. b9 E% t
- return;
: \( H* H. K7 ^+ m( o2 C - }7 x m# U+ Z. j$ h9 u1 N
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){# \( Y* h3 N1 @
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");
/ b# l* J1 k. \6 j# i$ M - }
5 B9 V) |0 f& T' } U - pose.pushPose();+ F8 ]! R" e; a& f0 {
- final int newLight = convertLight(6);: h4 V5 T/ y; ]* o% I
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false)); M! i0 y9 |: k5 e- I" p% H
- final float lineHeightSmall = (y2 - y1);* J; D1 R6 u4 ~# v: v. q
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
% D; T) }5 S$ N2 |$ o V4 D% d - pose.popPose();; X3 @6 N+ q! a- {% E8 b g
- }
} b$ b2 ^. j6 P0 k - 6 m% y$ P0 K# `) J8 S- T& y
- private RenderType getLayers(String texture, int light) {
( d! u5 O d6 J0 x. I& P6 e - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
# N ?# a. u: N# s1 B - }- t l$ \; D0 Q8 j% u$ \. q
& B8 T! J$ c" T: G! @- private RenderType getLightTexture(ResourceLocation texture) {
3 C) S$ X/ E! V- Y$ N - return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
) O1 d0 ?8 l7 R9 ~2 G2 A, q - }
7 X7 g- @- S' _6 T! B- T( H8 w/ s1 n - , }' V' ^9 L8 n
- private RenderType getTexture(ResourceLocation texture) {
) O1 D2 J+ Z$ x* R; W/ e5 d - return this.cache(texture, () -> entityCutout(texture), CACHE_B);) ?8 N- J, S1 K) m: p+ X* v+ t4 f2 }0 S
- }* t, {: d5 z3 }( [
- 5 H, J* g o6 j
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
* F+ n3 A- l- P u - if (cache.containsKey(identifier)) {
3 i" y0 }2 v0 h4 V' m - return cache.get(identifier);: z+ S- s0 B) @$ ~$ s
- } else {) Q) S0 r# O: V) x3 u" @1 f g
- final RenderType renderLayer = supplier.get();/ y6 }# ~6 ?# j: P3 F
- cache.put(identifier, renderLayer); }- z9 I* s" l' I
- return renderLayer;
# H9 y( b" n0 i! @) x7 L5 Q" s1 G( r" V - }
# m" S# x7 l8 P( ~9 w) z h& E J- C - }2 W, q+ k. L B* A' N6 d9 E6 u, H% h
- }
复制代码 |
|