2020-09-09 16:49:01 +02:00
package de.ellpeck.actuallyadditions.common.blocks.render ;
2016-06-06 21:27:09 +02:00
2020-09-07 20:33:27 +02:00
import com.mojang.blaze3d.matrix.MatrixStack ;
2020-09-09 16:49:01 +02:00
import de.ellpeck.actuallyadditions.common.ActuallyAdditions ;
import de.ellpeck.actuallyadditions.common.tile.TileEntityDisplayStand ;
import de.ellpeck.actuallyadditions.common.util.AssetUtil ;
import de.ellpeck.actuallyadditions.common.util.StackUtil ;
2020-09-07 20:33:27 +02:00
import net.minecraft.client.renderer.IRenderTypeBuffer ;
import net.minecraft.client.renderer.Quaternion ;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer ;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher ;
import net.minecraft.item.BlockItem ;
2016-06-06 21:27:09 +02:00
import net.minecraft.item.ItemStack ;
2020-09-07 20:33:27 +02:00
import net.minecraft.util.Util ;
2016-06-06 21:27:09 +02:00
2020-09-07 20:33:27 +02:00
// todo: migrate to client package
public class RenderDisplayStand extends TileEntityRenderer < TileEntityDisplayStand > {
public RenderDisplayStand ( TileEntityRendererDispatcher rendererDispatcherIn ) {
super ( rendererDispatcherIn ) ;
}
2016-06-06 21:27:09 +02:00
@Override
2020-09-07 20:33:27 +02:00
public void render ( TileEntityDisplayStand tile , float partialTicks , MatrixStack matrices , IRenderTypeBuffer bufferIn , int combinedLightIn , int combinedOverlayIn ) {
// BlockPos pos = tile.getPos();
2016-06-06 21:27:09 +02:00
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 ) ) {
2020-09-07 20:33:27 +02:00
matrices . push ( ) ;
// matrices.translate((float) pos.getX() + 0.5F, (float) pos.getY() + 1F, (float) pos.getZ() + 0.5F);
2016-06-06 21:27:09 +02:00
2020-09-07 20:33:27 +02:00
double boop = Util . nanoTime ( ) / 800D ;
matrices . translate ( 0D , Math . sin ( boop % ( 2 * Math . PI ) ) * 0 . 065 , 0D ) ;
matrices . rotate ( new Quaternion ( ( float ) ( boop * 40D % 360 ) , 0 , 1 , 0 ) ) ;
2016-06-06 21:27:09 +02:00
2020-09-07 20:33:27 +02:00
float scale = stack . getItem ( ) instanceof BlockItem ? 0 . 85F : 0 . 65F ;
matrices . scale ( scale , scale , scale ) ;
2019-05-02 09:10:29 +02:00
try {
2016-06-06 21:27:09 +02:00
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 ) ;
2016-06-06 21:27:09 +02:00
}
2020-09-07 20:33:27 +02:00
matrices . pop ( ) ;
2016-06-06 21:27:09 +02:00
}
}
}