made baubles render on the player

This commit is contained in:
Ellpeck 2018-10-20 22:13:00 +02:00
parent f3906141a1
commit 630d56bf81
5 changed files with 144 additions and 24 deletions

View file

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

View file

@ -1,10 +1,11 @@
package de.ellpeck.naturesaura.compat;
package de.ellpeck.naturesaura.compat.baubles;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.cap.BaublesCapabilities;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
@ -20,7 +21,22 @@ import javax.annotation.Nullable;
public class BaublesCompat {
private final IBauble eye = stack -> BaubleType.CHARM;
private final IBauble cache = stack -> BaubleType.BELT;
private final IBauble cache = new IBauble() {
@Override
public BaubleType getBaubleType(ItemStack itemstack) {
return BaubleType.BELT;
}
@Override
public void onWornTick(ItemStack stack, EntityLivingBase player) {
stack.getItem().onUpdate(stack, player.world, player, -1, false);
}
@Override
public boolean willAutoSync(ItemStack stack, EntityLivingBase player) {
return true;
}
};
@SubscribeEvent
public void onCapabilitiesAttach(AttachCapabilitiesEvent<ItemStack> event) {

View file

@ -0,0 +1,72 @@
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.items.IItemHandler;
import javax.annotation.Nonnull;
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,5 +1,6 @@
package de.ellpeck.naturesaura.events;
import baubles.api.BaubleType;
import baubles.api.BaublesApi;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura;
@ -146,34 +147,52 @@ public class ClientEvents {
}
}
for (int i = 0; i < mc.player.inventory.getSizeInventory(); i++) {
ItemStack slot = mc.player.inventory.getStackInSlot(i);
if (!slot.isEmpty() && slot.getItem() == ModItems.AURA_CACHE) {
IAuraContainer container = slot.getCapability(Capabilities.auraContainer, null);
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
int x = res.getScaledWidth() / 2 - 173;
int y = res.getScaledHeight() - 8;
this.displayAuraCache(mc, res);
}
}
}
GlStateManager.pushMatrix();
int color = container.getAuraColor();
GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
mc.getTextureManager().bindTexture(OVERLAYS);
if (width < 80)
Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 80 - width, 6, 256, 256);
if (width > 0)
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256);
private void displayAuraCache(Minecraft mc, ScaledResolution res) {
ItemStack stack = ItemStack.EMPTY;
float scale = 0.75F;
GlStateManager.scale(scale, scale, scale);
String s = slot.getDisplayName();
mc.fontRenderer.drawString(s, (x + 80) / scale - mc.fontRenderer.getStringWidth(s), (y - 7) / scale, color, true);
GlStateManager.popMatrix();
if (Compat.baubles) {
ItemStack slot = BaublesApi.getBaublesHandler(mc.player).getStackInSlot(BaubleType.BELT.getValidSlots()[0]);
if (!slot.isEmpty() && slot.getItem() == ModItems.AURA_CACHE) {
stack = slot;
}
}
break;
}
if (stack.isEmpty()) {
for (int i = 0; i < mc.player.inventory.getSizeInventory(); i++) {
ItemStack slot = mc.player.inventory.getStackInSlot(i);
if (!slot.isEmpty() && slot.getItem() == ModItems.AURA_CACHE) {
stack = slot;
break;
}
}
}
if (!stack.isEmpty()) {
IAuraContainer container = stack.getCapability(Capabilities.auraContainer, null);
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
int x = res.getScaledWidth() / 2 - 173;
int y = res.getScaledHeight() - 8;
GlStateManager.pushMatrix();
int color = container.getAuraColor();
GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
mc.getTextureManager().bindTexture(OVERLAYS);
if (width < 80)
Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 80 - width, 6, 256, 256);
if (width > 0)
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256);
float scale = 0.75F;
GlStateManager.scale(scale, scale, scale);
String s = stack.getDisplayName();
mc.fontRenderer.drawString(s, (x + 80) / scale - mc.fontRenderer.getStringWidth(s), (y - 7) / scale, color, true);
GlStateManager.popMatrix();
}
}
private void drawContainerInfo(IAuraContainer container, Minecraft mc, ScaledResolution res, int yOffset, String name) {

View file

@ -4,6 +4,8 @@ import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.compat.baubles.BaublesLayer;
import de.ellpeck.naturesaura.events.ClientEvents;
import de.ellpeck.naturesaura.particles.ParticleHandler;
import de.ellpeck.naturesaura.particles.ParticleMagic;
@ -14,6 +16,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -25,6 +28,8 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.util.Map;
public class ClientProxy implements IProxy {
@Override
@ -36,6 +41,13 @@ public class ClientProxy implements IProxy {
public void init(FMLInitializationEvent event) {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWoodStand.class, new RenderWoodStand());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityNatureAltar.class, new RenderNatureAltar());
if (Compat.baubles) {
Map<String, RenderPlayer> skinMap = Minecraft.getMinecraft().getRenderManager().getSkinMap();
for (RenderPlayer render : new RenderPlayer[]{skinMap.get("default"), skinMap.get("slim")}) {
render.addLayer(new BaublesLayer());
}
}
}
@Override