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 ;
2021-02-26 22:15:48 +01:00
import com.mojang.blaze3d.matrix.MatrixStack ;
import com.mojang.blaze3d.systems.RenderSystem ;
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 ;
2021-02-26 22:15:48 +01:00
import net.minecraft.client.renderer.IRenderTypeBuffer ;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer ;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher ;
2020-11-15 18:12:10 +01:00
import net.minecraft.client.resources.I18n ;
2021-02-26 22:15:48 +01:00
import net.minecraft.item.BlockItem ;
2016-12-18 17:28:29 +01:00
import net.minecraft.item.ItemStack ;
2021-02-26 22:15:48 +01:00
import net.minecraft.util.Util ;
import net.minecraftforge.api.distmarker.Dist ;
import net.minecraftforge.api.distmarker.OnlyIn ;
2016-12-18 17:28:29 +01:00
import net.minecraftforge.energy.CapabilityEnergy ;
2021-02-26 22:15:48 +01:00
import java.text.NumberFormat ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
@OnlyIn ( Dist . CLIENT )
public class RenderBatteryBox extends TileEntityRenderer < TileEntityBatteryBox > {
public RenderBatteryBox ( TileEntityRendererDispatcher rendererDispatcherIn ) {
super ( rendererDispatcherIn ) ;
}
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
// TODO: [port] migrate to matric (see cleanstart)
@Override
public void render ( TileEntityBatteryBox tile , float partialTicks , MatrixStack matrixStackIn , IRenderTypeBuffer bufferIn , int combinedLightIn , int combinedOverlayIn ) {
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 ) & & stack . getItem ( ) instanceof ItemBattery ) {
2021-02-26 22:15:48 +01:00
RenderSystem . pushMatrix ( ) ;
RenderSystem . translatef ( 0 . 5F , 1F , 0 . 5F ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
RenderSystem . pushMatrix ( ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
RenderSystem . scalef ( 0 . 0075F , 0 . 0075F , 0 . 0075F ) ;
RenderSystem . rotatef ( 180F , 1F , 0F , 0F ) ;
RenderSystem . translatef ( 0F , 0F , - 50F ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
stack . getCapability ( CapabilityEnergy . ENERGY ) . ifPresent ( cap - > {
2016-12-18 17:28:29 +01:00
NumberFormat format = NumberFormat . getInstance ( ) ;
2021-02-26 22:15:48 +01:00
FontRenderer font = Minecraft . getInstance ( ) . fontRenderer ;
2016-12-18 17:28:29 +01:00
2019-05-02 09:10:29 +02:00
String s = format . format ( cap . getEnergyStored ( ) ) + " / " + format . format ( cap . getMaxEnergyStored ( ) ) ;
float lengthS = - font . getStringWidth ( s ) / 2F ;
2020-11-15 18:12:10 +01:00
String s2 = I18n . format ( " actuallyadditions.cflong " ) ;
2019-05-02 09:10:29 +02:00
float lengthS2 = - font . getStringWidth ( s2 ) / 2F ;
2016-12-18 17:28:29 +01:00
2019-05-02 09:10:29 +02:00
for ( int i = 0 ; i < 4 ; i + + ) {
2021-02-26 22:15:48 +01:00
font . drawString ( matrixStackIn , s , lengthS , 10F , 0xFFFFFF ) ;
font . drawString ( matrixStackIn , s2 , lengthS2 , 20F , 0xFFFFFF ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
RenderSystem . translatef ( - 50F , 0F , 50F ) ;
RenderSystem . rotatef ( 90F , 0F , 1F , 0F ) ;
2016-12-18 17:28:29 +01:00
}
2021-02-26 22:15:48 +01:00
} ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
RenderSystem . popMatrix ( ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
double boop = Util . milliTime ( ) ;
RenderSystem . translated ( 0D , Math . sin ( boop % ( 2 * Math . PI ) ) * 0 . 065 , 0D ) ;
RenderSystem . rotatef ( ( float ) ( boop * 40D % 360 ) , 0 , 1 , 0 ) ;
2016-12-18 17:28:29 +01:00
2021-02-26 22:15:48 +01:00
float scale = stack . getItem ( ) instanceof BlockItem
? 0 . 85F
: 0 . 65F ;
RenderSystem . scalef ( scale , scale , scale ) ;
2019-05-02 09:10:29 +02:00
try {
2016-12-18 17:28:29 +01: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 battery box! The item is " + stack . getItem ( ) . getRegistryName ( ) + " ! " , e ) ;
2016-12-18 17:28:29 +01:00
}
2021-02-26 22:15:48 +01:00
RenderSystem . popMatrix ( ) ;
2016-12-18 17:28:29 +01:00
}
}
}