2018-10-21 14:42:30 +02:00
|
|
|
package de.ellpeck.naturesaura.renderers;
|
|
|
|
|
2020-01-21 23:02:39 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2018-11-21 20:36:55 +01:00
|
|
|
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;
|
2018-10-21 14:42:30 +02:00
|
|
|
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;
|
2018-10-21 14:42:30 +02:00
|
|
|
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;
|
2018-10-21 14:42:30 +02:00
|
|
|
|
|
|
|
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>> {
|
2018-10-21 14:42:30 +02:00
|
|
|
|
|
|
|
private final Set<Item> alreadyRendered = new HashSet<>();
|
|
|
|
|
2020-01-21 23:02:39 +01:00
|
|
|
public PlayerLayerTrinkets(IEntityRenderer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>> entityRendererIn) {
|
|
|
|
super(entityRendererIn);
|
|
|
|
}
|
|
|
|
|
2018-10-21 14:42:30 +02:00
|
|
|
@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)
|
2018-10-21 14:42:30 +02:00
|
|
|
return;
|
2018-11-02 21:10:53 +01:00
|
|
|
ItemStack main = player.getHeldItemMainhand();
|
|
|
|
ItemStack second = player.getHeldItemOffhand();
|
2018-10-21 14:42:30 +02:00
|
|
|
|
|
|
|
this.alreadyRendered.clear();
|
|
|
|
GlStateManager.pushMatrix();
|
2020-01-24 20:49:09 +01:00
|
|
|
GlStateManager.pushLightingAttributes();
|
|
|
|
GlStateManager.pushTextureAttributes();
|
2020-01-21 23:02:39 +01:00
|
|
|
GlStateManager.color4f(1F, 1F, 1F, 1F);
|
2018-11-02 21:10:53 +01:00
|
|
|
this.render(player, RenderType.BODY, main, second);
|
2018-10-21 14:42:30 +02:00
|
|
|
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);
|
2018-11-02 21:10:53 +01:00
|
|
|
this.render(player, RenderType.HEAD, main, second);
|
2020-01-24 20:49:09 +01:00
|
|
|
GlStateManager.popAttributes();
|
|
|
|
GlStateManager.popAttributes();
|
2018-10-21 14:42:30 +02:00
|
|
|
GlStateManager.popMatrix();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private void render(PlayerEntity player, RenderType type, ItemStack main, ItemStack second) {
|
2018-10-21 14:42:30 +02:00
|
|
|
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
2018-11-02 21:10:53 +01:00
|
|
|
this.renderStack(player.inventory.getStackInSlot(i), player, type, main, second);
|
2018-10-21 14:42:30 +02:00
|
|
|
}
|
|
|
|
|
2020-01-21 23:02:39 +01:00
|
|
|
/*if (Compat.baubles) { TODO baubles
|
2018-10-21 14:42:30 +02:00
|
|
|
IItemHandler baubles = BaublesApi.getBaublesHandler(player);
|
|
|
|
for (int i = 0; i < baubles.getSlots(); i++) {
|
2018-11-02 21:10:53 +01:00
|
|
|
this.renderStack(baubles.getStackInSlot(i), player, type, main, second);
|
2018-10-21 14:42:30 +02:00
|
|
|
}
|
2020-01-21 23:02:39 +01:00
|
|
|
}*/
|
2018-10-21 14:42:30 +02:00
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
private void renderStack(ItemStack stack, PlayerEntity player, RenderType type, ItemStack main, ItemStack second) {
|
2018-10-21 14:42:30 +02:00
|
|
|
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
|
|
|
}
|
2018-11-02 21:10:53 +01:00
|
|
|
((ITrinketItem) item).render(stack, player, type, stack == main || stack == second);
|
2018-10-21 14:42:30 +02:00
|
|
|
GlStateManager.popMatrix();
|
|
|
|
this.alreadyRendered.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldCombineTextures() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|