mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 07:27:59 +01:00
Fixed texturing bugs with magic rendering
This commit is contained in:
parent
07bcb12a46
commit
dd630248dd
12 changed files with 47 additions and 159 deletions
|
@ -1,35 +0,0 @@
|
|||
package com.minelittlepony.client.mixin;
|
||||
|
||||
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;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
|
||||
@Mixin(ItemRenderer.class)
|
||||
abstract class MixinItemRenderer {
|
||||
private static final String VertexConsumerProvider = "Lnet/minecraft/client/render/VertexConsumerProvider;";
|
||||
private static final String VertexConsumer = "Lnet/minecraft/client/render/VertexConsumer;";
|
||||
private static final String RenderLayer = "Lnet/minecraft/client/render/RenderLayer;";
|
||||
|
||||
private static final String Boolean = "Z";
|
||||
|
||||
private static final String PARAMS = "(" + VertexConsumerProvider + RenderLayer + Boolean + Boolean + ")" + VertexConsumer;
|
||||
|
||||
@Inject(method = {
|
||||
"getArmorGlintConsumer" + PARAMS,
|
||||
"getItemGlintConsumer" + PARAMS,
|
||||
"getDirectItemGlintConsumer" + PARAMS
|
||||
}, at = @At("HEAD"), cancellable = true)
|
||||
private static void onGetArmorVertexConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> info) {
|
||||
if (LevitatingItemRenderer.isEnabled()) {
|
||||
info.setReturnValue(provider.getBuffer(LevitatingItemRenderer.getRenderLayer()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.minelittlepony.client.mixin;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(SpriteIdentifier.class)
|
||||
abstract class MixinSpriteIdentifier {
|
||||
|
||||
@Inject(method = "getVertexConsumer("
|
||||
+ "Lnet/minecraft/client/render/VertexConsumerProvider;"
|
||||
+ "Ljava/util/function/Function;"
|
||||
+ ")"
|
||||
+ "Lnet/minecraft/client/render/VertexConsumer;",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void onGetBuffer(VertexConsumerProvider provider, Function<Identifier, RenderLayer> layerFunction, CallbackInfoReturnable<VertexConsumer> info) {
|
||||
if (LevitatingItemRenderer.isEnabled()) {
|
||||
SpriteIdentifier self = (SpriteIdentifier)(Object)this;
|
||||
|
||||
info.setReturnValue(self.getSprite().getTextureSpecificVertexConsumer(provider.getBuffer(LevitatingItemRenderer.getRenderLayer(self.getAtlasId()))));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.minelittlepony.client.mixin;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
|
||||
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(TexturedRenderLayers.class)
|
||||
abstract class MixinTexturedRenderLayers {
|
||||
|
||||
@Inject(method = "getEntityCutout()Lnet/minecraft/client/render/RenderLayer;", at = @At("HEAD"), cancellable = true)
|
||||
private static void onGetItemOpaque(CallbackInfoReturnable<RenderLayer> info) {
|
||||
if (LevitatingItemRenderer.isEnabled()) {
|
||||
info.setReturnValue(LevitatingItemRenderer.getRenderLayer());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getEntityTranslucentCull()Lnet/minecraft/client/render/RenderLayer;", at = @At("HEAD"), cancellable = true)
|
||||
private static void onGetItemTranslucent(CallbackInfoReturnable<RenderLayer> info) {
|
||||
if (LevitatingItemRenderer.isEnabled()) {
|
||||
info.setReturnValue(LevitatingItemRenderer.getRenderLayer());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,8 +26,8 @@ public class EarthPonyModel<T extends LivingEntity> extends AbstractPonyModel<T>
|
|||
super.init(context);
|
||||
|
||||
tail = addPart(context.findByName("tail"));
|
||||
addPart(context.findByName("snout"));
|
||||
addPart(context.findByName("ears"));
|
||||
snout = addPart(context.findByName("snout"));
|
||||
ears = addPart(context.findByName("ears"));
|
||||
|
||||
bodyRenderList.add(forPart(tail));
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@ package com.minelittlepony.client.render;
|
|||
|
||||
import com.minelittlepony.api.pony.IPony;
|
||||
import com.minelittlepony.client.MineLittlePony;
|
||||
import com.minelittlepony.common.util.Color;
|
||||
import com.minelittlepony.client.util.render.RenderLayerUtil;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
||||
|
@ -18,59 +17,36 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.PlayerScreenHandler;
|
||||
import net.minecraft.util.Arm;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.UseAction;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class LevitatingItemRenderer {
|
||||
|
||||
private static int tint;
|
||||
private static boolean enabled;
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public static RenderLayer getRenderLayer(Identifier texture) {
|
||||
if (!isEnabled()) {
|
||||
return RenderLayer.getEntityTranslucent(texture);
|
||||
}
|
||||
return MagicGlow.getTintedTexturedLayer(texture, Color.r(tint), Color.g(tint), Color.b(tint), 0.8F);
|
||||
}
|
||||
|
||||
public static RenderLayer getRenderLayer() {
|
||||
return getRenderLayer(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a magical overlay over an item in third person.
|
||||
*/
|
||||
public void renderItemGlow(LivingEntity entity, ItemStack drop, ModelTransformationMode transform, Arm hand, int glowColor, MatrixStack stack, VertexConsumerProvider renderContext) {
|
||||
setColor(glowColor);
|
||||
public void renderItemGlow(IPony pony, LivingEntity entity, ItemStack drop, ModelTransformationMode transform, Arm hand, int glowColor, MatrixStack stack, VertexConsumerProvider renderContext) {
|
||||
stack.push();
|
||||
|
||||
ItemRenderer renderItem = MinecraftClient.getInstance().getItemRenderer();
|
||||
ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
|
||||
|
||||
stack.scale(1.1F, 1.1F, 1.1F);
|
||||
|
||||
stack.translate(0.01F, 0.01F, 0.01F);
|
||||
|
||||
renderItem.renderItem(entity, drop, transform, hand == Arm.LEFT, stack, renderContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV, 0);
|
||||
VertexConsumerProvider interceptedContext = getProvider(pony, renderContext);
|
||||
|
||||
renderer.renderItem(entity, drop, transform, hand == Arm.LEFT, stack, interceptedContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV, 0);
|
||||
stack.translate(-0.02F, -0.02F, -0.02F);
|
||||
renderItem.renderItem(entity, drop, transform, hand == Arm.LEFT, stack, renderContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV, 0);
|
||||
renderer.renderItem(entity, drop, transform, hand == Arm.LEFT, stack, interceptedContext, entity.world, 0x0F00F0, OverlayTexture.DEFAULT_UV, 0);
|
||||
|
||||
stack.pop();
|
||||
unsetColor();
|
||||
}
|
||||
|
||||
private void setColor(int glowColor) {
|
||||
enabled = true;
|
||||
tint = glowColor;
|
||||
}
|
||||
|
||||
private void unsetColor() {
|
||||
enabled = false;
|
||||
private VertexConsumerProvider getProvider(IPony pony, VertexConsumerProvider renderContext) {
|
||||
final int color = pony.metadata().getGlowColor();
|
||||
return layer -> {
|
||||
return renderContext.getBuffer(MagicGlow.getColoured(RenderLayerUtil.getTexture(layer).orElse(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE), color));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,17 +69,14 @@ public class LevitatingItemRenderer {
|
|||
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
||||
|
||||
if (doMagic) {
|
||||
setColor(pony.metadata().getGlowColor());
|
||||
VertexConsumerProvider interceptedContext = getProvider(pony, renderContext);
|
||||
|
||||
matrix.scale(1.1F, 1.1F, 1.1F);
|
||||
|
||||
matrix.translate(0.015F, 0.01F, 0.01F);
|
||||
|
||||
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
||||
itemRenderer.renderItem(entity, stack, mode, left, matrix, interceptedContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
||||
matrix.translate(-0.03F, -0.02F, -0.02F);
|
||||
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
||||
|
||||
unsetColor();
|
||||
itemRenderer.renderItem(entity, stack, mode, left, matrix, interceptedContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
|
||||
}
|
||||
|
||||
matrix.pop();
|
||||
|
|
|
@ -42,8 +42,8 @@ public abstract class MagicGlow extends RenderPhase {
|
|||
return MAGIC;
|
||||
}
|
||||
|
||||
public static RenderLayer getTintedTexturedLayer(Identifier texture, float red, float green, float blue, float alpha) {
|
||||
return TINTED_LAYER.apply(texture, Color.argbToHex(alpha, red, green, blue));
|
||||
public static RenderLayer getColoured(Identifier texture, int color) {
|
||||
return TINTED_LAYER.apply(texture, color);
|
||||
}
|
||||
|
||||
private static class Colored extends Texture {
|
||||
|
@ -58,7 +58,7 @@ public abstract class MagicGlow extends RenderPhase {
|
|||
this.red = Color.r(color);
|
||||
this.green = Color.g(color);
|
||||
this.blue = Color.b(color);
|
||||
this.alpha = Color.a(color);
|
||||
this.alpha = 0.8F;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.minelittlepony.api.config.PonyConfig;
|
|||
import com.minelittlepony.api.pony.IPony;
|
||||
import com.minelittlepony.client.MineLittlePony;
|
||||
import com.minelittlepony.client.model.ModelType;
|
||||
import com.minelittlepony.client.render.LevitatingItemRenderer;
|
||||
import com.minelittlepony.client.render.MobRenderers;
|
||||
import com.minelittlepony.client.render.entity.SkeleponyRenderer;
|
||||
import com.minelittlepony.client.render.entity.ZomponyRenderer;
|
||||
|
@ -40,7 +39,7 @@ public class PonySkullRenderer {
|
|||
|
||||
private static void loadSkulls(Map<SkullBlock.SkullType, ISkull> skullMap) {
|
||||
skullMap.put(SkullBlock.Type.SKELETON, new MobSkull(SkeleponyRenderer.SKELETON, MobRenderers.SKELETON, ModelType.SKELETON));
|
||||
skullMap.put(SkullBlock.Type.WITHER_SKELETON, new MobSkull(SkeleponyRenderer.WITHER, MobRenderers.SKELETON, ModelType.ENDERMAN));
|
||||
skullMap.put(SkullBlock.Type.WITHER_SKELETON, new MobSkull(SkeleponyRenderer.WITHER, MobRenderers.SKELETON, ModelType.SKELETON));
|
||||
skullMap.put(SkullBlock.Type.ZOMBIE, new MobSkull(ZomponyRenderer.ZOMBIE, MobRenderers.ZOMBIE, ModelType.ZOMBIE));
|
||||
skullMap.put(SkullBlock.Type.PLAYER, new PlayerPonySkull());
|
||||
}
|
||||
|
@ -57,7 +56,7 @@ public class PonySkullRenderer {
|
|||
|
||||
selectedSkull = skull;
|
||||
selectedSkin = skull.getSkinResource(profile);
|
||||
return LevitatingItemRenderer.getRenderLayer(selectedSkin);
|
||||
return RenderLayer.getEntityTranslucent(selectedSkin);
|
||||
}
|
||||
|
||||
public static boolean renderSkull(@Nullable Direction direction,
|
||||
|
|
|
@ -23,9 +23,7 @@ import java.util.List;
|
|||
import net.minecraft.block.BedBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.Frustum;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.render.entity.EntityRendererFactory;
|
||||
import net.minecraft.client.render.entity.PlayerEntityRenderer;
|
||||
import net.minecraft.client.render.entity.feature.*;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class GlowingItemFeature<T extends LivingEntity, M extends EntityModel<T>
|
|||
@Override
|
||||
protected void postItemRender(T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext) {
|
||||
if (isUnicorn()) {
|
||||
PonyRenderDispatcher.getInstance().getMagicRenderer().renderItemGlow(entity, drop, transform, hand, ((IUnicorn)getContextModel()).getMagicColor(), stack, renderContext);
|
||||
PonyRenderDispatcher.getInstance().getMagicRenderer().renderItemGlow(getContext().getEntityPony(entity), entity, drop, transform, hand, ((IUnicorn)getContextModel()).getMagicColor(), stack, renderContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.minelittlepony.client.util.render;
|
||||
|
||||
import java.util.Optional;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public interface RenderLayerUtil {
|
||||
static Optional<Identifier> getTexture(RenderLayer layer) {
|
||||
if (layer instanceof RenderLayer.MultiPhase multiphase) {
|
||||
return multiphase.getPhases().texture.getId();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,11 @@
|
|||
accessWidener v1 named
|
||||
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
|
||||
accessible class net/minecraft/client/render/RenderPhase$TextureBase
|
||||
accessible class net/minecraft/client/render/VertexConsumers$Union
|
||||
|
||||
accessible method net/minecraft/client/render/RenderLayer of (Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;Lnet/minecraft/client/render/VertexFormat$DrawMode;ILnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;)Lnet/minecraft/client/render/RenderLayer$MultiPhase;
|
||||
accessible method net/minecraft/client/render/RenderLayer of (Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;Lnet/minecraft/client/render/VertexFormat$DrawMode;IZZLnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;)Lnet/minecraft/client/render/RenderLayer$MultiPhase;
|
||||
|
||||
accessible method net/minecraft/client/render/RenderLayer$MultiPhase getPhases ()Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;
|
||||
accessible method net/minecraft/client/render/RenderPhase$TextureBase getId ()Ljava/util/Optional;
|
||||
accessible field net/minecraft/client/render/RenderLayer$MultiPhaseParameters texture Lnet/minecraft/client/render/RenderPhase$TextureBase;
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
"MixinEntityRenderers",
|
||||
"MixinSkullBlockEntityRenderer",
|
||||
"MixinHeldItemRenderer",
|
||||
"MixinItemRenderer",
|
||||
"MixinTexturedRenderLayers",
|
||||
"MixinSpriteIdentifier",
|
||||
"MixinClientPlayerEntity",
|
||||
"MixinPlayerMoveC2SPacket",
|
||||
"MixinPlayerPositionLookS2CPacket"
|
||||
|
|
Loading…
Reference in a new issue