2018-10-21 14:42:30 +02:00
|
|
|
package de.ellpeck.naturesaura.renderers;
|
|
|
|
|
|
|
|
import baubles.api.BaublesApi;
|
2018-11-21 20:36:55 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.ITrinketItem;
|
|
|
|
import de.ellpeck.naturesaura.api.render.ITrinketItem.RenderType;
|
2018-10-21 14:42:30 +02:00
|
|
|
import de.ellpeck.naturesaura.compat.Compat;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.MobEffects;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class PlayerLayerTrinkets implements LayerRenderer<EntityPlayer> {
|
|
|
|
|
|
|
|
private final Set<Item> alreadyRendered = new HashSet<>();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doRenderLayer(@Nonnull EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
|
|
|
|
if (player.getActivePotionEffect(MobEffects.INVISIBILITY) != null)
|
|
|
|
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();
|
|
|
|
GlStateManager.color(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;
|
|
|
|
GlStateManager.rotate(yawOffset, 0, -1, 0);
|
|
|
|
GlStateManager.rotate(yaw - 270, 0, 1, 0);
|
|
|
|
GlStateManager.rotate(pitch, 0, 0, 1);
|
2018-11-02 21:10:53 +01:00
|
|
|
this.render(player, RenderType.HEAD, main, second);
|
2018-10-21 14:42:30 +02:00
|
|
|
GlStateManager.popMatrix();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-02 21:10:53 +01:00
|
|
|
private void render(EntityPlayer 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
|
|
|
}
|
|
|
|
|
|
|
|
if (Compat.baubles) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 21:10:53 +01:00
|
|
|
private void renderStack(ItemStack stack, EntityPlayer 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()) {
|
|
|
|
GlStateManager.translate(0F, 0.2F, 0F);
|
|
|
|
GlStateManager.rotate(90F / (float) Math.PI, 1.0F, 0.0F, 0.0F);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|