2019-03-23 20:49:34 +01:00
|
|
|
package com.minelittlepony.client.render;
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-07-08 04:47:13 +02:00
|
|
|
import com.minelittlepony.client.MineLittlePony;
|
2019-03-23 20:58:50 +01:00
|
|
|
import com.minelittlepony.pony.IPony;
|
2019-11-29 19:11:31 +01:00
|
|
|
import com.minelittlepony.util.math.Color;
|
2019-11-23 18:28:42 +01:00
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
|
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
2019-11-23 18:28:42 +01:00
|
|
|
import net.minecraft.client.render.OverlayTexture;
|
2019-11-29 19:11:31 +01:00
|
|
|
import net.minecraft.client.render.RenderLayer;
|
2019-11-23 18:28:42 +01:00
|
|
|
import net.minecraft.client.render.VertexConsumerProvider;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.render.item.ItemRenderer;
|
|
|
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
2019-11-30 11:14:24 +01:00
|
|
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
2019-11-23 18:28:42 +01:00
|
|
|
import net.minecraft.client.util.math.MatrixStack;
|
|
|
|
import net.minecraft.client.util.math.Vector3f;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2018-05-26 23:37:50 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-07-20 20:16:54 +02:00
|
|
|
import net.minecraft.util.Arm;
|
2019-11-30 11:14:24 +01:00
|
|
|
import net.minecraft.util.Identifier;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.util.UseAction;
|
2019-11-23 18:28:42 +01:00
|
|
|
import net.minecraft.world.World;
|
2019-05-27 17:59:15 +02:00
|
|
|
|
2018-05-26 23:37:50 +02:00
|
|
|
public class LevitatingItemRenderer {
|
|
|
|
|
2019-11-29 19:11:31 +01:00
|
|
|
static int tint;
|
2019-06-27 11:48:59 +02:00
|
|
|
private static boolean usingTransparency;
|
|
|
|
|
|
|
|
public static boolean usesTransparency() {
|
|
|
|
return usingTransparency;
|
2018-08-20 22:24:22 +02:00
|
|
|
}
|
|
|
|
|
2019-11-30 11:14:24 +01:00
|
|
|
public static RenderLayer getRenderLayer(Identifier texture) {
|
|
|
|
if (!usesTransparency()) {
|
|
|
|
return RenderLayer.getEntityTranslucent(texture);
|
|
|
|
}
|
|
|
|
return MagicGlow.getTintedTexturedLayer(texture, Color.r(tint), Color.g(tint), Color.b(tint), 0.8F);
|
|
|
|
}
|
|
|
|
|
2019-11-29 19:11:31 +01:00
|
|
|
public static RenderLayer getRenderLayer() {
|
2019-11-30 11:14:24 +01:00
|
|
|
return getRenderLayer(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
|
2019-11-29 19:11:31 +01:00
|
|
|
}
|
|
|
|
|
2018-05-26 23:37:50 +02:00
|
|
|
/**
|
|
|
|
* Renders a magical overlay over an item in third person.
|
|
|
|
*/
|
2019-11-23 18:28:42 +01:00
|
|
|
public void renderItemGlow(LivingEntity entity, ItemStack drop, ModelTransformation.Type transform, Arm hand, int glowColor, MatrixStack stack, VertexConsumerProvider renderContext) {
|
2018-05-26 23:37:50 +02:00
|
|
|
setColor(glowColor);
|
2019-11-29 19:11:31 +01:00
|
|
|
stack.push();
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-05-27 17:59:15 +02:00
|
|
|
ItemRenderer renderItem = MinecraftClient.getInstance().getItemRenderer();
|
2019-06-27 11:48:59 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
stack.scale(1.1F, 1.1F, 1.1F);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
stack.translate(0.01F, 0.01F, 0.01F);
|
|
|
|
renderItem.method_23177(entity, drop, transform, hand == Arm.LEFT, stack, renderContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV);
|
|
|
|
stack.translate(-0.02F, -0.02F, -0.02F);
|
|
|
|
renderItem.method_23177(entity, drop, transform, hand == Arm.LEFT, stack, renderContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
stack.pop();
|
2019-11-29 19:11:31 +01:00
|
|
|
unsetColor();
|
2018-05-26 23:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setColor(int glowColor) {
|
2019-11-29 19:11:31 +01:00
|
|
|
usingTransparency = true;
|
|
|
|
tint = glowColor;
|
2018-05-26 23:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void unsetColor() {
|
2019-11-29 19:11:31 +01:00
|
|
|
usingTransparency = false;
|
|
|
|
tint = 0;
|
2018-05-26 23:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders an item in first person optionally with a magical overlay.
|
|
|
|
*/
|
2019-11-30 11:14:24 +01:00
|
|
|
public void renderItemInFirstPerson(ItemRenderer itemRenderer, @Nullable AbstractClientPlayerEntity entity, ItemStack stack, ModelTransformation.Type transform, boolean left, MatrixStack matrix, VertexConsumerProvider renderContext, @Nullable World world, int lightUv) {
|
2018-08-30 16:12:21 +02:00
|
|
|
IPony pony = MineLittlePony.getInstance().getManager().getPony(entity);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
matrix.push();
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-07-12 17:06:03 +02:00
|
|
|
boolean doMagic = MineLittlePony.getInstance().getConfig().fpsmagic.get() && pony.getMetadata().hasMagic();
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
if (doMagic) {
|
2019-11-23 18:28:42 +01:00
|
|
|
setupPerspective(itemRenderer, entity, stack, left, matrix);
|
2018-05-26 23:37:50 +02:00
|
|
|
}
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
if (doMagic) {
|
|
|
|
setColor(pony.getMetadata().getGlowColor());
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
matrix.scale(1.1F, 1.1F, 1.1F);
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
matrix.translate(0.015F, 0.01F, 0.01F);
|
|
|
|
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
|
|
|
matrix.translate(-0.03F, -0.02F, -0.02F);
|
|
|
|
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
2019-03-24 18:55:15 +01:00
|
|
|
|
2018-05-26 23:37:50 +02:00
|
|
|
unsetColor();
|
|
|
|
}
|
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
matrix.pop();
|
2018-05-26 23:37:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves held items to look like they're floating in the player's field.
|
|
|
|
*/
|
2019-11-23 18:28:42 +01:00
|
|
|
private void setupPerspective(ItemRenderer renderer, LivingEntity entity, ItemStack item, boolean left, MatrixStack stack) {
|
|
|
|
UseAction action = item.getUseAction();
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-06-11 12:22:58 +02:00
|
|
|
boolean doNormal = entity.getItemUseTime() <= 0 || action == UseAction.NONE || action == UseAction.CROSSBOW;
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items.
|
2019-05-28 01:50:45 +02:00
|
|
|
float ticks = MinecraftClient.getInstance().getTickDelta() - entity.age;
|
2018-05-26 23:37:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
boolean handHeldTool =
|
|
|
|
action == UseAction.BOW
|
2019-06-11 12:22:58 +02:00
|
|
|
|| action == UseAction.CROSSBOW
|
|
|
|
|| action == UseAction.BLOCK;
|
2018-05-26 23:37:50 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
stack.translate(driftAmount - floatAmount / 4, floatAmount, handHeldTool ? -0.3F : -0.6F);
|
2018-08-22 12:31:24 +02:00
|
|
|
|
2019-11-23 18:28:42 +01:00
|
|
|
if (/*!renderer.hasDepthInGui(item) && */!handHeldTool) { // bows have to point forwards
|
|
|
|
int sign = left ? 1 : -1;
|
|
|
|
stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(sign * -60));
|
|
|
|
stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(sign * 30));
|
2018-05-26 23:37:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|