2016-06-05 04:05:37 +02:00
/ *
* This file ( " BlockPlayerInterface.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-06-05 04:05:37 +02:00
* /
package de.ellpeck.actuallyadditions.mod.blocks ;
2021-02-27 21:24:26 +01:00
import com.mojang.blaze3d.matrix.MatrixStack ;
2016-06-05 04:05:37 +02:00
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase ;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface ;
2016-07-14 02:11:41 +02:00
import de.ellpeck.actuallyadditions.mod.util.StringUtil ;
2021-03-01 20:14:50 +01:00
import net.minecraft.block.BlockState ;
2021-02-27 17:22:03 +01:00
import net.minecraft.client.MainWindow ;
2016-07-14 02:11:41 +02:00
import net.minecraft.client.Minecraft ;
2021-03-01 20:14:50 +01:00
import net.minecraft.entity.LivingEntity ;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity ;
2016-06-05 04:05:37 +02:00
import net.minecraft.item.ItemStack ;
import net.minecraft.tileentity.TileEntity ;
import net.minecraft.util.math.BlockPos ;
2021-03-01 20:14:50 +01:00
import net.minecraft.util.math.BlockRayTraceResult ;
2016-07-14 02:11:41 +02:00
import net.minecraft.util.math.RayTraceResult ;
2021-03-01 20:14:50 +01:00
import net.minecraft.util.math.shapes.ISelectionContext ;
import net.minecraft.util.math.shapes.VoxelShape ;
2016-07-14 02:11:41 +02:00
import net.minecraft.util.text.TextFormatting ;
2021-03-01 20:14:50 +01:00
import net.minecraft.world.IBlockReader ;
2016-06-05 04:05:37 +02:00
import net.minecraft.world.World ;
2021-02-27 13:24:45 +01:00
import net.minecraftforge.api.distmarker.Dist ;
2021-03-01 20:14:50 +01:00
import net.minecraftforge.api.distmarker.OnlyIn ;
2021-03-01 18:11:34 +01:00
2016-06-05 04:05:37 +02:00
2019-05-02 09:10:29 +02:00
public class BlockPlayerInterface extends BlockContainerBase implements IHudDisplay {
2021-02-27 13:24:45 +01:00
public BlockPlayerInterface ( ) {
2021-03-01 20:14:50 +01:00
super ( ActuallyBlocks . defaultPickProps ( 0 , 4 . 5F , 10 . 0F ) ) ;
2016-06-05 04:05:37 +02:00
}
2021-12-29 03:36:23 +01:00
//@Override
2021-08-22 17:09:06 +02:00
public TileEntity newBlockEntity ( IBlockReader worldIn ) {
2016-06-05 04:05:37 +02:00
return new TileEntityPlayerInterface ( ) ;
}
@Override
2021-08-22 17:09:06 +02:00
public void setPlacedBy ( World world , BlockPos pos , BlockState state , LivingEntity player , ItemStack stack ) {
TileEntity tile = world . getBlockEntity ( pos ) ;
2019-05-02 09:10:29 +02:00
if ( tile instanceof TileEntityPlayerInterface ) {
TileEntityPlayerInterface face = ( TileEntityPlayerInterface ) tile ;
if ( face . connectedPlayer = = null ) {
2021-08-22 17:09:06 +02:00
face . connectedPlayer = player . getUUID ( ) ;
2021-03-01 20:14:50 +01:00
face . playerName = player . getName ( ) . getString ( ) ;
2021-08-22 17:09:06 +02:00
face . setChanged ( ) ;
2016-07-14 02:11:41 +02:00
face . sendUpdate ( ) ;
2016-06-05 04:05:37 +02:00
}
}
2021-08-22 17:09:06 +02:00
super . setPlacedBy ( world , pos , state , player , stack ) ;
2016-06-05 04:05:37 +02:00
}
2016-07-14 02:11:41 +02:00
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn ( Dist . CLIENT )
2021-02-27 21:24:26 +01:00
public void displayHud ( MatrixStack matrices , Minecraft minecraft , PlayerEntity player , ItemStack stack , RayTraceResult rayCast , MainWindow resolution ) {
2021-03-01 20:14:50 +01:00
if ( ! ( rayCast instanceof BlockRayTraceResult ) ) {
return ;
}
2021-08-22 17:09:06 +02:00
TileEntity tile = minecraft . level . getBlockEntity ( ( ( BlockRayTraceResult ) rayCast ) . getBlockPos ( ) ) ;
2019-05-02 09:10:29 +02:00
if ( tile ! = null ) {
if ( tile instanceof TileEntityPlayerInterface ) {
TileEntityPlayerInterface face = ( TileEntityPlayerInterface ) tile ;
2021-02-27 13:24:45 +01:00
String name = face . playerName = = null
? " Unknown "
: face . playerName ;
2021-08-22 17:09:06 +02:00
minecraft . font . drawShadow ( matrices , " Bound to: " + TextFormatting . RED + name , resolution . getGuiScaledWidth ( ) / 2f + 5 , resolution . getGuiScaledHeight ( ) / 2f + 5 , StringUtil . DECIMAL_COLOR_WHITE ) ;
minecraft . font . drawShadow ( matrices , " UUID: " + TextFormatting . DARK_GREEN + face . connectedPlayer , resolution . getGuiScaledWidth ( ) / 2f + 5 , resolution . getGuiScaledHeight ( ) / 2f + 15 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2016-07-14 02:11:41 +02:00
}
}
}
2021-03-01 20:14:50 +01:00
@Override
public VoxelShape getShape ( BlockState state , IBlockReader worldIn , BlockPos pos , ISelectionContext context ) {
return Shapes . PLAYER_INTERFACE_SHAPE ;
}
2016-06-05 04:05:37 +02:00
}