Advertisement
Vaerys_Dawn

BeeLayer.java

Feb 3rd, 2021
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.44 KB | None | 0 0
  1.  
  2. @OnlyIn(Dist.CLIENT)
  3. public class BeeLayer extends LayerRenderer<CustomBeeEntity, CustomBeeModel<CustomBeeEntity>> {
  4.  
  5.     private final boolean isEmissive;
  6.     private final int glowingPulse;
  7.     private final boolean isEnchanted;
  8.     private final CustomBeeModel<CustomBeeEntity> additionModel;
  9.     private final ResourceLocation layerTexture;
  10.     private final ResourceLocation angerLayerTexture;
  11.     private float[] color;
  12.     private final boolean isRainbowBee;
  13.  
  14.     public BeeLayer(IEntityRenderer<CustomBeeEntity, CustomBeeModel<CustomBeeEntity>> renderer, CustomBeeRenderer.LayerType layerType, ModelTypes addition, ColorData colorData) {
  15.         super(renderer);
  16.         this.additionModel = addition == ModelTypes.DEFAULT ? null : new CustomBeeModel<>(addition);
  17.         this.isRainbowBee = colorData.isRainbowBee();
  18.         this.isEnchanted = colorData.isEnchanted();
  19.         this.glowingPulse = colorData.getGlowingPulse();
  20.  
  21.         switch (layerType) {
  22.             case PRIMARY:
  23.                 this.isEmissive = false;
  24.                 this.layerTexture = ResourceLocation.tryCreate(ResourcefulBees.MOD_ID + ":" + BeeConstants.ENTITY_TEXTURES_DIR + colorData.getPrimaryLayerTexture() + ".png");
  25.                 this.angerLayerTexture = ResourceLocation.tryCreate(ResourcefulBees.MOD_ID + ":" + BeeConstants.ENTITY_TEXTURES_DIR + colorData.getPrimaryLayerTexture() + "_angry.png");
  26.                 this.color = isRainbowBee ? RainbowColor.getColorFloats() : colorData.getPrimaryColorFloats();
  27.                 break;
  28.             case SECONDARY:
  29.                 this.isEmissive = false;
  30.                 this.layerTexture = ResourceLocation.tryCreate(ResourcefulBees.MOD_ID + ":" + BeeConstants.ENTITY_TEXTURES_DIR + colorData.getSecondaryLayerTexture() + ".png");
  31.                 this.angerLayerTexture = ResourceLocation.tryCreate(ResourcefulBees.MOD_ID + ":" + BeeConstants.ENTITY_TEXTURES_DIR + colorData.getSecondaryLayerTexture() + "_angry.png");
  32.                 this.color = isRainbowBee ? RainbowColor.getColorFloats() : colorData.getSecondaryColorFloats();
  33.                 break;
  34.             case EMISSIVE:
  35.                 this.isEmissive = true;
  36.                 this.layerTexture = ResourceLocation.tryCreate(ResourcefulBees.MOD_ID + ":" + BeeConstants.ENTITY_TEXTURES_DIR + colorData.getEmissiveLayerTexture() + ".png");
  37.                 this.angerLayerTexture = ResourceLocation.tryCreate(ResourcefulBees.MOD_ID + ":" + BeeConstants.ENTITY_TEXTURES_DIR + colorData.getEmissiveLayerTexture() + "_angry.png");
  38.                 this.color = isRainbowBee ? RainbowColor.getColorFloats() : colorData.getGlowColorFloats();
  39.                 break;
  40.             default:
  41.                 throw new IllegalStateException("You dun screwed up, did you add a new layer?");
  42.         }
  43.     }
  44.  
  45.     @Override
  46.     public void render(@Nonnull MatrixStack matrixStackIn, @Nonnull IRenderTypeBuffer bufferIn, int packedLightIn, @Nonnull CustomBeeEntity customBeeEntity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
  47.         if (isRainbowBee) color = RainbowColor.getColorFloats();
  48.         ResourceLocation texture = customBeeEntity.hasAngerTime() && angerLayerTexture != null ? angerLayerTexture : layerTexture;
  49.         if (texture == null) texture = BeeConstants.MISSING_TEXTURE;
  50.  
  51.         if (additionModel != null) {
  52.             this.getEntityModel().setModelAttributes(additionModel);
  53.             additionModel.setLivingAnimations(customBeeEntity, limbSwing, limbSwingAmount, partialTicks);
  54.             additionModel.setAngles(customBeeEntity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
  55.         }
  56.  
  57.         if (isEmissive) {
  58.             if (isEnchanted) {
  59.                 this.getEntityModel().render(matrixStackIn, bufferIn.getBuffer(RenderType.getEntityGlint()), packedLightIn, OverlayTexture.DEFAULT_UV, 0.0F, 0.0F, 0.0F, 0.0F);
  60.                 if (additionModel != null) {
  61.                     additionModel.render(matrixStackIn, bufferIn.getBuffer(RenderType.getEntityGlint()), packedLightIn, LivingRenderer.getOverlay(customBeeEntity, 0.0F), 0.0F, 0.0F, 0.0F, 0.0F);
  62.                 }
  63.             } else {
  64.                 IVertexBuilder ivertexbuilder = bufferIn.getBuffer(RenderType.getEyes(texture));
  65.                 if (glowingPulse == 0 || customBeeEntity.ticksExisted / 5 % glowingPulse == 0) {
  66.                     this.getEntityModel().render(matrixStackIn, ivertexbuilder, 15728640, OverlayTexture.DEFAULT_UV, color[0], color[1], color[2], 1.0F);
  67.                     if (additionModel != null) {
  68.                         additionModel.render(matrixStackIn, ivertexbuilder, 15728640, LivingRenderer.getOverlay(customBeeEntity, 0.0F), color[0], color[1], color[2], 1.0F);
  69.                     }
  70.                 }
  71.             }
  72.         } else {
  73.             if (!Files.exists(Paths.get("resources/assets/" + texture.getPath()))) {
  74.                 System.out.println("ANGERY");
  75.             }
  76.  
  77.             renderModel(this.getEntityModel(), texture, matrixStackIn, bufferIn, packedLightIn, customBeeEntity, color[0], color[1], color[2]);
  78.  
  79.  
  80.             if (additionModel != null) {
  81.                 IVertexBuilder ivertexbuilder = bufferIn.getBuffer(RenderType.getEntityTranslucent(texture));
  82.                 additionModel.render(matrixStackIn, ivertexbuilder, packedLightIn, LivingRenderer.getOverlay(customBeeEntity, 0.0F), color[0], color[1], color[2], 1.0F);
  83.             }
  84.         }
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement