2018-10-13 20:35:18 +02:00
package de.ellpeck.naturesaura.events ;
2021-12-19 18:24:54 +01:00
import com.mojang.blaze3d.platform.Window ;
import com.mojang.blaze3d.systems.RenderSystem ;
2023-07-08 12:32:27 +02:00
import com.mojang.blaze3d.vertex.BufferBuilder ;
import com.mojang.blaze3d.vertex.DefaultVertexFormat ;
import com.mojang.blaze3d.vertex.Tesselator ;
import com.mojang.blaze3d.vertex.VertexFormat ;
2019-01-27 13:57:34 +01:00
import de.ellpeck.naturesaura.Helper ;
2018-12-04 13:38:46 +01:00
import de.ellpeck.naturesaura.ModConfig ;
2018-10-13 20:35:18 +02:00
import de.ellpeck.naturesaura.NaturesAura ;
2018-11-12 22:04:40 +01:00
import de.ellpeck.naturesaura.api.NaturesAuraAPI ;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk ;
2021-12-19 18:24:54 +01:00
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer ;
2018-11-12 01:29:33 +01:00
import de.ellpeck.naturesaura.api.aura.type.IAuraType ;
2021-12-20 00:49:38 +01:00
import de.ellpeck.naturesaura.api.render.IVisualizable ;
2021-12-19 18:24:54 +01:00
import de.ellpeck.naturesaura.blocks.tiles.* ;
2020-01-26 01:41:49 +01:00
import de.ellpeck.naturesaura.items.ItemAuraCache ;
import de.ellpeck.naturesaura.items.ItemRangeVisualizer ;
2020-01-26 19:26:50 +01:00
import de.ellpeck.naturesaura.items.ModItems ;
2020-01-22 23:21:52 +01:00
import de.ellpeck.naturesaura.packet.PacketAuraChunk ;
2021-12-15 16:24:53 +01:00
import net.minecraft.ChatFormatting ;
2018-10-13 20:35:18 +02:00
import net.minecraft.client.Minecraft ;
2023-07-08 12:32:27 +02:00
import net.minecraft.client.gui.GuiGraphics ;
2021-12-19 18:24:54 +01:00
import net.minecraft.client.gui.screens.ChatScreen ;
2021-12-15 16:24:53 +01:00
import net.minecraft.client.renderer.BiomeColors ;
2022-08-01 16:14:37 +02:00
import net.minecraft.client.renderer.GameRenderer ;
2021-12-19 18:24:54 +01:00
import net.minecraft.client.resources.language.I18n ;
2021-12-15 16:24:53 +01:00
import net.minecraft.core.BlockPos ;
import net.minecraft.resources.ResourceLocation ;
import net.minecraft.util.Mth ;
2019-02-09 21:55:40 +01:00
import net.minecraft.util.Tuple ;
2021-12-15 16:24:53 +01:00
import net.minecraft.world.item.ItemStack ;
import net.minecraft.world.item.Items ;
2021-12-20 00:49:38 +01:00
import net.minecraft.world.level.Level ;
2022-08-01 16:14:37 +02:00
import net.minecraft.world.level.block.Blocks ;
import net.minecraft.world.level.block.BonemealableBlock ;
import net.minecraft.world.level.block.LeavesBlock ;
import net.minecraft.world.level.block.MyceliumBlock ;
2021-12-19 18:24:54 +01:00
import net.minecraft.world.phys.BlockHitResult ;
2020-01-21 21:04:44 +01:00
import net.minecraftforge.api.distmarker.Dist ;
import net.minecraftforge.api.distmarker.OnlyIn ;
2022-08-01 16:14:37 +02:00
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent ;
import net.minecraftforge.client.event.RenderGuiOverlayEvent ;
import net.minecraftforge.client.event.RenderLevelStageEvent ;
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay ;
2019-01-28 17:12:50 +01:00
import net.minecraftforge.common.IPlantable ;
2021-12-19 18:24:54 +01:00
import net.minecraftforge.energy.EnergyStorage ;
2020-01-21 21:04:44 +01:00
import net.minecraftforge.event.TickEvent ;
2019-10-20 22:30:49 +02:00
import net.minecraftforge.eventbus.api.SubscribeEvent ;
2018-10-21 12:51:13 +02:00
import org.apache.commons.lang3.mutable.MutableInt ;
2018-10-13 20:35:18 +02:00
2019-01-29 16:01:10 +01:00
import java.text.NumberFormat ;
2020-12-07 01:06:22 +01:00
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
2018-10-13 20:35:18 +02:00
2019-10-20 22:30:49 +02:00
@OnlyIn ( Dist . CLIENT )
2018-10-13 20:35:18 +02:00
public class ClientEvents {
2018-10-20 21:19:08 +02:00
public static final ResourceLocation OVERLAYS = new ResourceLocation ( NaturesAura . MOD_ID , " textures/gui/overlays.png " ) ;
2019-03-01 20:51:43 +01:00
public static final ResourceLocation BOOK_GUI = new ResourceLocation ( NaturesAura . MOD_ID , " textures/gui/book.png " ) ;
2020-02-07 15:22:30 +01:00
public static final List < PacketAuraChunk > PENDING_AURA_CHUNKS = new ArrayList < > ( ) ;
2019-02-25 17:15:39 +01:00
private static final ItemStack ITEM_FRAME = new ItemStack ( Items . ITEM_FRAME ) ;
2020-02-21 18:15:37 +01:00
private static final ItemStack DISPENSER = new ItemStack ( Blocks . DISPENSER ) ;
2019-02-09 21:55:40 +01:00
private static final Map < ResourceLocation , Tuple < ItemStack , Boolean > > SHOWING_EFFECTS = new HashMap < > ( ) ;
private static ItemStack heldCache = ItemStack . EMPTY ;
private static ItemStack heldEye = ItemStack . EMPTY ;
private static ItemStack heldOcular = ItemStack . EMPTY ;
2021-12-20 00:49:38 +01:00
private static BlockPos hoveringAuraSpot ;
2018-10-18 19:08:15 +02:00
2018-10-13 20:35:18 +02:00
@SubscribeEvent
2022-08-01 16:14:37 +02:00
public void onDebugRender ( CustomizeGuiOverlayEvent . DebugText event ) {
2021-12-15 16:30:22 +01:00
var mc = Minecraft . getInstance ( ) ;
2021-12-15 16:24:53 +01:00
if ( mc . options . renderDebug & & ModConfig . instance . debugText . get ( ) ) {
2021-12-15 16:30:22 +01:00
var prefix = ChatFormatting . GREEN + " [ " + NaturesAura . MOD_NAME + " ] " + ChatFormatting . RESET + " " ;
2018-10-13 20:35:18 +02:00
List < String > left = event . getLeft ( ) ;
2023-06-28 10:13:18 +02:00
if ( mc . player . isCreative ( ) | | mc . player . isSpectator ( ) ) {
2020-12-04 14:15:34 +01:00
left . add ( " " ) ;
2021-12-15 16:30:22 +01:00
var amount = new MutableInt ( IAuraChunk . DEFAULT_AURA ) ;
var spots = new MutableInt ( ) ;
var chunks = new MutableInt ( ) ;
2021-12-15 16:24:53 +01:00
IAuraChunk . getSpotsInArea ( mc . level , mc . player . blockPosition ( ) , 35 , ( blockPos , drainSpot ) - > {
2018-10-26 20:25:21 +02:00
spots . increment ( ) ;
2018-12-02 01:36:41 +01:00
amount . add ( drainSpot ) ;
2018-12-04 13:38:46 +01:00
} ) ;
2021-12-15 16:24:53 +01:00
Helper . getAuraChunksWithSpotsInArea ( mc . level , mc . player . blockPosition ( ) , 35 , c - > chunks . increment ( ) ) ;
2021-12-15 16:30:22 +01:00
var format = NumberFormat . getInstance ( ) ;
2021-01-30 16:43:46 +01:00
left . add ( prefix + " A: " + format . format ( amount . intValue ( ) ) + " (S: " + spots . intValue ( ) + " , C: " + chunks . intValue ( ) + " ) " ) ;
2021-12-04 15:40:09 +01:00
left . add ( prefix + " AT: " + IAuraType . forLevel ( mc . level ) . getName ( ) ) ;
2018-10-26 20:25:21 +02:00
}
2018-10-13 20:35:18 +02:00
}
}
@SubscribeEvent
2020-01-21 21:04:44 +01:00
public void onClientTick ( TickEvent . ClientTickEvent event ) {
2020-01-22 23:21:52 +01:00
if ( event . phase ! = TickEvent . Phase . END ) {
2022-06-27 15:24:04 +02:00
ClientEvents . heldCache = ItemStack . EMPTY ;
ClientEvents . heldEye = ItemStack . EMPTY ;
ClientEvents . heldOcular = ItemStack . EMPTY ;
2019-02-09 21:55:40 +01:00
2021-12-15 16:30:22 +01:00
var mc = Minecraft . getInstance ( ) ;
2021-12-04 15:40:09 +01:00
if ( mc . level = = null ) {
2020-01-26 01:41:49 +01:00
ItemRangeVisualizer . clear ( ) ;
2022-06-27 15:24:04 +02:00
ClientEvents . PENDING_AURA_CHUNKS . clear ( ) ;
2020-01-22 23:21:52 +01:00
} else {
2022-06-27 15:24:04 +02:00
ClientEvents . PENDING_AURA_CHUNKS . removeIf ( next - > next . tryHandle ( mc . level ) ) ;
2020-01-22 23:21:52 +01:00
2021-12-15 16:24:53 +01:00
if ( ! mc . isPaused ( ) ) {
2021-12-04 15:40:09 +01:00
if ( mc . level . getGameTime ( ) % 20 = = 0 ) {
2021-12-15 16:30:22 +01:00
var amount = Mth . floor ( 190 * ModConfig . instance . excessParticleAmount . get ( ) ) ;
for ( var i = 0 ; i < amount ; i + + ) {
var x = Mth . floor ( mc . player . getX ( ) ) + mc . level . random . nextInt ( 64 ) - 32 ;
2023-02-05 15:49:29 +01:00
var y = Mth . floor ( mc . player . getY ( ) ) + mc . level . random . nextInt ( 32 ) - 16 ;
2021-12-15 16:30:22 +01:00
var z = Mth . floor ( mc . player . getZ ( ) ) + mc . level . random . nextInt ( 64 ) - 32 ;
2023-02-05 15:49:29 +01:00
var pos = Helper . getClosestAirAboveGround ( mc . level , new BlockPos ( x , y , z ) , 16 ) . below ( ) ;
2021-12-15 16:30:22 +01:00
var state = mc . level . getBlockState ( pos ) ;
var block = state . getBlock ( ) ;
2021-12-15 16:24:53 +01:00
if ( block instanceof BonemealableBlock | | block instanceof IPlantable | | block instanceof LeavesBlock | | block instanceof MyceliumBlock ) {
2021-12-15 16:30:22 +01:00
var excess = IAuraChunk . triangulateAuraInArea ( mc . level , pos , 45 ) - IAuraChunk . DEFAULT_AURA ;
2020-01-22 23:21:52 +01:00
if ( excess > 0 ) {
2021-12-15 16:30:22 +01:00
var chance = Math . max ( 10 , 50 - excess / 25000 ) ;
2021-12-15 16:24:53 +01:00
if ( mc . level . random . nextInt ( chance ) < = 0 )
2020-01-22 23:21:52 +01:00
NaturesAuraAPI . instance ( ) . spawnMagicParticle (
2021-12-15 16:24:53 +01:00
pos . getX ( ) + mc . level . random . nextFloat ( ) ,
2020-01-22 23:21:52 +01:00
pos . getY ( ) + 0 . 5F ,
2021-12-15 16:24:53 +01:00
pos . getZ ( ) + mc . level . random . nextFloat ( ) ,
mc . level . random . nextGaussian ( ) * 0 . 01F ,
mc . level . random . nextFloat ( ) * 0 . 025F ,
mc . level . random . nextGaussian ( ) * 0 . 01F ,
block instanceof MyceliumBlock ? 0x875ca1 : BiomeColors . getAverageGrassColor ( mc . level , pos ) ,
Math . min ( 2F , 1F + mc . level . random . nextFloat ( ) * ( excess / 30000F ) ) ,
Math . min ( 300 , 100 + mc . level . random . nextInt ( excess / 3000 + 1 ) ) ,
2020-01-22 23:21:52 +01:00
0F , false , true ) ;
}
2019-01-28 17:12:50 +01:00
}
2019-01-28 16:56:22 +01:00
}
}
2021-12-04 15:40:09 +01:00
if ( Helper . isHoldingItem ( mc . player , ModItems . RANGE_VISUALIZER ) & & mc . level . getGameTime ( ) % 5 = = 0 ) {
2021-12-15 16:30:22 +01:00
var inst = NaturesAuraAPI . instance ( ) ;
2020-01-22 23:21:52 +01:00
inst . setParticleSpawnRange ( 512 ) ;
inst . setParticleDepth ( false ) ;
2021-12-15 16:30:22 +01:00
for ( var pos : ItemRangeVisualizer . VISUALIZED_RAILS . get ( mc . level . dimension ( ) . location ( ) ) ) {
2020-01-22 23:21:52 +01:00
NaturesAuraAPI . instance ( ) . spawnMagicParticle (
2021-12-15 16:24:53 +01:00
pos . getX ( ) + mc . level . random . nextFloat ( ) ,
pos . getY ( ) + mc . level . random . nextFloat ( ) ,
pos . getZ ( ) + mc . level . random . nextFloat ( ) ,
0F , 0F , 0F , 0xe0faff , mc . level . random . nextFloat ( ) * 5 + 1 , 100 , 0F , false , true ) ;
2020-01-22 23:21:52 +01:00
}
inst . setParticleDepth ( true ) ;
inst . setParticleSpawnRange ( 32 ) ;
2019-03-20 20:51:24 +01:00
}
2022-06-27 15:24:04 +02:00
ClientEvents . heldCache = Helper . getEquippedItem ( s - > s . getItem ( ) instanceof ItemAuraCache , mc . player ) ;
ClientEvents . heldEye = Helper . getEquippedItem ( s - > s . getItem ( ) = = ModItems . EYE , mc . player ) ;
ClientEvents . heldOcular = Helper . getEquippedItem ( s - > s . getItem ( ) = = ModItems . EYE_IMPROVED , mc . player ) ;
2019-03-20 20:51:24 +01:00
2022-06-27 15:24:04 +02:00
if ( ! ClientEvents . heldOcular . isEmpty ( ) & & mc . level . getGameTime ( ) % 20 = = 0 ) {
ClientEvents . SHOWING_EFFECTS . clear ( ) ;
2021-12-15 16:24:53 +01:00
Helper . getAuraChunksWithSpotsInArea ( mc . level , mc . player . blockPosition ( ) , 100 ,
2022-06-27 15:24:04 +02:00
chunk - > chunk . getActiveEffectIcons ( mc . player , ClientEvents . SHOWING_EFFECTS ) ) ;
2020-01-22 23:21:52 +01:00
}
2019-03-20 20:51:24 +01:00
}
2019-01-28 15:43:21 +01:00
}
2018-10-13 20:35:18 +02:00
}
}
2018-10-14 17:46:00 +02:00
2018-12-04 13:38:46 +01:00
@SubscribeEvent
2022-08-01 16:14:37 +02:00
public void onLevelRender ( RenderLevelStageEvent event ) {
if ( event . getStage ( ) ! = RenderLevelStageEvent . Stage . AFTER_PARTICLES )
return ;
2021-12-20 00:49:38 +01:00
var mc = Minecraft . getInstance ( ) ;
var view = mc . gameRenderer . getMainCamera ( ) . getPosition ( ) ;
var tesselator = Tesselator . getInstance ( ) ;
var buffer = tesselator . getBuilder ( ) ;
mc . getProfiler ( ) . push ( NaturesAura . MOD_ID + " :onLevelRender " ) ;
RenderSystem . enableDepthTest ( ) ;
var mv = RenderSystem . getModelViewStack ( ) ;
mv . pushPose ( ) ;
mv . mulPoseMatrix ( event . getPoseStack ( ) . last ( ) . pose ( ) ) ;
mv . translate ( - view . x , - view . y , - view . z ) ;
RenderSystem . applyModelViewMatrix ( ) ;
RenderSystem . enableBlend ( ) ;
2022-08-01 16:14:37 +02:00
RenderSystem . setShader ( GameRenderer : : getPositionColorShader ) ;
RenderSystem . setShaderColor ( 1 , 1 , 1 , 1 ) ;
2021-12-20 00:49:38 +01:00
// aura spot debug
2022-06-27 15:24:04 +02:00
ClientEvents . hoveringAuraSpot = null ;
2023-06-28 10:13:18 +02:00
if ( mc . options . renderDebug & & ( mc . player . isCreative ( ) | | mc . player . isSpectator ( ) ) & & ModConfig . instance . debugLevel . get ( ) ) {
2021-12-20 00:49:38 +01:00
var playerEye = mc . player . getEyePosition ( event . getPartialTick ( ) ) ;
var playerView = mc . player . getViewVector ( event . getPartialTick ( ) ) . normalize ( ) ;
var range = mc . gameMode . getPickRange ( ) ;
buffer . begin ( VertexFormat . Mode . QUADS , DefaultVertexFormat . POSITION_COLOR ) ;
IAuraChunk . getSpotsInArea ( mc . level , mc . player . blockPosition ( ) , 64 , ( pos , spot ) - > {
Helper . renderWeirdBox ( buffer , pos . getX ( ) , pos . getY ( ) , pos . getZ ( ) , 1 , 1 , 1 , spot > 0 ? 0F : 1F , spot > 0 ? 1F : 0F , 0F , 0 . 35F ) ;
// dirty raytrace to see if we're looking at roughly this spot
if ( playerEye . distanceToSqr ( pos . getX ( ) + 0 . 5 , pos . getY ( ) + 0 . 5 , pos . getZ ( ) + 0 . 5 ) < = range * range ) {
for ( var d = 0F ; d < = range ; d + = 0 . 5F ) {
2023-07-08 12:32:27 +02:00
if ( pos . equals ( BlockPos . containing ( playerEye . add ( playerView . scale ( d ) ) ) ) ) {
2022-06-27 15:24:04 +02:00
ClientEvents . hoveringAuraSpot = pos ;
2021-12-20 00:49:38 +01:00
break ;
}
}
}
2018-12-04 13:38:46 +01:00
2021-12-20 00:49:38 +01:00
} ) ;
tesselator . end ( ) ;
2018-12-04 13:38:46 +01:00
}
2019-01-27 13:57:34 +01:00
2021-12-20 00:49:38 +01:00
// range visualizer
2019-03-20 20:51:24 +01:00
if ( Helper . isHoldingItem ( mc . player , ModItems . RANGE_VISUALIZER ) ) {
2021-12-20 00:49:38 +01:00
RenderSystem . disableCull ( ) ;
var dim = mc . level . dimension ( ) . location ( ) ;
buffer . begin ( VertexFormat . Mode . QUADS , DefaultVertexFormat . POSITION_COLOR ) ;
for ( var pos : ItemRangeVisualizer . VISUALIZED_BLOCKS . get ( dim ) ) {
if ( ! mc . level . isLoaded ( pos ) )
2019-03-20 20:51:24 +01:00
continue ;
2021-12-20 00:49:38 +01:00
var state = mc . level . getBlockState ( pos ) ;
var block = state . getBlock ( ) ;
2019-03-20 20:51:24 +01:00
if ( ! ( block instanceof IVisualizable ) )
continue ;
2021-12-20 00:49:38 +01:00
this . renderVisualize ( buffer , ( IVisualizable ) block , mc . level , pos ) ;
2019-03-20 20:51:24 +01:00
}
2021-12-20 00:49:38 +01:00
for ( var entity : ItemRangeVisualizer . VISUALIZED_ENTITIES . get ( dim ) ) {
2020-01-21 21:04:44 +01:00
if ( ! entity . isAlive ( ) | | ! ( entity instanceof IVisualizable ) )
2019-03-20 20:51:24 +01:00
continue ;
2021-12-20 00:49:38 +01:00
this . renderVisualize ( buffer , ( IVisualizable ) entity , mc . level , entity . blockPosition ( ) ) ;
2019-01-27 13:57:34 +01:00
}
2021-12-20 00:49:38 +01:00
tesselator . end ( ) ;
RenderSystem . enableCull ( ) ;
2019-01-27 13:57:34 +01:00
}
2021-12-20 00:49:38 +01:00
mv . popPose ( ) ;
RenderSystem . applyModelViewMatrix ( ) ;
RenderSystem . disableBlend ( ) ;
mc . getProfiler ( ) . pop ( ) ;
2018-12-04 13:38:46 +01:00
}
2021-12-20 00:49:38 +01:00
private void renderVisualize ( BufferBuilder buffer , IVisualizable visualize , Level level , BlockPos pos ) {
var box = visualize . getVisualizationBounds ( level , pos ) ;
if ( box ! = null ) {
box = box . inflate ( 0 . 05F ) ;
var color = visualize . getVisualizationColor ( level , pos ) ;
Helper . renderWeirdBox ( buffer , box . minX , box . minY , box . minZ , box . maxX - box . minX , box . maxY - box . minY , box . maxZ - box . minZ , ( color > > 16 & 255 ) / 255F , ( color > > 8 & 255 ) / 255F , ( color & 255 ) / 255F , 0 . 5F ) ;
}
}
2019-01-28 15:43:21 +01:00
2018-10-14 17:46:00 +02:00
@SubscribeEvent
2022-08-01 16:14:37 +02:00
public void onOverlayRender ( RenderGuiOverlayEvent . Post event ) {
2021-12-19 18:24:54 +01:00
var mc = Minecraft . getInstance ( ) ;
2023-07-08 12:32:27 +02:00
var graphics = event . getGuiGraphics ( ) ;
var stack = graphics . pose ( ) ;
2022-08-01 16:14:37 +02:00
if ( event . getOverlay ( ) = = VanillaGuiOverlay . HOTBAR . type ( ) ) {
2021-12-15 16:24:53 +01:00
var res = event . getWindow ( ) ;
2018-10-14 17:46:00 +02:00
if ( mc . player ! = null ) {
2022-06-27 15:24:04 +02:00
if ( ! ClientEvents . heldCache . isEmpty ( ) ) {
var container = ClientEvents . heldCache . getCapability ( NaturesAuraAPI . CAP_AURA_CONTAINER , null ) . orElse ( null ) ;
2021-12-19 18:24:54 +01:00
var width = Mth . ceil ( container . getStoredAura ( ) / ( float ) container . getMaxAura ( ) * 80 ) ;
2020-03-11 23:32:37 +01:00
int conf = ModConfig . instance . cacheBarLocation . get ( ) ;
2021-12-19 18:24:54 +01:00
var x = res . getGuiScaledWidth ( ) / 2 + ( conf = = 0 ? - 173 - ( mc . player . getOffhandItem ( ) . isEmpty ( ) ? 0 : 29 ) : 93 ) ;
var y = res . getGuiScaledHeight ( ) - 8 ;
2018-11-02 21:10:53 +01:00
2021-12-19 18:24:54 +01:00
stack . pushPose ( ) ;
2018-11-02 21:10:53 +01:00
2021-12-19 18:24:54 +01:00
var color = container . getAuraColor ( ) ;
RenderSystem . setShaderColor ( ( color > > 16 & 255 ) / 255F , ( color > > 8 & 255 ) / 255F , ( color & 255 ) / 255F , 1 ) ;
2018-11-02 21:10:53 +01:00
if ( width < 80 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , x + width , y , width , 0 , 80 - width , 6 , 256 , 256 ) ;
2018-11-02 21:10:53 +01:00
if ( width > 0 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , x , y , 0 , 6 , width , 6 , 256 , 256 ) ;
2018-11-02 21:10:53 +01:00
2021-12-19 18:24:54 +01:00
var scale = 0 . 75F ;
stack . pushPose ( ) ;
stack . scale ( scale , scale , scale ) ;
2022-06-27 15:24:04 +02:00
var s = ClientEvents . heldCache . getHoverName ( ) . getString ( ) ;
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , s , conf = = 1 ? x / scale : ( x + 80 ) / scale - mc . font . width ( s ) , ( y - 7 ) / scale , color , true ) ;
2021-12-19 18:24:54 +01:00
stack . popPose ( ) ;
2018-11-02 21:10:53 +01:00
2021-12-19 18:24:54 +01:00
RenderSystem . setShaderColor ( 1F , 1F , 1F , 1 ) ;
stack . pushPose ( ) ;
2018-11-02 21:10:53 +01:00
}
2018-10-20 21:19:08 +02:00
2022-06-27 15:24:04 +02:00
if ( ! ClientEvents . heldEye . isEmpty ( ) | | ! ClientEvents . heldOcular . isEmpty ( ) ) {
2021-12-19 18:24:54 +01:00
stack . pushPose ( ) ;
2018-11-02 21:10:53 +01:00
2020-01-24 17:05:41 +01:00
int conf = ModConfig . instance . auraBarLocation . get ( ) ;
2021-12-19 18:24:54 +01:00
if ( ! mc . options . renderDebug & & ( conf ! = 2 | | ! ( mc . screen instanceof ChatScreen ) ) ) {
var color = IAuraType . forLevel ( mc . level ) . getColor ( ) ;
RenderSystem . setShaderColor ( ( color > > 16 & 0xFF ) / 255F , ( color > > 8 & 0xFF ) / 255F , ( color & 0xFF ) / 255F , 1 ) ;
2018-12-02 18:33:04 +01:00
2021-12-19 18:24:54 +01:00
var totalAmount = IAuraChunk . triangulateAuraInArea ( mc . level , mc . player . blockPosition ( ) , 35 ) ;
var totalPercentage = totalAmount / ( IAuraChunk . DEFAULT_AURA * 2F ) ;
var text = I18n . get ( " info. " + NaturesAura . MOD_ID + " .aura_in_area " ) ;
var textScale = 0 . 75F ;
2019-02-05 11:49:14 +01:00
2021-12-19 18:24:54 +01:00
var startX = conf % 2 = = 0 ? 3 : res . getGuiScaledWidth ( ) - 3 - 6 ;
2022-06-27 15:24:04 +02:00
var startY = conf < 2 ? 10 : ( ! ClientEvents . heldOcular . isEmpty ( ) & & ( totalPercentage > 1F | | totalPercentage < 0 ) ? - 26 : 0 ) + res . getGuiScaledHeight ( ) - 60 ;
2019-02-05 11:49:14 +01:00
float plusOffX = conf % 2 = = 0 ? 7 : - 1 - 6 ;
2021-12-19 18:24:54 +01:00
var textX = conf % 2 = = 0 ? 3 : res . getGuiScaledWidth ( ) - 3 - mc . font . width ( text ) * textScale ;
float textY = conf < 2 ? 3 : res . getGuiScaledHeight ( ) - 3 - 6 ;
2018-12-02 18:33:04 +01:00
2021-12-19 18:24:54 +01:00
var tHeight = Mth . ceil ( Mth . clamp ( totalPercentage , 0F , 1F ) * 50 ) ;
2022-06-27 15:24:04 +02:00
var y = ! ClientEvents . heldOcular . isEmpty ( ) & & totalPercentage > 1F ? startY + 26 : startY ;
2018-11-04 12:43:22 +01:00
if ( tHeight < 50 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , startX , y , 6 , 12 , 6 , 50 - tHeight , 256 , 256 ) ;
2018-11-04 12:43:22 +01:00
if ( tHeight > 0 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , startX , y + 50 - tHeight , 0 , 12 + 50 - tHeight , 6 , tHeight , 256 , 256 ) ;
2018-12-25 19:38:25 +01:00
2022-06-27 15:24:04 +02:00
if ( ! ClientEvents . heldOcular . isEmpty ( ) ) {
2021-12-19 18:24:54 +01:00
var topHeight = Mth . ceil ( Mth . clamp ( ( totalPercentage - 1F ) * 2F , 0F , 1F ) * 25 ) ;
2018-12-26 12:10:41 +01:00
if ( topHeight > 0 ) {
if ( topHeight < 25 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , startX , startY , 18 , 12 , 6 , 25 - topHeight , 256 , 256 ) ;
graphics . blit ( ClientEvents . OVERLAYS , startX , startY + 25 - topHeight , 12 , 12 + 25 - topHeight , 6 , topHeight , 256 , 256 ) ;
2018-12-26 12:10:41 +01:00
}
2021-12-19 18:24:54 +01:00
var bottomHeight = Mth . floor ( Mth . clamp ( ( totalPercentage + 1F ) * 2F - 1F , 0F , 1F ) * 25 ) ;
2018-12-26 12:10:41 +01:00
if ( bottomHeight < 25 ) {
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , startX , startY + 51 , 18 , 12 , 6 , 25 - bottomHeight , 256 , 256 ) ;
2018-12-26 12:10:41 +01:00
if ( bottomHeight > 0 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , startX , startY + 51 + 25 - bottomHeight , 12 , 12 + 25 - bottomHeight , 6 , bottomHeight , 256 , 256 ) ;
2018-12-26 12:10:41 +01:00
}
2018-12-25 19:38:25 +01:00
}
2018-11-04 12:43:22 +01:00
2022-06-27 15:24:04 +02:00
if ( totalPercentage > ( ClientEvents . heldOcular . isEmpty ( ) ? 1F : 1 . 5F ) )
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , " + " , startX + plusOffX , startY - 0 . 5F , color , true ) ;
2022-06-27 15:24:04 +02:00
if ( totalPercentage < ( ClientEvents . heldOcular . isEmpty ( ) ? 0F : - 0 . 5F ) )
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , " - " , startX + plusOffX , startY - 0 . 5F + ( ClientEvents . heldOcular . isEmpty ( ) ? 44 : 70 ) , color , true ) ;
2018-11-04 12:43:22 +01:00
2021-12-19 18:24:54 +01:00
stack . pushPose ( ) ;
stack . scale ( textScale , textScale , textScale ) ;
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , text , textX / textScale , textY / textScale , color , true ) ;
2021-12-19 18:24:54 +01:00
stack . popPose ( ) ;
2019-02-09 21:55:40 +01:00
2022-06-27 15:24:04 +02:00
if ( ! ClientEvents . heldOcular . isEmpty ( ) ) {
2021-12-19 18:24:54 +01:00
stack . pushPose ( ) ;
2022-09-15 15:10:18 +02:00
//stack.scale(scale, scale, scale);
2021-12-19 18:24:54 +01:00
var stackX = conf % 2 = = 0 ? 10 : res . getGuiScaledWidth ( ) - 22 ;
2022-09-15 15:10:18 +02:00
var stackY = conf < 2 ? 10 : res . getGuiScaledHeight ( ) - 60 ;
2022-06-27 15:24:04 +02:00
for ( var effect : ClientEvents . SHOWING_EFFECTS . values ( ) ) {
2021-12-19 18:24:54 +01:00
var itemStack = effect . getA ( ) ;
2023-07-08 12:32:27 +02:00
Helper . renderItemInGui ( graphics , itemStack , stackX , stackY , 1F ) ;
2020-01-21 21:04:44 +01:00
if ( effect . getB ( ) ) {
2021-12-19 18:24:54 +01:00
RenderSystem . disableDepthTest ( ) ;
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , stackX , stackY , 240 , 0 , 16 , 16 , 256 , 256 ) ;
2021-12-19 18:24:54 +01:00
RenderSystem . enableDepthTest ( ) ;
2019-02-09 21:55:40 +01:00
}
2022-09-15 15:10:18 +02:00
stackY + = 12 ;
2019-02-09 21:55:40 +01:00
}
2021-12-19 18:24:54 +01:00
stack . popPose ( ) ;
2019-02-09 21:55:40 +01:00
}
2018-11-04 12:43:22 +01:00
}
2018-11-02 21:10:53 +01:00
2021-12-19 18:24:54 +01:00
if ( mc . hitResult instanceof BlockHitResult blockHitResult ) {
var pos = blockHitResult . getBlockPos ( ) ;
2018-11-02 21:10:53 +01:00
if ( pos ! = null ) {
2021-12-19 18:24:54 +01:00
var tile = mc . level . getBlockEntity ( pos ) ;
2020-01-21 21:04:44 +01:00
IAuraContainer container ;
2021-12-19 18:24:54 +01:00
var x = res . getGuiScaledWidth ( ) / 2 ;
var y = res . getGuiScaledHeight ( ) / 2 ;
2021-12-23 13:27:52 +01:00
if ( tile ! = null & & ( container = tile . getCapability ( NaturesAuraAPI . CAP_AURA_CONTAINER , null ) . orElse ( null ) ) ! = null ) {
2021-12-19 18:24:54 +01:00
var state = mc . level . getBlockState ( pos ) ;
var blockStack = state . getBlock ( ) . getCloneItemStack ( state , blockHitResult , mc . level , pos , mc . player ) ;
2023-07-08 12:32:27 +02:00
this . drawContainerInfo ( graphics , container . getStoredAura ( ) , container . getMaxAura ( ) , container . getAuraColor ( ) ,
2021-12-28 11:53:10 +01:00
mc , res , 35 , blockStack . getHoverName ( ) . getString ( ) , null ) ;
2018-11-02 21:10:53 +01:00
2021-12-04 15:40:09 +01:00
if ( tile instanceof BlockEntityNatureAltar ) {
2021-12-19 18:24:54 +01:00
var tileStack = ( ( BlockEntityNatureAltar ) tile ) . getItemHandler ( ) . getStackInSlot ( 0 ) ;
2020-01-21 21:04:44 +01:00
if ( ! tileStack . isEmpty ( ) ) {
2021-12-23 13:27:52 +01:00
var stackCont = tileStack . getCapability ( NaturesAuraAPI . CAP_AURA_CONTAINER , null ) . orElse ( null ) ;
2020-01-21 21:04:44 +01:00
if ( stackCont ! = null ) {
2023-07-08 12:32:27 +02:00
this . drawContainerInfo ( graphics , stackCont . getStoredAura ( ) , stackCont . getMaxAura ( ) , stackCont . getAuraColor ( ) ,
2021-12-28 11:53:10 +01:00
mc , res , 55 , tileStack . getHoverName ( ) . getString ( ) , null ) ;
2020-01-21 21:04:44 +01:00
}
2018-11-02 21:10:53 +01:00
}
}
2021-12-04 15:40:09 +01:00
} else if ( tile instanceof BlockEntityRFConverter ) {
EnergyStorage storage = ( ( BlockEntityRFConverter ) tile ) . storage ;
2023-07-08 12:32:27 +02:00
this . drawContainerInfo ( graphics , storage . getEnergyStored ( ) , storage . getMaxEnergyStored ( ) , 0xcc4916 ,
2021-12-19 18:24:54 +01:00
mc , res , 35 , I18n . get ( " block.naturesaura.rf_converter " ) ,
2019-01-26 00:34:05 +01:00
storage . getEnergyStored ( ) + " / " + storage . getMaxEnergyStored ( ) + " RF " ) ;
2021-12-19 18:24:54 +01:00
} else if ( tile instanceof BlockEntityGratedChute chute ) {
var itemStack = chute . getItemHandler ( ) . getStackInSlot ( 0 ) ;
2019-01-30 16:03:41 +01:00
2021-12-19 18:24:54 +01:00
if ( itemStack . isEmpty ( ) ) {
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font ,
2021-12-19 18:24:54 +01:00
ChatFormatting . GRAY . toString ( ) + ChatFormatting . ITALIC + I18n . get ( " info.naturesaura.empty " ) ,
2020-01-21 21:04:44 +01:00
x + 5 , y - 11 , 0xFFFFFF ) ;
2021-12-19 18:24:54 +01:00
} else {
2023-07-08 12:32:27 +02:00
Helper . renderItemInGui ( graphics , itemStack , x + 2 , y - 18 , 1F ) ;
2021-12-19 18:24:54 +01:00
}
2019-02-25 17:15:39 +01:00
2023-07-08 12:32:27 +02:00
Helper . renderItemInGui ( graphics , ClientEvents . ITEM_FRAME , x - 24 , y - 24 , 1F ) ;
2021-12-19 18:24:54 +01:00
var u = chute . isBlacklist ? 240 : 224 ;
RenderSystem . disableDepthTest ( ) ;
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , x - 18 , y - 18 , u , 0 , 16 , 16 , 256 , 256 ) ;
2021-12-19 18:24:54 +01:00
RenderSystem . enableDepthTest ( ) ;
} else if ( tile instanceof BlockEntityItemDistributor distributor ) {
2023-07-08 12:32:27 +02:00
Helper . renderItemInGui ( graphics , ClientEvents . DISPENSER , x - 24 , y - 24 , 1F ) ;
2021-12-19 18:24:54 +01:00
var u = ! distributor . isRandomMode ? 240 : 224 ;
RenderSystem . disableDepthTest ( ) ;
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , x - 18 , y - 18 , u , 0 , 16 , 16 , 256 , 256 ) ;
2021-12-19 18:24:54 +01:00
RenderSystem . enableDepthTest ( ) ;
} else if ( tile instanceof BlockEntityAuraTimer timer ) {
var itemStack = timer . getItemHandler ( ) . getStackInSlot ( 0 ) ;
2020-09-22 03:17:02 +02:00
if ( ! itemStack . isEmpty ( ) ) {
2023-07-08 12:32:27 +02:00
Helper . renderItemInGui ( graphics , itemStack , x - 20 , y - 20 , 1 ) ;
graphics . drawString ( mc . font , ChatFormatting . GRAY + this . createTimeString ( timer . getTotalTime ( ) ) , x + 5 , y - 11 , 0xFFFFFF ) ;
graphics . drawString ( mc . font , ChatFormatting . GRAY + I18n . get ( " info.naturesaura.remaining " , this . createTimeString ( timer . getTimeLeft ( ) ) ) , x + 5 , y + 3 , 0xFFFFFF ) ;
2020-05-05 19:43:27 +02:00
}
2018-11-02 21:10:53 +01:00
}
}
}
2018-10-20 21:19:08 +02:00
2021-12-19 18:24:54 +01:00
RenderSystem . setShaderColor ( 1F , 1F , 1F , 1 ) ;
stack . popPose ( ) ;
2018-10-14 17:46:00 +02:00
}
2021-12-20 00:49:38 +01:00
2022-06-27 15:24:04 +02:00
if ( ClientEvents . hoveringAuraSpot ! = null ) {
2021-12-20 00:49:38 +01:00
var format = NumberFormat . getInstance ( ) ;
2023-06-27 10:40:31 +02:00
var spot = IAuraChunk . getAuraChunk ( mc . level , ClientEvents . hoveringAuraSpot ) . getActualDrainSpot ( ClientEvents . hoveringAuraSpot , false ) ;
var color = spot . intValue ( ) > 0 ? ChatFormatting . GREEN : ChatFormatting . RED ;
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , " Pos: " + spot . pos . toShortString ( ) , res . getGuiScaledWidth ( ) / 2F + 5 , res . getGuiScaledHeight ( ) / 2F - 20 , 0xFFFFFF , true ) ;
graphics . drawString ( mc . font , " Amount: " + color + format . format ( spot . intValue ( ) ) , res . getGuiScaledWidth ( ) / 2F + 5 , res . getGuiScaledHeight ( ) / 2F - 10 , 0xFFFFFF , true ) ;
2023-06-27 10:40:31 +02:00
if ( spot . originalSpreadPos ! = null )
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , " Dist from Original: " + ( int ) Math . sqrt ( spot . pos . distSqr ( spot . originalSpreadPos ) ) + " ( " + spot . originalSpreadPos . toShortString ( ) + " ) " , res . getGuiScaledWidth ( ) / 2F + 5 , res . getGuiScaledHeight ( ) / 2F , 0xFFFFFF , true ) ;
2021-12-20 00:49:38 +01:00
}
2018-10-14 17:46:00 +02:00
}
2021-12-19 18:24:54 +01:00
}
2018-10-14 17:46:00 +02:00
}
2018-10-20 21:19:08 +02:00
2020-05-05 19:43:27 +02:00
private String createTimeString ( int totalTicks ) {
2021-12-15 16:30:22 +01:00
var ticks = totalTicks % 20 ;
var seconds = totalTicks / 20 % 60 ;
var minutes = totalTicks / 20 / 60 % 60 ;
var hours = totalTicks / 20 / 60 / 60 ;
2020-05-05 19:43:27 +02:00
return String . format ( " %02d:%02d:%02d.%02d " , hours , minutes , seconds , ticks ) ;
}
2023-07-08 12:32:27 +02:00
private void drawContainerInfo ( GuiGraphics graphics , int stored , int max , int color , Minecraft mc , Window res , int yOffset , String name , String textBelow ) {
2021-12-19 18:24:54 +01:00
RenderSystem . setShaderColor ( ( color > > 16 & 255 ) / 255F , ( color > > 8 & 255 ) / 255F , ( color & 255 ) / 255F , 1 ) ;
2018-10-20 21:19:08 +02:00
2021-12-19 18:24:54 +01:00
var x = res . getGuiScaledWidth ( ) / 2 - 40 ;
var y = res . getGuiScaledHeight ( ) / 2 + yOffset ;
var width = Mth . ceil ( stored / ( float ) max * 80 ) ;
2018-10-20 21:19:08 +02:00
if ( width < 80 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , x + width , y , width , 0 , 80 - width , 6 , 256 , 256 ) ;
2018-10-20 21:19:08 +02:00
if ( width > 0 )
2023-07-08 12:32:27 +02:00
graphics . blit ( ClientEvents . OVERLAYS , x , y , 0 , 6 , width , 6 , 256 , 256 ) ;
2018-10-20 21:19:08 +02:00
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , name , x + 40 - mc . font . width ( name ) / 2F , y - 9 , color , true ) ;
2019-01-26 00:34:05 +01:00
if ( textBelow ! = null )
2023-07-08 12:32:27 +02:00
graphics . drawString ( mc . font , textBelow , x + 40 - mc . font . width ( textBelow ) / 2F , y + 7 , color , true ) ;
2021-12-19 18:24:54 +01:00
}
2018-10-13 20:35:18 +02:00
}