2018-05-26 23:37:50 +02:00
|
|
|
package com.minelittlepony.render;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL14;
|
|
|
|
|
|
|
|
import com.minelittlepony.MineLittlePony;
|
|
|
|
import com.minelittlepony.ducks.IRenderItem;
|
2018-08-30 16:12:21 +02:00
|
|
|
import com.minelittlepony.pony.data.IPony;
|
2018-09-05 10:12:38 +02:00
|
|
|
import com.minelittlepony.render.skull.PonySkullRenderer;
|
|
|
|
import com.minelittlepony.util.render.Color;
|
2018-05-26 23:37:50 +02:00
|
|
|
import com.mumfrey.liteloader.client.overlays.IMinecraft;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
2018-08-20 22:24:22 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2018-05-26 23:37:50 +02:00
|
|
|
import net.minecraft.client.renderer.ItemRenderer;
|
|
|
|
import net.minecraft.client.renderer.RenderItem;
|
2018-08-20 22:24:22 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager.DestFactor;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
|
2018-05-26 23:37:50 +02:00
|
|
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumHandSide;
|
|
|
|
import static net.minecraft.client.renderer.GlStateManager.*;
|
|
|
|
|
|
|
|
public class LevitatingItemRenderer {
|
|
|
|
|
2018-08-20 22:24:22 +02:00
|
|
|
public static void enableItemGlowRenderProfile() {
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO);
|
|
|
|
Minecraft.getMinecraft().entityRenderer.disableLightmap();
|
|
|
|
}
|
|
|
|
|
2018-05-26 23:37:50 +02:00
|
|
|
/**
|
|
|
|
* Renders a magical overlay over an item in third person.
|
|
|
|
*/
|
|
|
|
public void renderItemGlow(EntityLivingBase entity, ItemStack drop, TransformType transform, EnumHandSide hand, int glowColor) {
|
|
|
|
pushMatrix();
|
|
|
|
disableLighting();
|
|
|
|
setColor(glowColor);
|
|
|
|
|
|
|
|
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
|
|
|
|
((IRenderItem) renderItem).useTransparency(true);
|
2018-06-20 23:54:41 +02:00
|
|
|
PonySkullRenderer.ponyInstance.useTransparency(true);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
scale(1.1, 1.1, 1.1);
|
|
|
|
|
|
|
|
translate(0, 0.01F, 0.01F);
|
|
|
|
renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT);
|
|
|
|
translate(0.01F, -0.01F, -0.02F);
|
|
|
|
renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT);
|
|
|
|
|
|
|
|
((IRenderItem) renderItem).useTransparency(false);
|
2018-06-20 23:54:41 +02:00
|
|
|
PonySkullRenderer.ponyInstance.useTransparency(false);
|
2018-05-26 23:37:50 +02:00
|
|
|
unsetColor();
|
|
|
|
enableLighting();
|
|
|
|
popMatrix();
|
|
|
|
|
|
|
|
// I hate rendering
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setColor(int glowColor) {
|
|
|
|
GL14.glBlendColor(Color.r(glowColor), Color.g(glowColor), Color.b(glowColor), 0.2F);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unsetColor() {
|
|
|
|
GL14.glBlendColor(255, 255, 255, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders an item in first person optionally with a magical overlay.
|
|
|
|
*/
|
|
|
|
public void renderItemInFirstPerson(ItemRenderer renderer, AbstractClientPlayer entity, ItemStack stack, TransformType transform, boolean left) {
|
2018-08-30 16:12:21 +02:00
|
|
|
IPony pony = MineLittlePony.getInstance().getManager().getPony(entity);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
pushMatrix();
|
|
|
|
|
2018-06-10 09:37:15 +02:00
|
|
|
boolean doMagic = MineLittlePony.getConfig().fpsmagic && pony.getMetadata().hasMagic();
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
if (doMagic) {
|
|
|
|
setupPerspective(entity, stack, left);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.renderItemSide(entity, stack, transform, left);
|
|
|
|
|
|
|
|
if (doMagic) {
|
|
|
|
disableLighting();
|
|
|
|
|
|
|
|
IRenderItem renderItem = (IRenderItem)Minecraft.getMinecraft().getRenderItem();
|
|
|
|
renderItem.useTransparency(true);
|
2018-06-20 23:41:08 +02:00
|
|
|
PonySkullRenderer.ponyInstance.useTransparency(true);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
setColor(pony.getMetadata().getGlowColor());
|
|
|
|
|
|
|
|
scale(1.1, 1.1, 1.1);
|
|
|
|
|
2018-08-18 14:15:05 +02:00
|
|
|
translate(-0.015F, 0.01F, 0.01F);
|
2018-05-26 23:37:50 +02:00
|
|
|
renderer.renderItemSide(entity, stack, transform, left);
|
2018-08-18 14:15:05 +02:00
|
|
|
translate(0.03F, -0.01F, -0.02F);
|
2018-05-26 23:37:50 +02:00
|
|
|
renderer.renderItemSide(entity, stack, transform, left);
|
|
|
|
|
|
|
|
renderItem.useTransparency(false);
|
2018-06-20 23:41:08 +02:00
|
|
|
PonySkullRenderer.ponyInstance.useTransparency(false);
|
|
|
|
|
2018-05-26 23:37:50 +02:00
|
|
|
unsetColor();
|
|
|
|
enableLighting();
|
|
|
|
}
|
|
|
|
|
|
|
|
popMatrix();
|
|
|
|
|
|
|
|
// I hate rendering
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves held items to look like they're floating in the player's field.
|
|
|
|
*/
|
|
|
|
private void setupPerspective(EntityLivingBase entity, ItemStack stack, boolean left) {
|
|
|
|
EnumAction action = stack.getItemUseAction();
|
|
|
|
|
|
|
|
boolean doNormal = entity.getItemInUseCount() <= 0 || action == EnumAction.NONE;
|
|
|
|
|
|
|
|
if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items.
|
|
|
|
float ticks = ((IMinecraft)Minecraft.getMinecraft()).getTimer().elapsedPartialTicks - entity.ticksExisted;
|
|
|
|
|
|
|
|
float floatAmount = (float)Math.sin(ticks / 9) / 40;
|
2018-06-29 19:25:08 +02:00
|
|
|
float driftAmount = (float)Math.cos(ticks / 6) / 40;
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2018-08-22 12:31:24 +02:00
|
|
|
boolean handHeldTool = stack.getItemUseAction() == EnumAction.BOW
|
|
|
|
|| stack.getItemUseAction() == EnumAction.BLOCK;
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2018-08-22 12:31:24 +02:00
|
|
|
translate(driftAmount - floatAmount / 4, floatAmount, handHeldTool ? -0.3F : -0.6F);
|
|
|
|
|
|
|
|
if (!stack.getItem().isFull3D() && !handHeldTool) { // bows have to point forwards
|
2018-05-26 23:37:50 +02:00
|
|
|
if (left) {
|
|
|
|
rotate(-60, 0, 1, 0);
|
|
|
|
rotate(30, 0, 0, 1);
|
|
|
|
} else {
|
|
|
|
rotate(60, 0, 1, 0);
|
|
|
|
rotate(-30, 0, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|