NaturesAura/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java

89 lines
3.9 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.renderers;
2020-01-21 23:02:39 +01:00
import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.naturesaura.api.render.ITrinketItem;
import de.ellpeck.naturesaura.api.render.ITrinketItem.RenderType;
2020-01-21 23:02:39 +01:00
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.renderer.entity.IEntityRenderer;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
2020-01-21 23:02:39 +01:00
import net.minecraft.client.renderer.entity.model.PlayerModel;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2020-01-21 23:02:39 +01:00
import net.minecraft.potion.Effects;
2019-10-20 22:30:49 +02:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.Set;
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2020-01-21 23:02:39 +01:00
public class PlayerLayerTrinkets extends LayerRenderer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>> {
private final Set<Item> alreadyRendered = new HashSet<>();
2020-01-21 23:02:39 +01:00
public PlayerLayerTrinkets(IEntityRenderer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>> entityRendererIn) {
super(entityRendererIn);
}
@Override
2020-01-21 23:02:39 +01:00
public void render(@Nonnull AbstractClientPlayerEntity player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
2019-10-20 22:30:49 +02:00
if (player.getActivePotionEffect(Effects.INVISIBILITY) != null)
return;
ItemStack main = player.getHeldItemMainhand();
ItemStack second = player.getHeldItemOffhand();
this.alreadyRendered.clear();
GlStateManager.pushMatrix();
GlStateManager.pushLightingAttributes();
GlStateManager.pushTextureAttributes();
2020-01-21 23:02:39 +01:00
GlStateManager.color4f(1F, 1F, 1F, 1F);
this.render(player, RenderType.BODY, main, second);
float yaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks;
float yawOffset = player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialTicks;
float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;
2020-01-21 23:02:39 +01:00
GlStateManager.rotatef(yawOffset, 0, -1, 0);
GlStateManager.rotatef(yaw - 270, 0, 1, 0);
GlStateManager.rotatef(pitch, 0, 0, 1);
this.render(player, RenderType.HEAD, main, second);
GlStateManager.popAttributes();
GlStateManager.popAttributes();
GlStateManager.popMatrix();
}
2019-10-20 22:30:49 +02:00
private void render(PlayerEntity player, RenderType type, ItemStack main, ItemStack second) {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
this.renderStack(player.inventory.getStackInSlot(i), player, type, main, second);
}
2020-01-21 23:02:39 +01:00
/*if (Compat.baubles) { TODO baubles
IItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); i++) {
this.renderStack(baubles.getStackInSlot(i), player, type, main, second);
}
2020-01-21 23:02:39 +01:00
}*/
}
2019-10-20 22:30:49 +02:00
private void renderStack(ItemStack stack, PlayerEntity player, RenderType type, ItemStack main, ItemStack second) {
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (item instanceof ITrinketItem && !this.alreadyRendered.contains(item)) {
GlStateManager.pushMatrix();
2018-10-21 14:51:07 +02:00
if (type == RenderType.BODY && player.isSneaking()) {
2020-01-21 23:02:39 +01:00
GlStateManager.translatef(0F, 0.2F, 0F);
GlStateManager.rotatef(90F / (float) Math.PI, 1.0F, 0.0F, 0.0F);
2018-10-21 14:51:07 +02:00
}
((ITrinketItem) item).render(stack, player, type, stack == main || stack == second);
GlStateManager.popMatrix();
this.alreadyRendered.add(item);
}
}
}
@Override
public boolean shouldCombineTextures() {
return false;
}
}