|
|
Q/ t& S+ U& S6 V& J8 q行,这个怎么样
- Y# q" F# E* I8 c1 i+ y- package com.xhg78999.mtrfac.render;
1 V: |5 Y9 f: X9 r9 D; z: b. ~ - 4 R. ]6 B# M6 W/ L4 g! Q; k
- import com.mojang.blaze3d.vertex.PoseStack;
3 W: b2 }& x6 X$ n0 u& r/ i6 L - import com.mojang.blaze3d.vertex.VertexConsumer;
1 o1 N6 M+ j! i& F7 X) \ - import net.minecraft.client.renderer.RenderType;/ h" O' O9 G, A' f
- import net.minecraft.resources.ResourceLocation;
$ r* Z- w8 I7 L0 h: T- x# {+ v5 v
. D/ d2 y2 g+ }, y- import java.util.*;# @ F! A- B$ Y! A4 Z
- . Y0 G- h1 P! s* V- M% V9 p
- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(" _. \. I4 B: R' q% z
0 X/ ?9 A" P$ r, K- i- public class LineRender{
, f5 ]2 b" c' A* c2 E _* u - private final PoseStack pose;" t, f; E* ?* [) ?
- private final MultiBufferSource source;9 {# K# U2 v( l8 R
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();* ?; V' _- c9 W* `
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
* ^. s* u$ M. P* |. j; B4 s; a1 ` - ( a3 u- o; _/ @* C8 W% x
2 ^1 M' y0 a1 K f( \- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
; N. i0 p; Z7 i2 ]) I - if(x1 == x2 && y1 == y2 && z1 == z2){
8 q, k% K( P" [ - return;3 q* b$ k" `9 e `* l4 i
- }
4 C; p* g# n. ]' N/ K" w- y" V1 J - if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){2 F. ~( p5 m6 a1 `, d
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");+ k" `* c- `0 `' F
- }+ G+ t$ M' q( G- Q" o
- pose.pushPose();
8 v9 D8 J2 t, G - final int newLight = convertLight(6);
8 o5 r. ~( P, {+ W# D& h* _ - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));5 a9 I- {2 z' _$ Q1 p
- final float lineHeightSmall = (y2 - y1);* K4 M4 o3 V! A% Q' b R$ a; g
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);2 i8 D# _( @: y( i k7 U0 I9 [) P
- pose.popPose();! s _7 r9 s% W B9 Z3 \7 l
- }! @0 f* l5 \% N# r+ c9 A
- ! w. |) q, q/ D0 d! H. a8 w' X
- private RenderType getLayers(String texture, int light) {
+ J! g- s" u6 x2 m( @9 M. B - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
& v- q7 Z1 n' Q, M - }
7 a# r4 F6 g( }/ @* {: A; j
3 x# a4 p g* i6 O6 p- private RenderType getLightTexture(ResourceLocation texture) {! k9 c0 C% Z# I7 c0 C
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);4 \; K7 C2 r4 @5 ?+ r
- }
# N7 U* Q" |9 v8 t$ A - ( ~$ c2 ~# Z0 c2 u2 `
- private RenderType getTexture(ResourceLocation texture) {
2 Q6 w- m# m- f- i' b - return this.cache(texture, () -> entityCutout(texture), CACHE_B);
" u) w! H. c+ o9 Z# t" x8 ~ n - }
2 _) J2 b+ X3 L0 n# H% W7 O - - ?$ ~7 |( u) M+ V$ Y
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {& Y1 k" V7 W, x% D% {) U; r# ` q
- if (cache.containsKey(identifier)) {* ?' J# L( o- W; c9 ]' d- `
- return cache.get(identifier);
* s$ d7 g+ B0 M" e) F2 a; ]! p2 K - } else {
: {$ G9 x( P7 y) e- P9 Y: d: T - final RenderType renderLayer = supplier.get();) `7 S) J2 ^, b; `9 y* S0 R6 l
- cache.put(identifier, renderLayer);
: b( @& R! Y* m - return renderLayer;
5 S1 D2 H; R7 b3 K4 D# E4 y - }
, o0 n t1 ^* D' E5 e- W1 q. c - }
" B7 E: {2 u' g% F; g" N5 c& E/ s - }
复制代码 |
|