/
ButterflyEggRenderer.java
86 lines (79 loc) · 3.08 KB
/
ButterflyEggRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.bokmcdok.butterflies.client.renderer.entity;
import com.bokmcdok.butterflies.client.model.ButterflyEggModel;
import com.bokmcdok.butterflies.world.entity.animal.ButterflyEgg;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;
/**
* Renderer for a butterfly egg entity.
*/
@OnlyIn(Dist.CLIENT)
public class ButterflyEggRenderer extends MobRenderer<ButterflyEgg, ButterflyEggModel> {
/**
* Construction
* @param context The current rendering context.
*/
public ButterflyEggRenderer(EntityRendererProvider.Context context) {
super(context, new ButterflyEggModel(context.bakeLayer(ButterflyEggModel.LAYER_LOCATION)), 0.05F);
}
/**
* Gets the texture to use.
* @param entity The entity.
* @return The texture to use for this entity.
*/
@Override
@NotNull
public ResourceLocation getTextureLocation(@NotNull ButterflyEgg entity) {
return entity.getTexture();
}
/**
* Scale the entity down.
* @param entity The entity.
* @param poses The current entity pose.
* @param scale The scale that should be applied.
*/
@Override
protected void scale(@NotNull ButterflyEgg entity,
PoseStack poses,
float scale) {
float s = entity.getScale();
poses.scale(s, s, s);
}
/**
* Rotates the butterfly egg so it's attached to its block.
* @param entity The butterfly egg entity.
* @param p_115456_ Unknown.
* @param p_115457_ Unknown.
* @param poseStack The posed model to render.
* @param multiBufferSource The render buffer.
* @param p_115460_ Unknown.
*/
@Override
public void render(@NotNull ButterflyEgg entity,
float p_115456_,
float p_115457_,
@NotNull PoseStack poseStack,
@NotNull MultiBufferSource multiBufferSource,
int p_115460_) {
Direction direction = entity.getSurfaceDirection();
if (direction == Direction.UP) {
poseStack.mulPose(Axis.XP.rotationDegrees(180.f));
} else if (direction == Direction.NORTH) {
poseStack.mulPose(Axis.XP.rotationDegrees(90.f));
} else if (direction == Direction.SOUTH) {
poseStack.mulPose(Axis.XP.rotationDegrees(-90.f));
} else if (direction == Direction.WEST) {
poseStack.mulPose(Axis.ZP.rotationDegrees(-90.f));
} else if (direction == Direction.EAST){
poseStack.mulPose(Axis.ZP.rotationDegrees(90.f));
}
super.render(entity, p_115456_, p_115457_, poseStack, multiBufferSource, p_115460_);
}
}