/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.client.gui.components.debug; import java.util.ArrayList; import java.util.Map; import net.minecraft.ChatFormatting; import net.minecraft.SharedConstants; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.debug.DebugScreenDisplayer; import net.minecraft.client.gui.components.debug.DebugScreenEntry; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.Identifier; import net.minecraft.util.Util; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import org.jspecify.annotations.Nullable; public class DebugEntryLookingAtBlock implements DebugScreenEntry { private static final Identifier GROUP = Identifier.withDefaultNamespace("looking_at_block"); @Override public void display(DebugScreenDisplayer displayer, @Nullable Level serverOrClientLevel, @Nullable LevelChunk clientChunk, @Nullable LevelChunk serverChunk) { Level clientOrServerLevel; Entity cameraEntity = Minecraft.getInstance().getCameraEntity(); Level level = clientOrServerLevel = SharedConstants.DEBUG_SHOW_SERVER_DEBUG_VALUES ? serverOrClientLevel : Minecraft.getInstance().level; if (cameraEntity == null || clientOrServerLevel == null) { return; } HitResult block = cameraEntity.pick(20.0, 0.0f, false); ArrayList result = new ArrayList(); if (block.getType() == HitResult.Type.BLOCK) { BlockPos pos = ((BlockHitResult)block).getBlockPos(); BlockState blockState = clientOrServerLevel.getBlockState(pos); result.add(String.valueOf(ChatFormatting.UNDERLINE) + "Targeted Block: " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ()); result.add(String.valueOf(BuiltInRegistries.BLOCK.getKey(blockState.getBlock()))); for (Map.Entry, Comparable> entry : blockState.getValues().entrySet()) { result.add(this.getPropertyValueString(entry)); } blockState.getTags().map(e -> "#" + String.valueOf(e.location())).forEach(result::add); } displayer.addToGroup(GROUP, result); } private String getPropertyValueString(Map.Entry, Comparable> entry) { Property property = entry.getKey(); Comparable value = entry.getValue(); Object valueString = Util.getPropertyName(property, value); if (Boolean.TRUE.equals(value)) { valueString = String.valueOf(ChatFormatting.GREEN) + (String)valueString; } else if (Boolean.FALSE.equals(value)) { valueString = String.valueOf(ChatFormatting.RED) + (String)valueString; } return property.getName() + ": " + (String)valueString; } }