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 ;
2016-06-05 04:05:37 +02:00
import net.minecraft.block.SoundType ;
import net.minecraft.block.material.Material ;
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 ;
2016-06-05 04:05:37 +02:00
import net.minecraft.entity.EntityLivingBase ;
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.EnumRarity ;
import net.minecraft.item.ItemStack ;
import net.minecraft.tileentity.TileEntity ;
import net.minecraft.util.math.BlockPos ;
2016-07-14 02:11:41 +02:00
import net.minecraft.util.math.RayTraceResult ;
import net.minecraft.util.text.TextFormatting ;
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-02-26 22:15:48 +01:00
import net.minecraftforge.fml.relauncher.OnlyIn ;
2016-06-05 04:05:37 +02:00
2019-05-02 09:10:29 +02:00
public class BlockPlayerInterface extends BlockContainerBase implements IHudDisplay {
2016-06-05 04:05:37 +02:00
2021-02-27 13:24:45 +01:00
public BlockPlayerInterface ( ) {
super ( Material . ROCK , this . name ) ;
2016-06-05 04:05:37 +02:00
this . setHarvestLevel ( " pickaxe " , 0 ) ;
this . setHardness ( 4 . 5F ) ;
this . setResistance ( 10 . 0F ) ;
this . setSoundType ( SoundType . STONE ) ;
}
@Override
2021-02-28 12:33:01 +01:00
public TileEntity createNewTileEntity ( IBlockReader worldIn ) {
2016-06-05 04:05:37 +02:00
return new TileEntityPlayerInterface ( ) ;
}
@Override
2019-05-02 09:10:29 +02:00
public EnumRarity getRarity ( ItemStack stack ) {
2016-06-05 04:05:37 +02:00
return EnumRarity . EPIC ;
}
@Override
2021-02-26 22:15:48 +01:00
public void onBlockPlacedBy ( World world , BlockPos pos , BlockState state , EntityLivingBase player , ItemStack stack ) {
2016-06-05 04:05:37 +02:00
TileEntity tile = world . getTileEntity ( pos ) ;
2019-05-02 09:10:29 +02:00
if ( tile instanceof TileEntityPlayerInterface ) {
TileEntityPlayerInterface face = ( TileEntityPlayerInterface ) tile ;
if ( face . connectedPlayer = = null ) {
2016-06-05 04:05:37 +02:00
face . connectedPlayer = player . getUniqueID ( ) ;
2016-07-14 02:11:41 +02:00
face . playerName = player . getName ( ) ;
2016-06-05 04:05:37 +02:00
face . markDirty ( ) ;
2016-07-14 02:11:41 +02:00
face . sendUpdate ( ) ;
2016-06-05 04:05:37 +02:00
}
}
super . onBlockPlacedBy ( world , pos , state , player , stack ) ;
}
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 ) {
TileEntity tile = minecraft . world . getTileEntity ( 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 ;
2019-05-02 09:10:29 +02:00
minecraft . fontRenderer . drawStringWithShadow ( " Bound to: " + TextFormatting . RED + name , resolution . getScaledWidth ( ) / 2 + 5 , resolution . getScaledHeight ( ) / 2 + 5 , StringUtil . DECIMAL_COLOR_WHITE ) ;
minecraft . fontRenderer . drawStringWithShadow ( " UUID: " + TextFormatting . DARK_GREEN + face . connectedPlayer , resolution . getScaledWidth ( ) / 2 + 5 , resolution . getScaledHeight ( ) / 2 + 15 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2016-07-14 02:11:41 +02:00
}
}
}
2016-06-05 04:05:37 +02:00
}