2121import mekanism .client .render .RenderResizableCuboid .FaceDisplay ;
2222import mekanism .common .base .ProfilerConstants ;
2323import mekanism .common .tile .machine .TileEntityNutritionalLiquifier ;
24+ import net .minecraft .client .Camera ;
2425import net .minecraft .client .Minecraft ;
2526import net .minecraft .client .ParticleStatus ;
27+ import net .minecraft .client .multiplayer .ClientLevel ;
28+ import net .minecraft .client .particle .SingleQuadParticle ;
2629import net .minecraft .client .renderer .MultiBufferSource ;
2730import net .minecraft .client .renderer .Sheets ;
2831import net .minecraft .client .renderer .block .model .BakedQuad ;
2932import net .minecraft .client .renderer .blockentity .BlockEntityRendererProvider ;
3033import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
34+ import net .minecraft .client .resources .model .BakedModel ;
3135import net .minecraft .core .Direction ;
3236import net .minecraft .util .Mth ;
3337import net .minecraft .util .profiling .ProfilerFiller ;
@@ -102,7 +106,7 @@ protected void render(TileEntityNutritionalLiquifier tile, float partialTick, Po
102106 pseudoParticles .lastTick = tile .getLevel ().getGameTime ();
103107 pseudoParticles .particles .removeIf (PseudoParticle ::tick );
104108 }
105- int rate = Minecraft .getInstance ().options .particles ().get () == ParticleStatus .DECREASED ? 12 : 4 ;
109+ int rate = Minecraft .getInstance ().options .particles ().get () == ParticleStatus .DECREASED ? 10 : 3 ;
106110 if (tile .getLevel ().getGameTime () % rate == 0 ) {
107111 pseudoParticles .particles .add (new PseudoParticle (tile .getLevel (), stack ));
108112 }
@@ -175,6 +179,7 @@ private static class PseudoParticle {
175179 protected float bbHeight = 1.8F ;
176180
177181 protected PseudoParticle (Level world , ItemStack stack ) {
182+ //Particle Constructor
178183 setSize (0.2F , 0.2F );
179184 this .x = (world .random .nextFloat () - 0.5D ) * 0.3D ;
180185 this .y = (world .random .nextFloat () - 0.5D ) * 0.3D ;
@@ -184,6 +189,7 @@ protected PseudoParticle(Level world, ItemStack stack) {
184189 this .zo = z ;
185190 this .lifetime = (int ) (4.0F / (world .random .nextFloat () * 0.9F + 0.1F ));
186191
192+ //Particle Constructor that takes speed
187193 this .xd = (Math .random () * 2.0D - 1.0D ) * 0.4 ;
188194 this .yd = (Math .random () * 2.0D - 1.0D ) * 0.4 ;
189195 this .zd = (Math .random () * 2.0D - 1.0D ) * 0.4 ;
@@ -193,12 +199,19 @@ protected PseudoParticle(Level world, ItemStack stack) {
193199 this .yd = (this .yd / f1 ) * f * 0.4 + 0.1 ;
194200 this .zd = (this .zd / f1 ) * f * 0.4 ;
195201
196- sprite = Minecraft .getInstance ().getItemRenderer ().getModel (stack , world , null , 0 ).getParticleIcon (ModelData .EMPTY );
202+ //BreakingItemParticle Constructor
203+ BakedModel model = Minecraft .getInstance ().getItemRenderer ().getModel (stack , world , null , 0 );
204+ BakedModel override = model .getOverrides ().resolve (model , stack , world instanceof ClientLevel level ? level : null , null , 0 );
205+ if (override != null ) {
206+ model = override ;
207+ }
208+ sprite = model .getParticleIcon (ModelData .EMPTY );
197209 this .gravity = 1.0F ;
198210 this .quadSize = 0.1F * (world .random .nextFloat () * 0.5F + 0.5F );
199211 this .uo = world .random .nextFloat () * 3.0F ;
200212 this .vo = world .random .nextFloat () * 3.0F ;
201213
214+ //BreakingItemParticle Constructor that takes speed
202215 this .xd *= 0.1 ;
203216 this .yd *= 0.1 ;
204217 this .zd *= 0.1 ;
@@ -208,12 +221,12 @@ protected PseudoParticle(Level world, ItemStack stack) {
208221 }
209222
210223 public boolean tick () {
211- if (this .age ++ >= this .lifetime || this .y < -0.25 ) {
212- return true ;
213- }
214224 this .xo = this .x ;
215225 this .yo = this .y ;
216226 this .zo = this .z ;
227+ if (this .age ++ >= this .lifetime || this .y < -0.25 ) {
228+ return true ;
229+ }
217230 this .yd -= 0.04D * this .gravity ;
218231 if (this .xd != 0.0D || this .yd != 0.0D || this .zd != 0.0D ) {
219232 bb = bb .move (this .xd , this .yd , this .zd );
@@ -228,38 +241,36 @@ public boolean tick() {
228241 }
229242
230243 public void render (Matrix4f matrix , VertexConsumer buffer , float partialTicks , int light ) {
244+ Camera camera = Minecraft .getInstance ().getEntityRenderDispatcher ().camera ;
245+ //From SingleQuadParticle#render
246+ Quaternionf quaternion = new Quaternionf ();
247+ SingleQuadParticle .FacingCameraMode .LOOKAT_XYZ .setRotation (quaternion , camera , partialTicks );
248+
249+ //From SingleQuadParticle#renderRotatedQuad
231250 float f = (float ) Mth .lerp (partialTicks , this .xo , this .x );
232251 float f1 = (float ) Mth .lerp (partialTicks , this .yo , this .y );
233252 float f2 = (float ) Mth .lerp (partialTicks , this .zo , this .z );
234- Quaternionf quaternion = Minecraft .getInstance ().getEntityRenderDispatcher ().camera .rotation ();
235-
236- Vector3f [] vectors = {new Vector3f (-1.0F , -1.0F , 0.0F ), new Vector3f (-1.0F , 1.0F , 0.0F ),
237- new Vector3f (1.0F , 1.0F , 0.0F ), new Vector3f (1.0F , -1.0F , 0.0F )};
238- for (int i = 0 ; i < 4 ; ++i ) {
239- Vector3f vector3f = vectors [i ];
240- quaternion .transform (vector3f );
241- vector3f .mul (quadSize );
242- vector3f .add (f , f1 , f2 );
243- }
253+ renderRotatedQuad (matrix , buffer , quaternion , f , f1 , f2 , light );
254+ }
244255
256+ //Copy of SingleQuadParticle#renderRotatedQuad
257+ protected void renderRotatedQuad (Matrix4f matrix ,VertexConsumer buffer , Quaternionf quaternion , float x , float y , float z , int light ) {
245258 float minU = this .getU0 ();
246259 float maxU = this .getU1 ();
247260 float minV = this .getV0 ();
248261 float maxV = this .getV1 ();
249- buffer .addVertex (matrix , vectors [0 ].x (), vectors [0 ].y (), vectors [0 ].z ())
250- .setUv (maxU , maxV )
251- .setColor (0xFF , 0xFF , 0xFF , 0xFF )
252- .setLight (light );
253- buffer .addVertex (matrix , vectors [1 ].x (), vectors [1 ].y (), vectors [1 ].z ())
254- .setUv (maxU , minV )
255- .setColor (0xFF , 0xFF , 0xFF , 0xFF )
256- .setLight (light );
257- buffer .addVertex (matrix , vectors [2 ].x (), vectors [2 ].y (), vectors [2 ].z ())
258- .setUv (minU , minV )
259- .setColor (0xFF , 0xFF , 0xFF , 0xFF )
260- .setLight (light );
261- buffer .addVertex (matrix , vectors [3 ].x (), vectors [3 ].y (), vectors [3 ].z ())
262- .setUv (minU , maxV )
262+ this .renderVertex (matrix , buffer , quaternion , x , y , z , 1.0F , -1.0F , maxU , maxV , light );
263+ this .renderVertex (matrix , buffer , quaternion , x , y , z , 1.0F , 1.0F , maxU , minV , light );
264+ this .renderVertex (matrix , buffer , quaternion , x , y , z , -1.0F , 1.0F , minU , minV , light );
265+ this .renderVertex (matrix , buffer , quaternion , x , y , z , -1.0F , -1.0F , minU , maxV , light );
266+ }
267+
268+ //Copy of SingleQuadParticle#renderVertex
269+ private void renderVertex (Matrix4f matrix , VertexConsumer buffer , Quaternionf quaternion , float x , float y , float z , float xOffset , float yOffset , float u ,
270+ float v , int light ) {
271+ Vector3f vector3f = new Vector3f (xOffset , yOffset , 0.0F ).rotate (quaternion ).mul (quadSize ).add (x , y , z );
272+ buffer .addVertex (matrix , vector3f .x (), vector3f .y (), vector3f .z ())
273+ .setUv (u , v )
263274 .setColor (0xFF , 0xFF , 0xFF , 0xFF )
264275 .setLight (light );
265276 }
0 commit comments