Fix gaia head render with mixins

This commit is contained in:
Vincent Lee committed 2020-07-18 17:28:11 -05:00
1 parent 3000c4b18f
commit 313b0fb0a2
13 files changed
+156 -70

No files matched your search

@@ -9,13 +9,10 @@
package vazkii.botania.client.render.tile;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.block.SkullBlock;
import net.minecraft.block.WallSkullBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
@@ -23,7 +20,6 @@ import net.minecraft.client.renderer.entity.model.GenericHeadModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
@@ -32,50 +28,22 @@ import net.minecraft.entity.monster.SkeletonEntity;
import net.minecraft.entity.monster.WitherSkeletonEntity;
import net.minecraft.entity.monster.ZombieEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.SkullTileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.core.helper.ShaderWrappedRenderLayer;
import vazkii.botania.client.render.entity.RenderDoppleganger;
import vazkii.botania.common.block.BlockGaiaHead;
import vazkii.botania.mixin.AccessorSkullTileEntityRenderer;
import javax.annotation.Nullable;
import java.util.Map;
public class RenderTileGaiaHead extends SkullTileEntityRenderer {
private static final Map<SkullBlock.ISkullType, GenericHeadModel> MODELS = ObfuscationReflectionHelper.getPrivateValue(SkullTileEntityRenderer.class, null, "field_199358_e");
private static final Map<SkullBlock.ISkullType, ResourceLocation> SKINS = ObfuscationReflectionHelper.getPrivateValue(SkullTileEntityRenderer.class, null, "field_199357_d");
static {
// rendering heads on entities still goes through the original codepath in the superclass, so we need these in the original maps
// here we just use the default steve skin for now
// unfortunately, doing it "right" (showing the appropriate skin for the viewer + shader) requires coremodding to redirect those codepaths. TODO do that?
MODELS.put(BlockGaiaHead.GAIA_TYPE, MODELS.get(SkullBlock.Types.PLAYER));
SKINS.put(BlockGaiaHead.GAIA_TYPE, SKINS.get(SkullBlock.Types.PLAYER));
}
public RenderTileGaiaHead(TileEntityRendererDispatcher manager) {
super(manager);
}
@Override
public void render(@Nullable SkullTileEntity skull, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int light, int overlay) {
// [VanillaCopy] super, but null safe and call our own render method with appropriate overridden type and profile
float animateProgress = 0;
float angle = 180;
Direction direction = null;
if (skull != null) {
animateProgress = skull.getAnimationProgress(partialTicks);
BlockState blockstate = skull.getBlockState();
boolean flag = blockstate.getBlock() instanceof WallSkullBlock;
direction = flag ? blockstate.get(WallSkullBlock.FACING) : null;
angle = 22.5F * (float) (flag ? (2 + direction.getHorizontalIndex()) * 4 : blockstate.get(SkullBlock.ROTATION));
}
// [VanillaCopy] super, but finding the skull type and profile ourselves and calling our own method to get RenderType
public static void gaiaRender(@Nullable Direction facing, float rotation, float animationProgress, MatrixStack ms, IRenderTypeBuffer buffers, int light) {
Entity view = Minecraft.getInstance().getRenderViewEntity();
SkullBlock.ISkullType type = SkullBlock.Types.PLAYER;
GameProfile profile = null;
@@ -96,12 +64,7 @@ public class RenderTileGaiaHead extends SkullTileEntityRenderer {
type = SkullBlock.Types.DRAGON;
}
gaiaRender(direction, angle, type, profile, animateProgress, ms, buffers, light);
}
// [VanillaCopy] super, but calling our own method to get RenderType
private static void gaiaRender(@Nullable Direction facing, float rotation, SkullBlock.ISkullType type, @Nullable GameProfile profile, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int light) {
GenericHeadModel genericheadmodel = MODELS.get(type);
GenericHeadModel genericheadmodel = AccessorSkullTileEntityRenderer.getModels().get(type);
ms.push();
if (facing == null) {
ms.translate(0.5D, 0.0D, 0.5D);
@@ -123,26 +86,13 @@ public class RenderTileGaiaHead extends SkullTileEntityRenderer {
}
ms.scale(-1.0F, -1.0F, 1.0F);
IVertexBuilder ivertexbuilder = buffers.getBuffer(layerFor(type, profile));
genericheadmodel.func_225603_a_(partialTicks, rotation, 0.0F);
RenderType layer = AccessorSkullTileEntityRenderer.callGetRenderType(type, profile);
if (ShaderHelper.useShaders()) {
layer = new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.DOPPLEGANGER, RenderDoppleganger.defaultCallback, layer);
}
IVertexBuilder ivertexbuilder = buffers.getBuffer(layer);
genericheadmodel.func_225603_a_(animationProgress, rotation, 0.0F);
genericheadmodel.render(ms, ivertexbuilder, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
ms.pop();
}
// [VanillaCopy] super but wrapped in a shader
private static RenderType layerFor(SkullBlock.ISkullType type, @Nullable GameProfile profile) {
RenderType base;
ResourceLocation resourcelocation = SKINS.get(type);
if (type == SkullBlock.Types.PLAYER && profile != null) {
Minecraft minecraft = Minecraft.getInstance();
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = minecraft.getSkinManager().loadSkinFromCache(profile);
base = map.containsKey(MinecraftProfileTexture.Type.SKIN) ? RenderType.getEntityTranslucent(minecraft.getSkinManager().loadSkin(map.get(MinecraftProfileTexture.Type.SKIN), MinecraftProfileTexture.Type.SKIN)) : RenderType.getEntityCutoutNoCull(DefaultPlayerSkin.getDefaultSkin(PlayerEntity.getUUID(profile)));
} else {
base = RenderType.getEntityCutoutNoCull(resourcelocation);
}
return ShaderHelper.useShaders()
? new ShaderWrappedRenderLayer(ShaderHelper.BotaniaShader.DOPPLEGANGER, RenderDoppleganger.defaultCallback, base)
: base;
}
}
@@ -835,6 +835,7 @@ public final class ModBlocks {
register(r, Registry.BLOCK.getKey(mutatedGrass), new BlockItem(mutatedGrass, props));
register(r, Registry.BLOCK.getKey(animatedTorch), new BlockItem(animatedTorch, props));
register(r, Registry.BLOCK.getKey(corporeaCrystalCube), new BlockItem(corporeaCrystalCube, props));
register(r, Registry.BLOCK.getKey(gaiaHead), new ItemGaiaHead(gaiaHead, gaiaHeadWall, ModItems.defaultBuilder().rarity(Rarity.UNCOMMON)));
DistExecutor.runForDist(() -> () -> registerWithTEISRS(r), () -> () -> registerWithoutTEISRS(r));
}
@@ -854,8 +855,6 @@ public final class ModBlocks {
register(r, Registry.BLOCK.getKey(brewery), new BlockItem(brewery, props));
register(r, Registry.BLOCK.getKey(corporeaIndex), new BlockItem(corporeaIndex, props));
register(r, Registry.BLOCK.getKey(hourglass), new BlockItem(hourglass, props));
Item head = new ItemGaiaHead(gaiaHead, gaiaHeadWall, ModItems.defaultBuilder().rarity(Rarity.UNCOMMON));
register(r, Registry.BLOCK.getKey(gaiaHead), head);
return null;
}
@@ -872,8 +871,6 @@ public final class ModBlocks {
register(r, Registry.BLOCK.getKey(brewery), new BlockItem(brewery, ModItems.defaultBuilder().setISTER(() -> () -> new TEISR(brewery))));
register(r, Registry.BLOCK.getKey(corporeaIndex), new BlockItem(corporeaIndex, ModItems.defaultBuilder().setISTER(() -> () -> new TEISR(corporeaIndex))));
register(r, Registry.BLOCK.getKey(hourglass), new BlockItem(hourglass, ModItems.defaultBuilder().setISTER(() -> () -> new TEISR(hourglass))));
Item head = new ItemGaiaHead(gaiaHead, gaiaHeadWall, ModItems.defaultBuilder().rarity(Rarity.UNCOMMON).setISTER(() -> () -> new TEISR(gaiaHead)));
register(r, Registry.BLOCK.getKey(gaiaHead), head);
return null;
}
@@ -51,13 +51,12 @@ public class SubTileTigerseye extends TileEntityFunctionalFlower {
((AccessorCreeperEntity) entity).setTimeSinceIgnited(2);
entity.setAttackTarget(null);
if (getMana() >= COST) {
boolean did = false;
Set<PrioritizedGoal> goals = ((AccessorGoalSelector) entity.goalSelector).getGoals();
boolean hasRunAwayFromPlayerGoal = goals.stream()
.anyMatch(g -> g.getGoal() instanceof AvoidEntityGoal && ((AccessorAvoidEntityGoal) g.getGoal()).getClassToAvoid() == PlayerEntity.class);
.anyMatch(g -> g.getGoal() instanceof AvoidEntityGoal && ((AccessorAvoidEntityGoal) g.getGoal()).getClassToAvoid() == PlayerEntity.class);
if (!hasRunAwayFromPlayerGoal) {
entity.goalSelector.addGoal(3, new AvoidEntityGoal<>(entity, PlayerEntity.class, 6, 1, 1.2));
did = true;
@@ -65,7 +64,7 @@ public class SubTileTigerseye extends TileEntityFunctionalFlower {
for (PrioritizedGoal pg : new ArrayList<>(((AccessorGoalSelector) entity.targetSelector).getGoals())) {
if (pg.getGoal() instanceof NearestAttackableTargetGoal
&& ((AccessorNearestAttackableTarget) pg.getGoal()).getTargetClass() == PlayerEntity.class) {
&& ((AccessorNearestAttackableTarget) pg.getGoal()).getTargetClass() == PlayerEntity.class) {
entity.targetSelector.removeGoal(pg.getGoal());
did = true;
}
@@ -63,14 +63,14 @@ public class EntityThrownItem extends ItemEntity {
Predicate<Entity> filter = e -> !e.isSpectator() && e.isAlive() && e.canBeCollidedWith() && (!(e instanceof PlayerEntity) || pickupDelay == 0);
RayTraceResult ray = ProjectileHelper.func_234618_a_(this, filter, RayTraceContext.BlockMode.OUTLINE);
if (ray.getType() == RayTraceResult.Type.BLOCK) {
BlockPos pos = ((BlockRayTraceResult)ray).getPos();
BlockPos pos = ((BlockRayTraceResult) ray).getPos();
BlockState state = this.world.getBlockState(pos);
if (state.isIn(Blocks.NETHER_PORTAL)) {
this.setPortal(pos);
} else if (state.isIn(Blocks.END_GATEWAY)) {
TileEntity tileentity = this.world.getTileEntity(pos);
if (tileentity instanceof EndGatewayTileEntity) {
((EndGatewayTileEntity)tileentity).teleportEntity(this);
((EndGatewayTileEntity) tileentity).teleportEntity(this);
}
}
}
@@ -1,7 +1,16 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.tileentity.EndPortalTileEntityRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -1,6 +1,15 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -1,6 +1,15 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import net.minecraft.client.renderer.RenderState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -1,8 +1,17 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeBuffers;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@@ -0,0 +1,39 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.SkullBlock;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.model.GenericHeadModel;
import net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import javax.annotation.Nullable;
import java.util.Map;
@Mixin(SkullTileEntityRenderer.class)
public interface AccessorSkullTileEntityRenderer {
@Accessor("MODELS")
static Map<SkullBlock.ISkullType, GenericHeadModel> getModels() {
throw new IllegalStateException();
}
@Invoker
static RenderType callGetRenderType(SkullBlock.ISkullType skullType, @Nullable GameProfile profile) {
throw new IllegalStateException();
}
}
@@ -1,6 +1,15 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import net.minecraft.entity.boss.WitherEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@@ -0,0 +1,42 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.block.SkullBlock;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer;
import net.minecraft.util.Direction;
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.CallbackInfo;
import vazkii.botania.client.render.tile.RenderTileGaiaHead;
import vazkii.botania.common.block.BlockGaiaHead;
import javax.annotation.Nullable;
/**
* This hook is necessary instead of just overriding render() in RenderTileGaiaHead as normal
* because vanilla ItemStackTileEntityRenderer checks for skull blocks and calls this static method directly.
*/
@Mixin(SkullTileEntityRenderer.class)
public abstract class MixinSkullTileEntityRenderer {
@Inject(at = @At("HEAD"), method = "render(Lnet/minecraft/util/Direction;FLnet/minecraft/block/SkullBlock$ISkullType;Lcom/mojang/authlib/GameProfile;FLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V", cancellable = true)
private static void onRender(@Nullable Direction direction, float angle, SkullBlock.ISkullType skullType, @Nullable GameProfile gameProfileIn, float animationProgress, MatrixStack ms, IRenderTypeBuffer buffers, int light, CallbackInfo ci) {
if (skullType == BlockGaiaHead.GAIA_TYPE) {
RenderTileGaiaHead.gaiaRender(direction, angle, animationProgress, ms, buffers, light);
ci.cancel();
}
}
}
@@ -1,21 +1,33 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.mixin;
import net.minecraft.client.util.Splashes;
import net.minecraft.profiler.IProfiler;
import net.minecraft.resources.IResourceManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import vazkii.botania.common.core.handler.ConfigHandler;
import java.util.List;
@Mixin(Splashes.class)
public class MixinSplashes {
@Shadow @Final private List<String> possibleSplashes;
@Shadow
@Final
private List<String> possibleSplashes;
@Inject(at = @At("RETURN"), method = "apply")
public void addSplashes(List<String> splashes, IResourceManager resourceManager, IProfiler profiler, CallbackInfo ci) {
@@ -31,7 +31,9 @@
"AccessorRecipeBookPage",
"AccessorRenderState",
"AccessorRenderTypeBuffers",
"AccessorSkullTileEntityRenderer",
"AccessorWorldRenderer",
"MixinSkullTileEntityRenderer",
"MixinSplashes"
],
"injectors": {