2018-10-21 14:42:30 +02:00
|
|
|
package de.ellpeck.naturesaura.renderers;
|
|
|
|
|
2021-12-06 14:38:12 +01:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
2023-07-08 12:32:27 +02:00
|
|
|
import com.mojang.math.Axis;
|
2020-04-27 22:24:02 +02:00
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
2018-11-21 20:36:55 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.ITrinketItem;
|
|
|
|
import de.ellpeck.naturesaura.api.render.ITrinketItem.RenderType;
|
2021-12-19 16:35:03 +01:00
|
|
|
import de.ellpeck.naturesaura.compat.Compat;
|
2021-12-06 14:38:12 +01:00
|
|
|
import net.minecraft.client.model.PlayerModel;
|
|
|
|
import net.minecraft.client.player.AbstractClientPlayer;
|
|
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderLayerParent;
|
|
|
|
import net.minecraft.client.renderer.entity.layers.RenderLayer;
|
|
|
|
import net.minecraft.world.effect.MobEffects;
|
|
|
|
import net.minecraft.world.entity.Pose;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.Item;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2021-12-19 16:35:03 +01:00
|
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
import top.theillusivec4.curios.api.CuriosApi;
|
2018-10-21 14:42:30 +02:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-12-06 14:38:12 +01:00
|
|
|
public class PlayerLayerTrinkets extends RenderLayer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> {
|
2018-10-21 14:42:30 +02:00
|
|
|
|
|
|
|
private final Set<Item> alreadyRendered = new HashSet<>();
|
|
|
|
|
2021-12-06 14:38:12 +01:00
|
|
|
public PlayerLayerTrinkets(RenderLayerParent<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> p_117346_) {
|
|
|
|
super(p_117346_);
|
2020-01-21 23:02:39 +01:00
|
|
|
}
|
|
|
|
|
2018-10-21 14:42:30 +02:00
|
|
|
@Override
|
2021-12-06 14:38:12 +01:00
|
|
|
public void render(PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn, AbstractClientPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
|
2020-04-27 22:24:02 +02:00
|
|
|
if (!ModConfig.instance.renderItemsOnPlayer.get())
|
|
|
|
return;
|
2021-12-06 14:38:12 +01:00
|
|
|
if (player.getEffect(MobEffects.INVISIBILITY) != null)
|
2018-10-21 14:42:30 +02:00
|
|
|
return;
|
2021-12-06 14:38:12 +01:00
|
|
|
var main = player.getMainHandItem();
|
|
|
|
var second = player.getOffhandItem();
|
2018-10-21 14:42:30 +02:00
|
|
|
|
|
|
|
this.alreadyRendered.clear();
|
2021-12-06 14:38:12 +01:00
|
|
|
matrixStackIn.pushPose();
|
2020-01-29 19:04:33 +01:00
|
|
|
this.render(player, RenderType.BODY, main, second, matrixStackIn, bufferIn, packedLightIn);
|
2021-12-06 14:38:12 +01:00
|
|
|
var yaw = player.yHeadRotO + (player.yHeadRot - player.yHeadRotO) * partialTicks;
|
|
|
|
var yawOffset = player.yBodyRotO + (player.yBodyRot - player.yBodyRotO) * partialTicks;
|
|
|
|
var pitch = player.xRotO + (player.getXRot() - player.xRotO) * partialTicks;
|
2023-07-08 12:32:27 +02:00
|
|
|
matrixStackIn.mulPose(Axis.YN.rotationDegrees(yawOffset));
|
|
|
|
matrixStackIn.mulPose(Axis.YP.rotationDegrees(yaw - 270));
|
|
|
|
matrixStackIn.mulPose(Axis.ZP.rotationDegrees(pitch));
|
2020-01-29 19:04:33 +01:00
|
|
|
this.render(player, RenderType.HEAD, main, second, matrixStackIn, bufferIn, packedLightIn);
|
2021-12-06 14:38:12 +01:00
|
|
|
matrixStackIn.popPose();
|
2018-10-21 14:42:30 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:38:12 +01:00
|
|
|
private void render(Player player, RenderType type, ItemStack main, ItemStack second, PoseStack matrices, MultiBufferSource buffer, int packedLight) {
|
|
|
|
for (var i = 0; i < player.getInventory().getContainerSize(); i++) {
|
|
|
|
this.renderStack(player.getInventory().getItem(i), player, type, main, second, matrices, buffer, packedLight);
|
2018-10-21 14:42:30 +02:00
|
|
|
}
|
|
|
|
|
2021-12-19 16:35:03 +01:00
|
|
|
if (Compat.hasCompat("curios")) {
|
2020-09-22 16:16:25 +02:00
|
|
|
IItemHandler handler = CuriosApi.getCuriosHelper().getEquippedCurios(player).orElse(null);
|
2020-01-26 19:26:50 +01:00
|
|
|
if (handler != null) {
|
2021-12-19 16:35:03 +01:00
|
|
|
for (var i = 0; i < handler.getSlots(); i++)
|
2020-09-22 16:16:25 +02:00
|
|
|
this.renderStack(handler.getStackInSlot(i), player, type, main, second, matrices, buffer, packedLight);
|
|
|
|
}
|
2021-12-19 16:35:03 +01:00
|
|
|
}
|
2018-10-21 14:42:30 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:38:12 +01:00
|
|
|
private void renderStack(ItemStack stack, Player player, RenderType type, ItemStack main, ItemStack second, PoseStack matrices, MultiBufferSource buffer, int packedLight) {
|
2018-10-21 14:42:30 +02:00
|
|
|
if (!stack.isEmpty()) {
|
2021-12-06 14:38:12 +01:00
|
|
|
var item = stack.getItem();
|
2018-10-21 14:42:30 +02:00
|
|
|
if (item instanceof ITrinketItem && !this.alreadyRendered.contains(item)) {
|
2021-12-06 14:38:12 +01:00
|
|
|
matrices.pushPose();
|
2020-01-29 19:04:33 +01:00
|
|
|
if (type == RenderType.BODY && player.getPose() == Pose.CROUCHING) {
|
|
|
|
matrices.translate(0F, 0.2F, 0F);
|
2023-07-08 12:32:27 +02:00
|
|
|
matrices.mulPose(Axis.XP.rotationDegrees(90F / (float) Math.PI));
|
2018-10-21 14:51:07 +02:00
|
|
|
}
|
2020-01-29 19:04:33 +01:00
|
|
|
((ITrinketItem) item).render(stack, player, type, matrices, buffer, packedLight, stack == main || stack == second);
|
2021-12-06 14:38:12 +01:00
|
|
|
matrices.popPose();
|
2018-10-21 14:42:30 +02:00
|
|
|
this.alreadyRendered.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-08 12:32:27 +02:00
|
|
|
}
|