Guest User

ModSubscribeEvents

a guest
May 12th, 2021
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Mod.EventBusSubscriber(modid = Main.MOD_ID)
  2. public class ModSubscribeEvents {
  3.  
  4. @SubscribeEvent
  5. public static void onTextureStitch(TextureStitchEvent.Pre event){
  6. if (event.getMap().getTextureLocation().equals(AtlasTexture.LOCATION_BLOCKS_TEXTURE)){
  7. event.addSprite(new ResourceLocation(Main.MOD_ID, "block/sfire_0"));
  8. event.addSprite(new ResourceLocation(Main.MOD_ID, "block/sfire_1"));
  9. }
  10. }
  11.  
  12. RenderMaterial LOCATION_SFIRE_0 = new RenderMaterial(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(Main.MOD_ID, "block/sfire_0"));
  13. RenderMaterial LOCATION_SFIRE_1 = new RenderMaterial(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(Main.MOD_ID, "block/sfire_1"));
  14.  
  15. @SubscribeEvent
  16. public void onRenderEntity(RenderLivingEvent.Pre event) {
  17. Entity entityIn = event.getEntity();
  18. if (entityIn.isAlive() && entityIn.getEntityWorld().isRemote
  19. && !(entityIn instanceof PlayerEntity) && (Config.COMMON.sRendering.get() == 1)) {
  20.  
  21. EntityRenderer<? super Entity> entityrenderer = event.getRenderer();
  22. MatrixStack matrixStackIn = event.getMatrixStack();
  23. IRenderTypeBuffer bufferIn = event.getBuffers();
  24. int packedLightIn = event.getLight();
  25.  
  26. float partialTicks = event.getPartialRenderTick();
  27. double xIn = MathHelper.lerp(partialTicks, entityIn.lastTickPosX, entityIn.getPosX());
  28. double yIn = MathHelper.lerp(partialTicks, entityIn.lastTickPosY, entityIn.getPosY());
  29. double zIn = MathHelper.lerp(partialTicks, entityIn.lastTickPosZ, entityIn.getPosZ());
  30. float rotationYawIn = MathHelper.lerp(partialTicks, entityIn.prevRotationYaw, entityIn.rotationYaw);
  31.  
  32. Vector3d vector3d = entityrenderer.getRenderOffset(entityIn, partialTicks);
  33. double d2 = xIn + vector3d.getX();
  34. double d3 = yIn + vector3d.getY();
  35. double d0 = zIn + vector3d.getZ();
  36. matrixStackIn.push();
  37. matrixStackIn.translate(d2, d3, d0);
  38. entityrenderer.render(entityIn, rotationYawIn, partialTicks, matrixStackIn, bufferIn, packedLightIn);
  39.  
  40. if (flag) { //flag is defined somewhere else, but it works correctly
  41. this.renderSFire(matrixStackIn, bufferIn, entityIn, rotationYawIn);
  42. }
  43. matrixStackIn.translate(-vector3d.getX(), -vector3d.getY(), -vector3d.getZ());
  44. matrixStackIn.pop();
  45. }
  46. }
  47.  
  48. private void renderSFire(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, Entity entityIn, float entityYaw) {
  49. TextureAtlasSprite textureatlassprite = LOCATION_SFIRE_0.getSprite();
  50. TextureAtlasSprite textureatlassprite1 = LOCATION_SFIRE_1.getSprite();
  51.  
  52. matrixStackIn.push();
  53. float f = entityIn.getWidth() * 1.4F;
  54. matrixStackIn.scale(f, f, f);
  55. float f1 = 0.5F;
  56. float f3 = entityIn.getHeight() / f;
  57. float f4 = 0.0F;
  58. ActiveRenderInfo activerenderinfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
  59. matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-activerenderinfo.getYaw()));
  60. matrixStackIn.translate(0.0D, 0.0D, -0.3F + (float)((int)f3) * 0.02F);
  61. float f5 = 0.0F;
  62. int i = 0;
  63. IVertexBuilder ivertexbuilder = bufferIn.getBuffer(Atlases.getCutoutBlockType());
  64.  
  65. for(MatrixStack.Entry matrixstack$entry = matrixStackIn.getLast(); f3 > 0.0F; ++i) {
  66. TextureAtlasSprite textureatlassprite2 = i % 2 == 0 ? textureatlassprite : textureatlassprite1;
  67. float f6 = textureatlassprite2.getMinU();
  68. float f7 = textureatlassprite2.getMinV();
  69. float f8 = textureatlassprite2.getMaxU();
  70. float f9 = textureatlassprite2.getMaxV();
  71. if (i / 2 % 2 == 0) {
  72. float f10 = f8;
  73. f8 = f6;
  74. f6 = f10;
  75. }
  76. fireVertex(matrixstack$entry, ivertexbuilder, f1 - 0.0F, 0.0F - f4, f5, f8, f9);
  77. fireVertex(matrixstack$entry, ivertexbuilder, -f1 - 0.0F, 0.0F - f4, f5, f6, f9);
  78. fireVertex(matrixstack$entry, ivertexbuilder, -f1 - 0.0F, 1.4F - f4, f5, f6, f7);
  79. fireVertex(matrixstack$entry, ivertexbuilder, f1 - 0.0F, 1.4F - f4, f5, f8, f7);
  80. f3 -= 0.45F;
  81. f4 -= 0.45F;
  82. f1 *= 0.9F;
  83. f5 += 0.03F;
  84. }
  85. matrixStackIn.pop();
  86. }
  87. private static void fireVertex(MatrixStack.Entry matrixEntryIn, IVertexBuilder bufferIn, float x, float y, float z, float texU, float texV) {
  88. bufferIn.pos(matrixEntryIn.getMatrix(), x, y, z).color(255, 255, 255, 255).tex(texU, texV).overlay(0, 10).lightmap(240).normal(matrixEntryIn.getNormal(), 0.0F, 1.0F, 0.0F).endVertex();
  89. }
  90. }
RAW Paste Data