ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderDisplayStand.java

53 lines
2.2 KiB
Java
Raw Normal View History

/*
* This file ("RenderDisplayStand.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.blocks.render;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public class RenderDisplayStand extends TileEntitySpecialRenderer<TileEntityDisplayStand> {
@Override
2019-05-02 09:10:29 +02:00
public void render(TileEntityDisplayStand tile, double x, double y, double z, float par5, int par6, float f) {
if (!(tile instanceof TileEntityDisplayStand)) { return; }
2019-02-27 19:53:05 +01:00
ItemStack stack = tile.inv.getStackInSlot(0);
2019-05-02 09:10:29 +02:00
if (StackUtil.isValid(stack)) {
GlStateManager.pushMatrix();
2019-05-02 09:10:29 +02:00
GlStateManager.translate((float) x + 0.5F, (float) y + 1F, (float) z + 0.5F);
2019-05-02 09:10:29 +02:00
double boop = Minecraft.getSystemTime() / 800D;
GlStateManager.translate(0D, Math.sin(boop % (2 * Math.PI)) * 0.065, 0D);
GlStateManager.rotate((float) (boop * 40D % 360), 0, 1, 0);
float scale = stack.getItem() instanceof ItemBlock ? 0.85F : 0.65F;
GlStateManager.scale(scale, scale, scale);
2019-05-02 09:10:29 +02:00
try {
AssetUtil.renderItemInWorld(stack);
2019-05-02 09:10:29 +02:00
} catch (Exception e) {
ActuallyAdditions.LOGGER.error("Something went wrong trying to render an item in a display stand! The item is " + stack.getItem().getRegistryName() + "!", e);
}
GlStateManager.popMatrix();
}
}
}