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 ;
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 ;
2021-02-28 11:35:10 +01:00
import de.ellpeck.actuallyadditions.mod.util.Lang ;
2016-12-18 17:28:29 +01:00
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 ;
2021-02-28 11:35:10 +01:00
import net.minecraft.client.renderer.model.ItemCameraTransforms ;
2021-02-26 22:15:48 +01:00
import net.minecraft.client.renderer.tileentity.TileEntityRenderer ;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher ;
2022-06-24 21:38:07 +02: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 ;
2021-02-28 11:35:10 +01:00
import net.minecraft.util.math.vector.Vector3f ;
2021-02-26 22:15:48 +01:00
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
@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-28 11:35:10 +01:00
// TODO: [port] migrate to matric (see cleanstart) (done partly)
2021-02-26 22:15:48 +01:00
@Override
2021-02-28 11:35:10 +01:00
public void render ( TileEntityBatteryBox tile , float partialTicks , MatrixStack matrices , IRenderTypeBuffer buffer , int combinedLight , int combinedOverlay ) {
2019-02-27 19:53:05 +01:00
ItemStack stack = tile . inv . getStackInSlot ( 0 ) ;
2021-02-28 11:35:10 +01:00
if ( stack . isEmpty ( ) | | ! ( stack . getItem ( ) instanceof ItemBattery ) ) {
return ;
}
2016-12-18 17:28:29 +01:00
2021-08-22 17:09:06 +02:00
matrices . pushPose ( ) ;
2021-02-28 11:35:10 +01:00
matrices . translate ( . 5f , . 35f , . 5f ) ;
2021-08-22 17:09:06 +02:00
matrices . mulPose ( Vector3f . ZP . rotationDegrees ( 180 ) ) ;
2016-12-18 17:28:29 +01:00
2021-08-22 17:09:06 +02:00
matrices . pushPose ( ) ;
2021-02-28 11:35:10 +01:00
matrices . scale ( 0 . 0075F , 0 . 0075F , 0 . 0075F ) ;
matrices . translate ( 0F , 0F , - 60F ) ;
2016-12-18 17:28:29 +01:00
2021-02-28 11:35:10 +01:00
stack . getCapability ( CapabilityEnergy . ENERGY ) . ifPresent ( cap - > {
2021-08-22 17:09:06 +02:00
FontRenderer font = Minecraft . getInstance ( ) . font ;
2016-12-18 17:28:29 +01:00
2021-02-28 11:35:10 +01:00
String energyTotal = Lang . cleanEnergyValues ( cap , false ) ;
2022-06-24 21:38:07 +02:00
String energyName = I18n . get ( " misc.actuallyadditions.power_name_long " ) ;
2016-12-18 17:28:29 +01:00
2021-02-28 11:35:10 +01:00
for ( int i = 0 ; i < 4 ; i + + ) {
2021-08-22 17:09:06 +02:00
font . draw ( matrices , energyTotal , - font . width ( energyTotal ) / 2F , 10F , 0xFFFFFF ) ;
font . draw ( matrices , energyName , - font . width ( energyName ) / 2F , 20F , 0xFFFFFF ) ;
2016-12-18 17:28:29 +01:00
2021-02-28 11:35:10 +01:00
matrices . translate ( - 60F , 0F , 60F ) ;
2021-08-22 17:09:06 +02:00
matrices . mulPose ( Vector3f . YP . rotationDegrees ( 90 ) ) ;
2021-02-28 11:35:10 +01:00
}
// TODO: Remove if the above works
// NumberFormat format = NumberFormat.getInstance();
// FontRenderer font = Minecraft.getInstance().fontRenderer;
//
// String s = format.format(cap.getEnergyStored()) + "/" + format.format(cap.getMaxEnergyStored());
// float lengthS = -font.getStringWidth(s) / 2F;
// String s2 = I18n.format("actuallyadditions.cflong");
// float lengthS2 = -font.getStringWidth(s2) / 2F;
//
// for (int i = 0; i < 4; i++) {
// font.drawString(matrices, s, lengthS, 10F, 0xFFFFFF);
// font.drawString(matrices, s2, lengthS2, 20F, 0xFFFFFF);
//
// RenderSystem.translatef(-50F, 0F, 50F);
// RenderSystem.rotatef(90F, 0F, 1F, 0F);
// }
} ) ;
2016-12-18 17:28:29 +01:00
2021-08-22 17:09:06 +02:00
matrices . popPose ( ) ; // text rotation
matrices . popPose ( ) ; // rotation + centering
2016-12-18 17:28:29 +01:00
2021-08-22 17:09:06 +02:00
double boop = Util . getMillis ( ) / 800D ;
2021-02-28 11:35:10 +01:00
float scale = stack . getItem ( ) instanceof BlockItem
? 0 . 85F
: 0 . 65F ;
2016-12-18 17:28:29 +01:00
2021-08-22 17:09:06 +02:00
matrices . pushPose ( ) ;
2021-02-28 11:35:10 +01:00
matrices . translate ( . 5f , 1f + Math . sin ( boop % ( 2 * Math . PI ) ) * 0 . 065 , . 5f ) ;
2021-08-22 17:09:06 +02:00
matrices . mulPose ( Vector3f . YP . rotationDegrees ( ( float ) ( boop * 40D % 360 ) ) ) ;
2021-02-28 11:35:10 +01:00
matrices . scale ( scale , scale , scale ) ;
2016-12-18 17:28:29 +01:00
2021-02-28 11:35:10 +01:00
try {
2021-08-22 17:09:06 +02:00
Minecraft . getInstance ( ) . getItemRenderer ( ) . renderStatic (
2021-02-28 11:35:10 +01:00
stack , ItemCameraTransforms . TransformType . FIXED , combinedLight , combinedOverlay , matrices , buffer
) ;
} 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-28 11:35:10 +01:00
2021-08-22 17:09:06 +02:00
matrices . popPose ( ) ;
2016-12-18 17:28:29 +01:00
}
}