Fixed compatibility with CCL and other mods using the old proxy object pattern

This commit is contained in:
Sollace 2019-06-27 11:48:59 +02:00
parent fe82f60ca3
commit 4ddbc897cf
5 changed files with 27 additions and 62 deletions

View file

@ -1,14 +0,0 @@
package com.minelittlepony.client.ducks;
public interface IRenderItem {
/**
* Sets whether items should be rendered with transparency support.
*/
void useTransparency(boolean use);
/**
* Returns true if this renderer is set to render models as a transparent overlay.
*/
boolean usesTransparency();
}

View file

@ -6,7 +6,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.client.render.LevitatingItemRenderer;
import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer;
import com.mojang.blaze3d.platform.GlStateManager;
@ -18,8 +17,7 @@ public abstract class MixinGlStateManager {
at = @At("HEAD"),
cancellable = true)
private static void enableBlendProfile(GlStateManager.RenderMode profile, CallbackInfo info) {
if (profile == GlStateManager.RenderMode.PLAYER_SKIN && PonySkullRenderer.ponyInstance.usesTransparency()) {
LevitatingItemRenderer.enableItemGlowRenderProfile();
if (profile == GlStateManager.RenderMode.PLAYER_SKIN && LevitatingItemRenderer.enableItemGlowRenderProfile()) {
info.cancel();
}
}

View file

@ -1,6 +1,5 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.client.ducks.IRenderItem;
import com.minelittlepony.client.render.LevitatingItemRenderer;
import net.minecraft.client.render.item.ItemRenderer;
@ -15,23 +14,14 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ItemRenderer.class)
public abstract class MixinItemRenderer implements SynchronousResourceReloadListener, IRenderItem {
private boolean transparency;
@Override
public void useTransparency(boolean transparency) {
this.transparency = transparency;
}
public abstract class MixinItemRenderer implements SynchronousResourceReloadListener {
@Inject(method = "renderItemAndGlow("
+ "Lnet/minecraft/item/ItemStack;"
+ "Lnet/minecraft/client/render/model/BakedModel;)V",
at = @At("HEAD"))
private void onRenderItem(ItemStack stack, BakedModel model, CallbackInfo info) {
if (transparency) {
LevitatingItemRenderer.enableItemGlowRenderProfile();
}
LevitatingItemRenderer.enableItemGlowRenderProfile();
}
@Inject(method = "renderItemAndGlow("
@ -43,12 +33,11 @@ public abstract class MixinItemRenderer implements SynchronousResourceReloadList
+ "Ljava/lang/Runnable;I)V"),
cancellable = true)
private void beforeRenderEffect(ItemStack stack, BakedModel model, CallbackInfo info) {
if (transparency) {
if (LevitatingItemRenderer.usesTransparency()) {
info.cancel();
}
}
@ModifyArg(method = "renderQuads("
+ "Lnet/minecraft/client/render/BufferBuilder;"
+ "Ljava/util/List;I"
@ -59,6 +48,6 @@ public abstract class MixinItemRenderer implements SynchronousResourceReloadList
+ "Lnet/minecraft/client/render/model/BakedQuad;I)V"),
index = 2)
private int modifyItemRenderTint(int color) {
return transparency ? -1 : color;
return LevitatingItemRenderer.usesTransparency() ? -1 : color;
}
}

View file

@ -3,8 +3,6 @@ package com.minelittlepony.client.render;
import org.lwjgl.opengl.GL14;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.ducks.IRenderItem;
import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer;
import com.minelittlepony.client.util.render.Color;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.settings.PonySettings;
@ -23,10 +21,20 @@ import static com.mojang.blaze3d.platform.GlStateManager.*;
public class LevitatingItemRenderer {
public static void enableItemGlowRenderProfile() {
enableBlend();
blendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO);
MinecraftClient.getInstance().gameRenderer.disableLightmap();
private static boolean usingTransparency;
public static boolean enableItemGlowRenderProfile() {
if (usesTransparency()) {
enableBlend();
blendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO);
MinecraftClient.getInstance().gameRenderer.disableLightmap();
}
return usesTransparency();
}
public static boolean usesTransparency() {
return usingTransparency;
}
/**
@ -38,8 +46,8 @@ public class LevitatingItemRenderer {
setColor(glowColor);
ItemRenderer renderItem = MinecraftClient.getInstance().getItemRenderer();
((IRenderItem) renderItem).useTransparency(true);
PonySkullRenderer.ponyInstance.useTransparency(true);
usingTransparency = true;
scalef(1.1F, 1.1F, 1.1F);
@ -48,8 +56,7 @@ public class LevitatingItemRenderer {
translatef(-0.02F, -0.02F, -0.02F);
renderItem.renderHeldItem(drop, entity, transform, hand == AbsoluteHand.LEFT);
((IRenderItem) renderItem).useTransparency(false);
PonySkullRenderer.ponyInstance.useTransparency(false);
usingTransparency = false;
unsetColor();
enableLighting();
popMatrix();
@ -86,8 +93,7 @@ public class LevitatingItemRenderer {
if (doMagic) {
disableLighting();
((IRenderItem)itemRenderer).useTransparency(true);
PonySkullRenderer.ponyInstance.useTransparency(true);
usingTransparency = true;
setColor(pony.getMetadata().getGlowColor());
@ -98,9 +104,7 @@ public class LevitatingItemRenderer {
translatef(-0.02F, -0.02F, -0.02F);
renderer.renderItemFromSide(entity, stack, transform, left);
((IRenderItem)itemRenderer).useTransparency(false);
PonySkullRenderer.ponyInstance.useTransparency(false);
usingTransparency = false;
unsetColor();
enableLighting();

View file

@ -3,7 +3,7 @@ package com.minelittlepony.client.render.tileentities.skull;
import com.google.common.collect.Maps;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLPClient;
import com.minelittlepony.client.ducks.IRenderItem;
import com.minelittlepony.client.render.LevitatingItemRenderer;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonySettings;
@ -26,13 +26,11 @@ import static com.mojang.blaze3d.platform.GlStateManager.*;
/**
* PonySkullRenderer! It renders ponies as skulls, or something...
*/
public class PonySkullRenderer extends SkullBlockEntityRenderer implements IRenderItem {
public class PonySkullRenderer extends SkullBlockEntityRenderer {
public static PonySkullRenderer ponyInstance = new PonySkullRenderer();
private static SkullBlockEntityRenderer backup = null;
private boolean transparency = false;
private static final Map<SkullBlock.SkullType, ISkull> skullMap = SystemUtil.consume(Maps.newHashMap(), (skullMap) -> {
skullMap.put(SkullBlock.Type.SKELETON, new SkeletonSkullRenderer());
skullMap.put(SkullBlock.Type.WITHER_SKELETON, new WitherSkullRenderer());
@ -108,7 +106,7 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer implements IRend
scalef(-1, -1, 1);
enableAlphaTest();
skull.preRender(usesTransparency());
skull.preRender(LevitatingItemRenderer.usesTransparency());
skull.render(animateTicks, rotation, scale);
popMatrix();
@ -146,16 +144,6 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer implements IRend
return rotation;
}
@Override
public void useTransparency(boolean use) {
transparency = use;
}
@Override
public boolean usesTransparency() {
return transparency;
}
/**
* A skull, just a skull.
*