|
|
$ x3 K' V7 G; c/ k
行,这个怎么样/ ^& o' _; K6 [! L
- package com.xhg78999.mtrfac.render;
`. x+ r. e7 N2 S* k1 J - # N; Z$ K+ F6 z6 j) K/ E& g
- import com.mojang.blaze3d.vertex.PoseStack;
# y9 Y) t" i$ _6 y" | - import com.mojang.blaze3d.vertex.VertexConsumer;7 F2 L2 x; e% t; m- j5 r
- import net.minecraft.client.renderer.RenderType;1 _+ s+ M- L% E: l6 |# e# r
- import net.minecraft.resources.ResourceLocation;& m* t0 X6 N' k, e; ~
8 u+ h' w; f, v0 c1 P- import java.util.*;
9 a, p. l, ?) V% N0 X( c
) y0 `; f, \* Z; z+ O- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
$ z+ E! w( o4 G7 `3 H
. M0 s' B: A+ u$ e S9 W" o- public class LineRender{
9 [0 I' g6 |. [ r3 T& M - private final PoseStack pose;5 b) A U6 f5 o$ h
- private final MultiBufferSource source;0 ^" L& S( @* a# Z( D' ?
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();, M( m, V, {- E/ i3 }3 q- @9 O9 w+ s
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* ?5 c5 y$ _# ^5 S" ~ - F8 e3 z" \* f$ \6 F
. B- ?3 T! x1 I) k4 P1 n/ E- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
4 H5 M9 t! a5 _- v, c" B - if(x1 == x2 && y1 == y2 && z1 == z2){
% k2 x, y/ H4 m$ b1 f3 J - return;
6 b4 Z8 ]% I" G$ ~6 ^ - }
' V" T3 V( X$ Q - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
; U3 B: w+ ^* o C* c) ?7 e - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");" ^( t! Z- r4 o8 T, _
- }
4 _$ W$ G) Q! O - pose.pushPose();
" n) B/ y1 E- Q- b( M6 R7 \ - final int newLight = convertLight(6);0 b2 N$ ^/ \3 H# x1 [
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));7 p& u0 l# M( t% L5 w
- final float lineHeightSmall = (y2 - y1);
" k# Q, o0 W" z& x b - this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);$ S1 [/ L5 s% [" {5 `3 U
- pose.popPose();
# V9 n( q- R+ I1 u$ j! b R - }
) T; g* c( {& e
) W' i" n! M8 U, ^- private RenderType getLayers(String texture, int light) {
8 b) S" [/ e+ r1 u% W. m3 L/ y: ^ - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));/ B/ M/ z& @1 p; E
- }
4 P7 a+ B# L: d: }) {2 y - % [. W% R' W$ ~
- private RenderType getLightTexture(ResourceLocation texture) { C6 h2 ^: l! X. M+ k- m
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);9 q/ K6 {, v- S" O2 u& v( Q4 D! L8 I
- }( B9 @+ i, Q' o; F* K* ~
- $ c6 ?0 G+ [& D* U0 S0 R9 N
- private RenderType getTexture(ResourceLocation texture) {
; {& a. |5 d! T/ _ - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
( M9 t0 Y" e3 a5 ^& |0 K - }
" g# v1 @' k' |- h1 H4 o3 @
5 G0 L' @/ W( ^% R- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {/ q) o" k1 K+ k
- if (cache.containsKey(identifier)) {+ l1 }2 g/ P+ ]- | h j8 K
- return cache.get(identifier);
- N) o7 b: e' ^8 T - } else {3 S) T$ ]- ?( M- E
- final RenderType renderLayer = supplier.get();# a, {" {) b% O+ _- J
- cache.put(identifier, renderLayer);' g0 P+ f1 b: ~# j0 r
- return renderLayer;1 U% r) H E# K0 i* C0 |
- }* N: E6 ] W1 ~
- }/ q4 s) w; [1 S y- I# G2 e: M
- }
复制代码 |
|