|
|
7 m: y" i7 m9 H# r [行,这个怎么样/ w3 \ E2 I5 H; a# r. r
- package com.xhg78999.mtrfac.render;; ~; ~0 ]$ p$ ?9 L" j
/ e- S% `7 g* s. @- import com.mojang.blaze3d.vertex.PoseStack;( s2 r6 r/ \* S9 r3 [6 p# S
- import com.mojang.blaze3d.vertex.VertexConsumer;4 p* b* _! R$ w7 o
- import net.minecraft.client.renderer.RenderType;" t& s/ G$ j! b4 B+ M; m2 M
- import net.minecraft.resources.ResourceLocation;2 d" N1 y' R. f% P4 x
- / ~. X/ u3 L! r8 ]7 b2 o$ B5 _
- import java.util.*;
4 B2 W3 q Y+ C1 e5 w
% J' i" n7 c/ q8 _- // Render!Vertex!Textures!Aaaaaaaaaaaaaaaaaaaaa I crashed! :(* h9 X' A) e( i% {! Q
* c# `9 Y4 j2 b7 X0 |- public class LineRender{
0 f3 V' S# S# ^ - private final PoseStack pose;6 [$ N( D8 n( I* U6 o7 P6 x
- private final MultiBufferSource source;
7 [5 w# i9 h/ q8 h" ?1 ^0 d - private static final Map<String, RenderType> CACHE_A = new HashMap<>();
' B: W5 I j5 P7 E8 _. r' U - private static final Map<ResourceLocation, RenderType> CACHE_B = new HashMap<>();) \* `1 q4 I: ]3 o! @ ]6 b
* i; \% Z! |* ~! D; ]- / B' T0 N p& l! k& \. m4 Y
- public void renderLine(float x1, float y1, float z1, float x2, float y2, float z2){
5 R' e# q. Q' L7 K1 C. v - if(x1 == x2 && y1 == y2 && z1 == z2){
7 k' y$ `$ j; q% m) s0 v* P - return;! {, A( l* _! a: @1 x5 B
- }3 k' |! x( j( y
- if((x1 == 114514 && z1 == 114514) || (x1 == -114514 && z1 == -114514)){1 b5 d$ x8 d( ~- r
- System.out.printIn("Looks like you put it in a henhenaaaaaaa pos. Oh, Homo is everywhere! :)");% [ ~! m3 B4 H0 \9 ?( v
- }4 p% h. U( r- M7 n d& ?! h
- pose.pushPose();$ U- T$ @7 A3 S9 \/ g
- final int newLight = convertLight(6);
( ?0 h: V: a' l/ n0 Y1 R - final VertexConsumer vertexs = source.getBuffer(getRenderLayer("mtrfac:textures/custom_render/lines.png", newLight, false));
$ Y' V3 ^$ C6 t9 } - final float lineHeightSmall = (y2 - y1);5 ~; e9 s$ E+ {$ y$ G4 `1 r6 A
- this.draw(pose, source, x1, y1 + lineHeightSmall * i, z1, x2, y1 + lineHeightSmall * (i + 1), z2, facing, 0xFF000000, newLight);
+ q8 z* U- o+ W0 [ - pose.popPose();- k. K* C/ a. z
- }) l( s# S; ]6 i$ A t
8 C& O7 B, k' }) a2 e3 m- private RenderType getLayers(String texture, int light) {
: o' m; k: d& I: I - return light == MAX_LIGHT_GLOWING ? this.getLightTexture(new ResourceLocation(texture)) : this.getTexture(new ResourceLocation(texture));) [. y0 A g: {2 B, @
- }
$ X1 P' i" J; {1 N
C7 I6 b7 ^; E/ E6 p- private RenderType getLightTexture(ResourceLocation texture) {/ |" [3 J* W$ [
- return this.cache(texture.toString() + false, () -> beaconBeam(texture, false), CACHE_A);' M* r& O: |1 Q
- }
" ?5 a: \4 B1 w1 x: g0 k I6 T
' n; M, S. R2 ~- C4 D- private RenderType getTexture(ResourceLocation texture) {7 Y0 }3 q/ U2 n
- return this.cache(texture, () -> entityCutout(texture), CACHE_B);+ \) d i/ f( W; t6 O
- }1 z* x3 a+ m6 y- O. E
9 g% W( F ~$ B1 U6 }, J. T- Q- private static <T> RenderType cache(T identifier, Supplier<RenderType> supplier, Map<T, RenderType> cache) {9 N. i' n, V/ b, ?. ^9 [% W# x, I
- if (cache.containsKey(identifier)) {
" q# U0 E; w! q. r - return cache.get(identifier);! k/ y" V) R2 v! ]9 [
- } else {
* |( f) N3 B" u8 z0 C - final RenderType renderLayer = supplier.get();
9 m' g i6 O& N' a6 p$ s6 C* z: ? - cache.put(identifier, renderLayer);
; h2 }3 ?1 t: C; [7 ?0 Y - return renderLayer;& W, L* w+ u% j* v) {" F
- }) m9 P3 e8 l1 Z, U; ~
- }
( D- D0 ^" y" q! G) H Z - }
复制代码 |
|