2016-12-18 17:28:29 +01:00
/ *
* This file ( " RenderBatteryBox.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
2016-12-18 17:28:29 +01:00
* /
package de.ellpeck.actuallyadditions.mod.blocks.render ;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions ;
2016-12-18 17:28:29 +01:00
import de.ellpeck.actuallyadditions.mod.items.ItemBattery ;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBatteryBox ;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil ;
import de.ellpeck.actuallyadditions.mod.util.StackUtil ;
import net.minecraft.client.Minecraft ;
import net.minecraft.client.gui.FontRenderer ;
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.energy.CapabilityEnergy ;
import net.minecraftforge.energy.IEnergyStorage ;
import net.minecraftforge.fml.relauncher.Side ;
import net.minecraftforge.fml.relauncher.SideOnly ;
2017-06-29 18:36:33 +02:00
import java.text.NumberFormat ;
2016-12-18 17:28:29 +01:00
@SideOnly ( Side . CLIENT )
2017-07-28 03:17:50 +02:00
public class RenderBatteryBox extends TileEntitySpecialRenderer < TileEntityBatteryBox > {
2016-12-18 17:28:29 +01:00
@Override
2017-07-28 03:17:50 +02:00
public void render ( TileEntityBatteryBox tile , double x , double y , double z , float par5 , int par6 , float f ) {
2016-12-18 17:28:29 +01:00
if ( ! ( tile instanceof TileEntityBatteryBox ) ) {
return ;
}
ItemStack stack = ( ( TileEntityBatteryBox ) tile ) . slots . getStackInSlot ( 0 ) ;
if ( StackUtil . isValid ( stack ) & & stack . getItem ( ) instanceof ItemBattery ) {
GlStateManager . pushMatrix ( ) ;
GlStateManager . translate ( ( float ) x + 0 . 5F , ( float ) y + 1F , ( float ) z + 0 . 5F ) ;
GlStateManager . pushMatrix ( ) ;
GlStateManager . scale ( 0 . 0075F , 0 . 0075F , 0 . 0075F ) ;
GlStateManager . rotate ( 180F , 1F , 0F , 0F ) ;
GlStateManager . translate ( 0F , 0F , - 50F ) ;
if ( stack . hasCapability ( CapabilityEnergy . ENERGY , null ) ) {
IEnergyStorage cap = stack . getCapability ( CapabilityEnergy . ENERGY , null ) ;
NumberFormat format = NumberFormat . getInstance ( ) ;
2017-06-29 18:30:02 +02:00
FontRenderer font = Minecraft . getMinecraft ( ) . fontRenderer ;
2016-12-18 17:28:29 +01:00
String s = format . format ( cap . getEnergyStored ( ) ) + " / " + format . format ( cap . getMaxEnergyStored ( ) ) ;
float lengthS = - font . getStringWidth ( s ) / 2F ;
String s2 = " Crystal Flux " ;
float lengthS2 = - font . getStringWidth ( s2 ) / 2F ;
for ( int i = 0 ; i < 4 ; i + + ) {
font . drawString ( s , lengthS , 10F , 0xFFFFFF , false ) ;
font . drawString ( s2 , lengthS2 , 20F , 0xFFFFFF , false ) ;
GlStateManager . translate ( - 50F , 0F , 50F ) ;
GlStateManager . rotate ( 90F , 0F , 1F , 0F ) ;
}
}
GlStateManager . popMatrix ( ) ;
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 ) ;
try {
AssetUtil . renderItemInWorld ( stack ) ;
}
catch ( Exception e ) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions . LOGGER . error ( " Something went wrong trying to render an item in a battery box! The item is " + stack . getItem ( ) . getRegistryName ( ) + " ! " , e ) ;
2016-12-18 17:28:29 +01:00
}
GlStateManager . popMatrix ( ) ;
}
}
}