mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Fix #16 by using a mixin on the item renderer instead of trying to recreate it myself.
This commit is contained in:
parent
3dce2be978
commit
f626345e8c
5 changed files with 62 additions and 20 deletions
6
src/main/java/com/minelittlepony/ducks/IRenderItem.java
Normal file
6
src/main/java/com/minelittlepony/ducks/IRenderItem.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package com.minelittlepony.ducks;
|
||||||
|
|
||||||
|
public interface IRenderItem {
|
||||||
|
|
||||||
|
void useTransparency(boolean use);
|
||||||
|
}
|
43
src/main/java/com/minelittlepony/mixin/MixinRenderItem.java
Normal file
43
src/main/java/com/minelittlepony/mixin/MixinRenderItem.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package com.minelittlepony.mixin;
|
||||||
|
|
||||||
|
import com.minelittlepony.ducks.IRenderItem;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.RenderItem;
|
||||||
|
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||||
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(value = RenderItem.class)
|
||||||
|
@Implements( value = @Interface(iface = IRenderItem.class, prefix = "mlp$") )
|
||||||
|
public abstract class MixinRenderItem implements IResourceManagerReloadListener, IRenderItem {
|
||||||
|
|
||||||
|
private static final String ItemStack = "Lnet/minecraft/item/ItemStack;";
|
||||||
|
private static final String IBakedModel = "Lnet/minecraft/client/renderer/block/model/IBakedModel;";
|
||||||
|
private static final String ItemCameraTransform$TransformType = "Lnet/minecraft/client/renderer/block/model/ItemCameraTransforms$TransformType;";
|
||||||
|
private static final String GlStateManager$SourceFactor = "Lnet/minecraft/client/renderer/GlStateManager$SourceFactor;";
|
||||||
|
private static final String GlStateManager$DestFactor = "Lnet/minecraft/client/renderer/GlStateManager$DestFactor;";
|
||||||
|
|
||||||
|
private boolean transparency;
|
||||||
|
|
||||||
|
public void mlp$useTransparency(boolean transparency) {
|
||||||
|
this.transparency = transparency;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "renderItemModel(" + ItemStack + IBakedModel + ItemCameraTransform$TransformType + "Z)V",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/client/renderer/GlStateManager;tryBlendFuncSeparate("
|
||||||
|
+ GlStateManager$SourceFactor + GlStateManager$DestFactor
|
||||||
|
+ GlStateManager$SourceFactor + GlStateManager$DestFactor + ")V"))
|
||||||
|
private void redirectBlendFunc(GlStateManager.SourceFactor srcFactor, GlStateManager.DestFactor dstFactor,
|
||||||
|
GlStateManager.SourceFactor srcFactorAlpha, GlStateManager.DestFactor dstFactorAlpha) {
|
||||||
|
if (transparency) {
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.CONSTANT_COLOR, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
|
} else {
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||||
import net.minecraft.client.renderer.entity.layers.LayerArrow;
|
import net.minecraft.client.renderer.entity.layers.LayerArrow;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -37,6 +38,7 @@ import static net.minecraft.client.renderer.GlStateManager.scale;
|
||||||
public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientPlayer> implements IRenderPony {
|
public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientPlayer> implements IRenderPony {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
|
@Final
|
||||||
private boolean smallArms;
|
private boolean smallArms;
|
||||||
private PlayerModel playerModel;
|
private PlayerModel playerModel;
|
||||||
private Pony thePony;
|
private Pony thePony;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.minelittlepony.model;
|
package com.minelittlepony.model;
|
||||||
|
|
||||||
import com.minelittlepony.PonyData;
|
import com.minelittlepony.PonyData;
|
||||||
import com.minelittlepony.model.AbstractPonyModel;
|
|
||||||
import com.minelittlepony.model.PonyModelConstants;
|
|
||||||
import com.minelittlepony.renderer.HornGlowRenderer;
|
import com.minelittlepony.renderer.HornGlowRenderer;
|
||||||
import net.minecraft.client.model.ModelBase;
|
import net.minecraft.client.model.ModelBase;
|
||||||
import net.minecraft.client.model.ModelBiped.ArmPose;
|
import net.minecraft.client.model.ModelBiped.ArmPose;
|
||||||
|
@ -51,7 +49,7 @@ public class UnicornHorn extends ModelBase implements PonyModelConstants {
|
||||||
float red = (data.getGlowColor() >> 16 & 255) / 255.0F;
|
float red = (data.getGlowColor() >> 16 & 255) / 255.0F;
|
||||||
float green = (data.getGlowColor() >> 8 & 255) / 255.0F;
|
float green = (data.getGlowColor() >> 8 & 255) / 255.0F;
|
||||||
float blue = (data.getGlowColor() & 255) / 255.0F;
|
float blue = (data.getGlowColor() & 255) / 255.0F;
|
||||||
blendFunc(GL11.GL_SRC_ALPHA, 1);
|
blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
|
||||||
|
|
||||||
this.horn.postRender(scale);
|
this.horn.postRender(scale);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.minelittlepony.renderer.layer;
|
package com.minelittlepony.renderer.layer;
|
||||||
|
|
||||||
import com.minelittlepony.PonyData;
|
import com.minelittlepony.PonyData;
|
||||||
|
import com.minelittlepony.ducks.IRenderItem;
|
||||||
import com.minelittlepony.ducks.IRenderPony;
|
import com.minelittlepony.ducks.IRenderPony;
|
||||||
import com.minelittlepony.model.AbstractPonyModel;
|
import com.minelittlepony.model.AbstractPonyModel;
|
||||||
import com.minelittlepony.model.BodyPart;
|
import com.minelittlepony.model.BodyPart;
|
||||||
|
@ -12,7 +13,6 @@ import net.minecraft.client.model.ModelBiped;
|
||||||
import net.minecraft.client.model.ModelRenderer;
|
import net.minecraft.client.model.ModelRenderer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.RenderItem;
|
import net.minecraft.client.renderer.RenderItem;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||||
import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
|
import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
|
||||||
|
@ -20,7 +20,6 @@ import net.minecraft.client.renderer.entity.layers.LayerRenderer;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHandSide;
|
import net.minecraft.util.EnumHandSide;
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
import org.lwjgl.opengl.GL14;
|
import org.lwjgl.opengl.GL14;
|
||||||
|
|
||||||
import static net.minecraft.client.renderer.GlStateManager.*;
|
import static net.minecraft.client.renderer.GlStateManager.*;
|
||||||
|
@ -119,35 +118,29 @@ public class LayerHeldPonyItem implements LayerRenderer<EntityLivingBase> {
|
||||||
if (drop2.hasEffect())
|
if (drop2.hasEffect())
|
||||||
drop2.setTagInfo("ench", null);
|
drop2.setTagInfo("ench", null);
|
||||||
|
|
||||||
GL11.glPushAttrib(GL11.GL_CURRENT_BIT | GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
float red = (glowColor >> 16 & 255) / 255.0F;
|
float red = (glowColor >> 16 & 255) / 255.0F;
|
||||||
float green = (glowColor >> 8 & 255) / 255.0F;
|
float green = (glowColor >> 8 & 255) / 255.0F;
|
||||||
float blue = (glowColor & 255) / 255.0F;
|
float blue = (glowColor & 255) / 255.0F;
|
||||||
float alpha = 0.2F;
|
float alpha = 0.2F;
|
||||||
// disableLighting();
|
|
||||||
enableBlend();
|
pushMatrix();
|
||||||
blendFunc(GL11.GL_CONSTANT_COLOR, 1);
|
disableLighting();
|
||||||
|
|
||||||
GL14.glBlendColor(red, green, blue, alpha);
|
GL14.glBlendColor(red, green, blue, alpha);
|
||||||
|
|
||||||
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
|
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
|
||||||
IBakedModel model = renderItem.getItemModelWithOverrides(drop, entity.world, entity);
|
((IRenderItem)renderItem).useTransparency(true);
|
||||||
|
|
||||||
ItemCameraTransforms itemcameratransforms = model.getItemCameraTransforms();
|
|
||||||
ItemCameraTransforms.applyTransformSide(itemcameratransforms.getTransform(transform), hand == EnumHandSide.LEFT);
|
|
||||||
|
|
||||||
scale(1.1, 1.1, 1.1);
|
scale(1.1, 1.1, 1.1);
|
||||||
|
|
||||||
translate(0, .01, .01);
|
translate(0, .01, .01);
|
||||||
renderItem.renderItem(drop2, model);
|
renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT);
|
||||||
translate(.01, -.01, -.02);
|
translate(.01, -.01, -.02);
|
||||||
// scale(1.1, 1.1, 1.1);
|
renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT);
|
||||||
renderItem.renderItem(drop2, model);
|
|
||||||
|
|
||||||
disableBlend();
|
((IRenderItem)renderItem).useTransparency(false);
|
||||||
enableLighting();
|
enableLighting();
|
||||||
enableTexture2D();
|
popMatrix();
|
||||||
popAttrib();
|
|
||||||
|
|
||||||
// I hate rendering
|
// I hate rendering
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue