|
1
|
|
|
package de.pewpewproject.lasertag.entity.render.armor; |
|
2
|
|
|
|
|
3
|
|
|
import de.pewpewproject.lasertag.item.Items; |
|
4
|
|
|
import de.pewpewproject.lasertag.item.LasertagVestItem; |
|
5
|
|
|
import net.minecraft.client.MinecraftClient; |
|
6
|
|
|
import net.minecraft.client.render.OverlayTexture; |
|
7
|
|
|
import net.minecraft.client.render.RenderLayer; |
|
8
|
|
|
import net.minecraft.client.render.VertexConsumerProvider; |
|
9
|
|
|
import net.minecraft.client.render.entity.model.BipedEntityModel; |
|
10
|
|
|
import net.minecraft.client.util.math.MatrixStack; |
|
11
|
|
|
import net.minecraft.entity.EquipmentSlot; |
|
12
|
|
|
import net.minecraft.entity.LivingEntity; |
|
13
|
|
|
import net.minecraft.entity.player.PlayerEntity; |
|
14
|
|
|
import net.minecraft.item.ItemStack; |
|
15
|
|
|
import software.bernie.geckolib3.core.processor.IBone; |
|
16
|
|
|
import software.bernie.geckolib3.renderers.geo.GeoArmorRenderer; |
|
17
|
|
|
import software.bernie.geckolib3.util.GeoUtils; |
|
18
|
|
|
|
|
19
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Renderer for the lasertag vest |
|
23
|
|
|
* |
|
24
|
|
|
* @author Étienne Muser |
|
25
|
|
|
*/ |
|
26
|
|
|
public class LasertagVestRenderer extends GeoArmorRenderer<LasertagVestItem> { |
|
27
|
|
|
|
|
28
|
|
|
private static final LasertagVestModel VEST_MODEL = new LasertagVestModel(); |
|
29
|
|
|
private static final LasertagVestLightsModel LIGHTS_MODEL = new LasertagVestLightsModel(); |
|
30
|
|
|
|
|
31
|
|
|
public LasertagVestRenderer() { |
|
32
|
|
|
super(VEST_MODEL); |
|
33
|
|
|
|
|
34
|
|
|
this.headBone = "armorHead"; |
|
35
|
|
|
this.bodyBone = "armorBody"; |
|
36
|
|
|
this.rightArmBone = "armorRightArm"; |
|
37
|
|
|
this.leftArmBone = "armorLeftArm"; |
|
38
|
|
|
this.rightLegBone = "armorRightLeg"; |
|
39
|
|
|
this.leftLegBone = "armorLeftLeg"; |
|
40
|
|
|
this.rightBootBone = "armorRightBoot"; |
|
41
|
|
|
this.leftBootBone = "armorLeftBoot"; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
@Override |
|
45
|
|
|
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, ItemStack stack, LivingEntity entity, |
|
46
|
|
|
EquipmentSlot slot, int light, BipedEntityModel<LivingEntity> contextModel) { |
|
47
|
|
|
this.setModel(VEST_MODEL); |
|
48
|
|
|
super.render(matrices, vertexConsumers, stack, entity, slot, light, contextModel); |
|
49
|
|
|
|
|
50
|
|
|
this.setModel(LIGHTS_MODEL); |
|
51
|
|
|
RenderLayer cameo = RenderLayer.getEyes(LIGHTS_MODEL.getTextureResource(null)); |
|
52
|
|
|
matrices.push(); |
|
53
|
|
|
|
|
54
|
|
|
matrices.translate(0.0D, 1.497F, 0.0D); |
|
55
|
|
|
matrices.scale(-1.005F, -1.0F, 1.005F); |
|
56
|
|
|
|
|
57
|
|
|
var lightsModel = LIGHTS_MODEL.getModel(LIGHTS_MODEL.getModelResource(null)); |
|
58
|
|
|
|
|
59
|
|
|
if (this.bodyBone != null) { |
|
60
|
|
|
IBone bodyBone = LIGHTS_MODEL.getBone(this.bodyBone); |
|
61
|
|
|
GeoUtils.copyRotations(contextModel.body, bodyBone); |
|
62
|
|
|
bodyBone.setPositionX(contextModel.body.pivotX); |
|
63
|
|
|
bodyBone.setPositionY(-contextModel.body.pivotY); |
|
64
|
|
|
bodyBone.setPositionZ(contextModel.body.pivotZ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// Default color is black |
|
68
|
|
|
AtomicReference<Float> r = new AtomicReference<>((float) 0); |
|
69
|
|
|
AtomicReference<Float> g = new AtomicReference<>((float) 0); |
|
70
|
|
|
AtomicReference<Float> b = new AtomicReference<>((float) 0); |
|
71
|
|
|
|
|
72
|
|
|
// If player is activated |
|
73
|
|
View Code Duplication |
if (entity instanceof PlayerEntity) { |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
// Get the game managers |
|
76
|
|
|
var gameManager = MinecraftClient.getInstance().world.getClientLasertagManager(); |
|
77
|
|
|
var activationManager = gameManager.getActivationManager(); |
|
78
|
|
|
var teamsManager = gameManager.getTeamsManager(); |
|
79
|
|
|
var teamsConfigState = gameManager.getSyncedState().getTeamsConfigState(); |
|
80
|
|
|
|
|
81
|
|
|
boolean isDeactivated = activationManager.isDeactivated(entity.getUuid()); |
|
82
|
|
|
|
|
83
|
|
|
if (!isDeactivated) { |
|
84
|
|
|
teamsManager.getTeamOfPlayer(entity.getUuid()).ifPresent(teamId -> { |
|
85
|
|
|
|
|
86
|
|
|
var team = teamsConfigState.getTeamOfId(teamId).orElseThrow(); |
|
87
|
|
|
|
|
88
|
|
|
var color = team.color(); |
|
89
|
|
|
|
|
90
|
|
|
r.set(color.r() / 255.0F); |
|
91
|
|
|
g.set(color.g() / 255.0F); |
|
92
|
|
|
b.set(color.b() / 255.0F); |
|
93
|
|
|
}); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
this.render(lightsModel, (LasertagVestItem) Items.LASERTAG_VEST, 1.0F, cameo, matrices, vertexConsumers, vertexConsumers.getBuffer(cameo), 255, OverlayTexture.DEFAULT_UV, r.get(), g.get(), b.get(), 1.0F); |
|
98
|
|
|
matrices.pop(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|