made trinkets render even without baubles installed

This commit is contained in:
Ellpeck 2018-10-21 14:42:30 +02:00
parent c22a1da6b4
commit 00ba609408
8 changed files with 141 additions and 86 deletions

View file

@ -1,4 +1,4 @@
package de.ellpeck.naturesaura.compat.baubles; package de.ellpeck.naturesaura.compat;
import baubles.api.BaubleType; import baubles.api.BaubleType;
import baubles.api.IBauble; import baubles.api.IBauble;

View file

@ -1,6 +1,5 @@
package de.ellpeck.naturesaura.compat; package de.ellpeck.naturesaura.compat;
import de.ellpeck.naturesaura.compat.baubles.BaublesCompat;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Loader;

View file

@ -1,75 +0,0 @@
package de.ellpeck.naturesaura.compat.baubles;
import baubles.api.BaublesApi;
import baubles.api.render.IRenderBauble;
import baubles.api.render.IRenderBauble.RenderType;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
@SideOnly(Side.CLIENT)
public class BaublesLayer implements LayerRenderer<EntityPlayer> {
@Override
public void doRenderLayer(@Nonnull EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
if (player.getActivePotionEffect(MobEffects.INVISIBILITY) != null)
return;
IItemHandler inv = BaublesApi.getBaublesHandler(player);
GlStateManager.pushMatrix();
GlStateManager.color(1F, 1F, 1F, 1F);
this.render(inv, player, RenderType.BODY);
float yaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks;
float yawOffset = player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialTicks;
float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;
GlStateManager.rotate(yawOffset, 0, -1, 0);
GlStateManager.rotate(yaw - 270, 0, 1, 0);
GlStateManager.rotate(pitch, 0, 0, 1);
this.render(inv, player, RenderType.HEAD);
GlStateManager.popMatrix();
}
private void render(IItemHandler inv, EntityPlayer player, RenderType type) {
for (int i = 0; i < inv.getSlots(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (type == RenderType.BODY) {
boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty();
GlStateManager.pushMatrix();
IRenderBauble.Helper.rotateIfSneaking(player);
if (item == ModItems.EYE) {
GlStateManager.translate(0.1F, 0.19F, armor ? -0.195F : -0.13F);
GlStateManager.scale(0.15F, 0.15F, 0.15F);
GlStateManager.rotate(180F, 1F, 0F, 0F);
Helper.renderItemInWorld(stack);
} else if (item == ModItems.AURA_CACHE) {
GlStateManager.translate(-0.15F, 0.65F, armor ? -0.195F : -0.13F);
GlStateManager.scale(0.25F, 0.25F, 0.25F);
GlStateManager.rotate(180F, 1F, 0F, 0F);
Helper.renderItemInWorld(stack);
}
GlStateManager.popMatrix();
}
}
}
}
@Override
public boolean shouldCombineTextures() {
return false;
}
}

View file

@ -1,11 +1,17 @@
package de.ellpeck.naturesaura.items; package de.ellpeck.naturesaura.items;
import baubles.api.render.IRenderBauble;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.aura.Capabilities; import de.ellpeck.naturesaura.aura.Capabilities;
import de.ellpeck.naturesaura.aura.container.IAuraContainer; import de.ellpeck.naturesaura.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.aura.container.ItemAuraContainer; import de.ellpeck.naturesaura.aura.container.ItemAuraContainer;
import de.ellpeck.naturesaura.renderers.ITrinketItem;
import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets.RenderType;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -13,11 +19,13 @@ import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ItemAuraCache extends ItemImpl { public class ItemAuraCache extends ItemImpl implements ITrinketItem {
public ItemAuraCache() { public ItemAuraCache() {
super("aura_cache"); super("aura_cache");
@ -89,4 +97,15 @@ public class ItemAuraCache extends ItemImpl {
} }
}; };
} }
@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, EntityPlayer player, RenderType type) {
boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty();
IRenderBauble.Helper.rotateIfSneaking(player);
GlStateManager.translate(-0.15F, 0.65F, armor ? -0.195F : -0.13F);
GlStateManager.scale(0.25F, 0.25F, 0.25F);
GlStateManager.rotate(180F, 1F, 0F, 0F);
Helper.renderItemInWorld(stack);
}
} }

View file

@ -1,9 +1,34 @@
package de.ellpeck.naturesaura.items; package de.ellpeck.naturesaura.items;
public class ItemEye extends ItemImpl { import baubles.api.render.IRenderBauble;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.renderers.ITrinketItem;
import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets;
import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets.RenderType;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemEye extends ItemImpl implements ITrinketItem {
public ItemEye() { public ItemEye() {
super("eye"); super("eye");
this.setMaxStackSize(1); this.setMaxStackSize(1);
} }
@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, EntityPlayer player, RenderType type) {
if (type == RenderType.BODY) {
boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty();
IRenderBauble.Helper.rotateIfSneaking(player);
GlStateManager.translate(0.1F, 0.19F, armor ? -0.195F : -0.13F);
GlStateManager.scale(0.15F, 0.15F, 0.15F);
GlStateManager.rotate(180F, 1F, 0F, 0F);
Helper.renderItemInWorld(stack);
}
}
} }

View file

@ -4,8 +4,7 @@ import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand; import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar; import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand; import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets;
import de.ellpeck.naturesaura.compat.baubles.BaublesLayer;
import de.ellpeck.naturesaura.events.ClientEvents; import de.ellpeck.naturesaura.events.ClientEvents;
import de.ellpeck.naturesaura.particles.ParticleHandler; import de.ellpeck.naturesaura.particles.ParticleHandler;
import de.ellpeck.naturesaura.particles.ParticleMagic; import de.ellpeck.naturesaura.particles.ParticleMagic;
@ -42,11 +41,9 @@ public class ClientProxy implements IProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWoodStand.class, new RenderWoodStand()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWoodStand.class, new RenderWoodStand());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityNatureAltar.class, new RenderNatureAltar()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityNatureAltar.class, new RenderNatureAltar());
if (Compat.baubles) { Map<String, RenderPlayer> skinMap = Minecraft.getMinecraft().getRenderManager().getSkinMap();
Map<String, RenderPlayer> skinMap = Minecraft.getMinecraft().getRenderManager().getSkinMap(); for (RenderPlayer render : new RenderPlayer[]{skinMap.get("default"), skinMap.get("slim")}) {
for (RenderPlayer render : new RenderPlayer[]{skinMap.get("default"), skinMap.get("slim")}) { render.addLayer(new PlayerLayerTrinkets());
render.addLayer(new BaublesLayer());
}
} }
} }

View file

@ -0,0 +1,13 @@
package de.ellpeck.naturesaura.renderers;
import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets.RenderType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface ITrinketItem {
@SideOnly(Side.CLIENT)
void render(ItemStack stack, EntityPlayer player, RenderType type);
}

View file

@ -0,0 +1,77 @@
package de.ellpeck.naturesaura.renderers;
import baubles.api.BaublesApi;
import de.ellpeck.naturesaura.compat.Compat;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.Set;
@SideOnly(Side.CLIENT)
public class PlayerLayerTrinkets implements LayerRenderer<EntityPlayer> {
private final Set<Item> alreadyRendered = new HashSet<>();
@Override
public void doRenderLayer(@Nonnull EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
if (player.getActivePotionEffect(MobEffects.INVISIBILITY) != null)
return;
this.alreadyRendered.clear();
GlStateManager.pushMatrix();
GlStateManager.color(1F, 1F, 1F, 1F);
this.render(player, RenderType.BODY);
float yaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks;
float yawOffset = player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialTicks;
float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;
GlStateManager.rotate(yawOffset, 0, -1, 0);
GlStateManager.rotate(yaw - 270, 0, 1, 0);
GlStateManager.rotate(pitch, 0, 0, 1);
this.render(player, RenderType.HEAD);
GlStateManager.popMatrix();
}
private void render(EntityPlayer player, RenderType type) {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
this.renderStack(player.inventory.getStackInSlot(i), player, type);
}
if (Compat.baubles) {
IItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); i++) {
this.renderStack(baubles.getStackInSlot(i), player, type);
}
}
}
private void renderStack(ItemStack stack, EntityPlayer player, RenderType type) {
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (item instanceof ITrinketItem && !this.alreadyRendered.contains(item)) {
GlStateManager.pushMatrix();
((ITrinketItem) item).render(stack, player, type);
GlStateManager.popMatrix();
this.alreadyRendered.add(item);
}
}
}
@Override
public boolean shouldCombineTextures() {
return false;
}
public enum RenderType {
HEAD, BODY
}
}