|
|
! k+ k c$ G4 ^6 L% Z, g$ c
行,这个怎么样
) F9 r' E2 z6 l' S- d& ~) e" {- package com.xhg78999.mtrfac.render;0 |$ S$ o3 @# ^$ @% o$ n/ {
- 3 i' \0 A. a( ~& f/ }+ h$ ?
- import com.mojang.blaze3d.vertex.PoseStack;
! d+ S) {/ S+ y - import com.mojang.blaze3d.vertex.VertexConsumer;
" C# Y7 d5 q6 L0 G - import net.minecraft.client.renderer.RenderType;* ]" r2 l/ h1 F* d' M' y
- import net.minecraft.resources.ResourceLocation;
$ U: L/ I' e5 x0 C H - : n% l+ }6 [$ U5 Z# O [( B
- import java.util.*;
7 ~7 j/ y: e) v# X0 s3 B" U
5 N1 i& n5 M, E- |0 _- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(
5 \ Z7 F# q. y, {. H. g4 f9 d - + T& Y- w# q0 ^! J8 x7 w
- public class LineRender{
/ x- y5 \6 T- h& K/ k - private final PoseStack pose;5 H* [$ b& H% \8 ^4 Y5 D
- private final MultiBufferSource source;* q) k9 o6 C" v- l9 g
- private static final Map<String, RenderType> CACHE_A = new HashMap<>();3 Q! b: b5 c1 k& U
- private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();
. W9 R) a, I Y7 o6 e t- L1 f - ) _# u9 j6 e7 b s: v/ }
- # h0 V6 K' D1 T0 J4 g# S6 C
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
' ]% g. e8 w# Z1 A; N - if(x1 == x2 && y1 == y2 && z1 == z2){6 G0 a! T4 z0 H* N9 @" Y! Z2 `6 D
- return;
6 w% {8 t$ d; G l: Q" r - }/ i% }9 h! u/ K% Y" @
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){
. J& C7 @( E& v# a: n- ^6 q - System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");8 w7 W U# P8 h( n7 D# r# q
- }
. |, l8 @$ r( C) F$ A& O; K - pose.pushPose();
& X) M5 q* u1 p0 [7 y9 P( A - final int newLight = convertLight(6);, O5 D [, s& K8 }
- final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
1 {2 P9 x5 s2 V( X# o( _& m - final float lineHeightSmall = (y2 - y1); r$ |, {. ?! g# |& G% z8 T# `
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
( w/ m4 e1 e7 A: m - pose.popPose();- R2 v7 U; v9 r9 D% k1 l3 Y
- }
3 _* ^/ D+ V# F& X - 0 ^& E: _# ^; L/ H' _+ U
- private RenderType getLayers(String texture, int light) {
i4 l$ v& ? l4 ^) X1 b' Q - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));
: @' Q q8 u- ~! i( J - }
% Z$ b9 i& v" p( u! e - 4 ]" M4 @) x0 p! g1 I) Y
- private RenderType getLightTexture(ResourceLocation texture) {6 {7 I( W$ q8 [9 a7 j( Y) p; U
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);
8 d8 e& M ~' v8 d- e - }' W, @ D. K5 A8 j( Q8 b
- % b# U. S3 i& v* Q
- private RenderType getTexture(ResourceLocation texture) {+ U& j6 M) U [' c7 M- {: w1 W
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);8 ^( O$ S) S2 |" n3 I
- }
* b: g' ~9 T: _+ C - # G8 \+ e6 T6 w. M2 ^
- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {
, J7 V& E# s6 `6 {! V! D# U* k - if (cache.containsKey(identifier)) {
' \- L/ x, z2 B - return cache.get(identifier);% E& y5 C* F8 a# U
- } else {* p3 u! a+ t( p* Z
- final RenderType renderLayer = supplier.get();1 Q" E" P# y' b& g+ w
- cache.put(identifier, renderLayer);$ h3 s; }, m9 `. t [9 y& s
- return renderLayer;
9 g# K3 A7 d! U/ ? W7 C. D - }
; w* N) o9 J9 [6 r - }
% W# Z* b3 p) _' S9 `) H - }
复制代码 |
|