mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Fixed item glows
This commit is contained in:
parent
1a6320e6b1
commit
e613886c71
4 changed files with 102 additions and 17 deletions
|
@ -0,0 +1,21 @@
|
||||||
|
package com.minelittlepony.client.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.class_4722;
|
||||||
|
import net.minecraft.client.render.RenderLayer;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import com.minelittlepony.client.render.LevitatingItemRenderer;
|
||||||
|
|
||||||
|
@Mixin(class_4722.class)
|
||||||
|
abstract class MixinClass_4722 {
|
||||||
|
@Inject(method = "method_24075()Lnet/minecraft/client/render/RenderLayer;", at = @At("HEAD"), cancellable = true)
|
||||||
|
private static void onGetEntityTranslucent(CallbackInfoReturnable<RenderLayer> info) {
|
||||||
|
if (LevitatingItemRenderer.usesTransparency()) {
|
||||||
|
info.setReturnValue(LevitatingItemRenderer.getRenderLayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.client.render;
|
||||||
|
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
import com.minelittlepony.pony.IPony;
|
import com.minelittlepony.pony.IPony;
|
||||||
|
import com.minelittlepony.util.math.Color;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||||
import net.minecraft.client.render.FirstPersonRenderer;
|
import net.minecraft.client.render.FirstPersonRenderer;
|
||||||
import net.minecraft.client.render.OverlayTexture;
|
import net.minecraft.client.render.OverlayTexture;
|
||||||
|
import net.minecraft.client.render.RenderLayer;
|
||||||
import net.minecraft.client.render.VertexConsumerProvider;
|
import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
import net.minecraft.client.render.item.ItemRenderer;
|
import net.minecraft.client.render.item.ItemRenderer;
|
||||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
|
@ -22,22 +24,23 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public class LevitatingItemRenderer {
|
public class LevitatingItemRenderer {
|
||||||
|
|
||||||
|
static int tint;
|
||||||
private static boolean usingTransparency;
|
private static boolean usingTransparency;
|
||||||
|
|
||||||
public static boolean usesTransparency() {
|
public static boolean usesTransparency() {
|
||||||
return usingTransparency;
|
return usingTransparency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RenderLayer getRenderLayer() {
|
||||||
|
return MagicGlow.getTintedLayer(Color.r(tint), Color.g(tint), Color.b(tint), 0.8F);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a magical overlay over an item in third person.
|
* Renders a magical overlay over an item in third person.
|
||||||
*/
|
*/
|
||||||
public void renderItemGlow(LivingEntity entity, ItemStack drop, ModelTransformation.Type transform, Arm hand, int glowColor, MatrixStack stack, VertexConsumerProvider renderContext) {
|
public void renderItemGlow(LivingEntity entity, ItemStack drop, ModelTransformation.Type transform, Arm hand, int glowColor, MatrixStack stack, VertexConsumerProvider renderContext) {
|
||||||
|
|
||||||
// TODO: mixin into RenderLayer.getItemLayer(itemstack) to enable transparency
|
|
||||||
usingTransparency = true;
|
|
||||||
|
|
||||||
stack.push();
|
|
||||||
setColor(glowColor);
|
setColor(glowColor);
|
||||||
|
stack.push();
|
||||||
|
|
||||||
ItemRenderer renderItem = MinecraftClient.getInstance().getItemRenderer();
|
ItemRenderer renderItem = MinecraftClient.getInstance().getItemRenderer();
|
||||||
|
|
||||||
|
@ -48,19 +51,18 @@ public class LevitatingItemRenderer {
|
||||||
stack.translate(-0.02F, -0.02F, -0.02F);
|
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);
|
renderItem.method_23177(entity, drop, transform, hand == Arm.LEFT, stack, renderContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV);
|
||||||
|
|
||||||
|
|
||||||
unsetColor();
|
|
||||||
stack.pop();
|
stack.pop();
|
||||||
|
unsetColor();
|
||||||
usingTransparency = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setColor(int glowColor) {
|
private void setColor(int glowColor) {
|
||||||
//GL14.glBlendColor(Color.r(glowColor), Color.g(glowColor), Color.b(glowColor), 0.2F);
|
usingTransparency = true;
|
||||||
|
tint = glowColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unsetColor() {
|
private void unsetColor() {
|
||||||
//GL14.glBlendColor(255, 255, 255, 1);
|
usingTransparency = false;
|
||||||
|
tint = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,8 +84,6 @@ public class LevitatingItemRenderer {
|
||||||
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
||||||
|
|
||||||
if (doMagic) {
|
if (doMagic) {
|
||||||
usingTransparency = true;
|
|
||||||
|
|
||||||
setColor(pony.getMetadata().getGlowColor());
|
setColor(pony.getMetadata().getGlowColor());
|
||||||
|
|
||||||
matrix.scale(1.1F, 1.1F, 1.1F);
|
matrix.scale(1.1F, 1.1F, 1.1F);
|
||||||
|
@ -93,8 +93,6 @@ public class LevitatingItemRenderer {
|
||||||
matrix.translate(-0.03F, -0.02F, -0.02F);
|
matrix.translate(-0.03F, -0.02F, -0.02F);
|
||||||
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
itemRenderer.method_23177(entity, stack, transform, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV);
|
||||||
|
|
||||||
usingTransparency = false;
|
|
||||||
|
|
||||||
unsetColor();
|
unsetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,31 @@ package com.minelittlepony.client.render;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
import net.minecraft.client.render.RenderPhase;
|
import net.minecraft.client.render.RenderPhase;
|
||||||
import net.minecraft.client.render.VertexFormats;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
public class MagicGlow extends RenderPhase {
|
public class MagicGlow extends RenderPhase {
|
||||||
private MagicGlow(String name, Runnable beginAction, Runnable endAction) {
|
private MagicGlow(String name, Runnable beginAction, Runnable endAction) {
|
||||||
super(name, beginAction, endAction);
|
super(name, beginAction, endAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final RenderLayer MAGIC = RenderLayer.method_24048("mlp_magic_glow", VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL, 7, 256, RenderLayer.MultiPhaseData.builder()
|
protected static final RenderPhase.Transparency GLOWING_TRANSPARENCY = new RenderPhase.Transparency("glowing_transparency", () -> {
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFuncSeparate(
|
||||||
|
SourceFactor.CONSTANT_COLOR, DestFactor.ONE,
|
||||||
|
SourceFactor.ONE, DestFactor.ZERO);
|
||||||
|
}, () -> {
|
||||||
|
RenderSystem.disableBlend();
|
||||||
|
RenderSystem.defaultBlendFunc();
|
||||||
|
});
|
||||||
|
|
||||||
|
private static final RenderLayer MAGIC = RenderLayer.method_24048("mlp_magic_glow", VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL, 7, 256, RenderLayer.MultiPhaseData.builder()
|
||||||
.texture(NO_TEXTURE)
|
.texture(NO_TEXTURE)
|
||||||
.transparency(TRANSLUCENT_TRANSPARENCY)
|
.writeMaskState(COLOR_MASK)
|
||||||
|
.transparency(LIGHTNING_TRANSPARENCY)
|
||||||
.lightmap(DISABLE_LIGHTMAP)
|
.lightmap(DISABLE_LIGHTMAP)
|
||||||
.cull(DISABLE_CULLING)
|
.cull(DISABLE_CULLING)
|
||||||
.build(false));
|
.build(false));
|
||||||
|
@ -19,4 +35,53 @@ public class MagicGlow extends RenderPhase {
|
||||||
public static RenderLayer getRenderLayer() {
|
public static RenderLayer getRenderLayer() {
|
||||||
return MAGIC;
|
return MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RenderLayer getTintedLayer(float red, float green, float blue, float alpha) {
|
||||||
|
return RenderLayer.method_24049("mlp_tint_layer", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, 7, 256, true, true, RenderLayer.MultiPhaseData.builder()
|
||||||
|
.texture(new Color(red, green, blue, alpha))
|
||||||
|
.writeMaskState(COLOR_MASK)
|
||||||
|
.alpha(ONE_TENTH_ALPHA)
|
||||||
|
.transparency(GLOWING_TRANSPARENCY)
|
||||||
|
.lightmap(DISABLE_LIGHTMAP)
|
||||||
|
.overlay(DISABLE_OVERLAY_COLOR)
|
||||||
|
.cull(DISABLE_CULLING)
|
||||||
|
.build(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Color extends Texture {
|
||||||
|
|
||||||
|
private final float red;
|
||||||
|
private final float green;
|
||||||
|
private final float blue;
|
||||||
|
private final float alpha;
|
||||||
|
|
||||||
|
public Color(float red, float green, float blue, float alpha) {
|
||||||
|
super(SpriteAtlasTexture.BLOCK_ATLAS_TEX, false, false);
|
||||||
|
this.red = red;
|
||||||
|
this.green = green;
|
||||||
|
this.blue = blue;
|
||||||
|
this.alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startDrawing() {
|
||||||
|
super.startDrawing();
|
||||||
|
RenderSystem.blendColor(red, green, blue, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endDrawing() {
|
||||||
|
super.endDrawing();
|
||||||
|
RenderSystem.blendColor(1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return super.equals(other)
|
||||||
|
&& ((Color)other).red == red
|
||||||
|
&& ((Color)other).green == green
|
||||||
|
&& ((Color)other).blue == blue
|
||||||
|
&& ((Color)other).alpha == alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"MixinSkullBlockEntityRenderer",
|
"MixinSkullBlockEntityRenderer",
|
||||||
"MixinFirstPersonRenderer",
|
"MixinFirstPersonRenderer",
|
||||||
"MixinItemRenderer",
|
"MixinItemRenderer",
|
||||||
|
"MixinClass_4722",
|
||||||
"MixinClientPlayerEntity",
|
"MixinClientPlayerEntity",
|
||||||
"MixinPlayerMoveC2SPacket_Both",
|
"MixinPlayerMoveC2SPacket_Both",
|
||||||
"MixinPlayerMoveC2SPacket_LookOnly"
|
"MixinPlayerMoveC2SPacket_LookOnly"
|
||||||
|
|
Loading…
Reference in a new issue