Search in sources :

Example 1 with TilePlayerInterface

use of com.cjm721.overloaded.tile.functional.TilePlayerInterface in project Overloaded by CJ-MC-Mods.

the class BlockPlayerInterface method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) {
        TileEntity te = worldIn.getTileEntity(pos);
        if (te instanceof TilePlayerInterface) {
            UUID placer = ((TilePlayerInterface) te).getPlacer();
            GameProfile profile = worldIn.getMinecraftServer().getPlayerProfileCache().getProfileByUUID(placer);
            if (profile == null) {
                playerIn.sendMessage(new TextComponentString(String.format("Bound to offline player: %s", placer.toString())));
            } else {
                playerIn.sendMessage(new TextComponentString("Bound to player: " + profile.getName()));
            }
        }
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TilePlayerInterface(com.cjm721.overloaded.block.tile.TilePlayerInterface) GameProfile(com.mojang.authlib.GameProfile) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with TilePlayerInterface

use of com.cjm721.overloaded.tile.functional.TilePlayerInterface in project Overloaded by CJ-MC-Mods.

the class BlockPlayerInterface method use.

@Override
@Nonnull
public ActionResultType use(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult rayTraceResult) {
    if (!world.isClientSide && hand == Hand.MAIN_HAND) {
        TileEntity te = world.getBlockEntity(pos);
        if (te instanceof TilePlayerInterface) {
            UUID placer = ((TilePlayerInterface) te).getPlacer();
            if (placer == null) {
                player.sendMessage(new StringTextComponent("Not bound to anyone..... ghosts placed this."), player.getUUID());
            } else {
                String username = UsernameCache.getLastKnownUsername(placer);
                player.sendMessage(new StringTextComponent("Bound to player: " + (username == null ? placer.toString() : username)), player.getUUID());
            }
        }
        return ActionResultType.SUCCESS;
    }
    return super.use(state, world, pos, player, hand, rayTraceResult);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TilePlayerInterface(com.cjm721.overloaded.tile.functional.TilePlayerInterface) StringTextComponent(net.minecraft.util.text.StringTextComponent) UUID(java.util.UUID) Nonnull(javax.annotation.Nonnull)

Aggregations

UUID (java.util.UUID)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TilePlayerInterface (com.cjm721.overloaded.block.tile.TilePlayerInterface)1 TilePlayerInterface (com.cjm721.overloaded.tile.functional.TilePlayerInterface)1 GameProfile (com.mojang.authlib.GameProfile)1 Nonnull (javax.annotation.Nonnull)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1